Skip to content

Commit

Permalink
refactor: Update linter tooling & refactor errors (#967)
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis authored Jul 27, 2021
1 parent 262d867 commit 4efec1a
Show file tree
Hide file tree
Showing 35 changed files with 1,726 additions and 1,242 deletions.
7 changes: 3 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ extends:
- plugin:jest/recommended
- plugin:unicorn/recommended
- plugin:react/recommended
- plugin:prettier/recommended
- plugin:@typescript-eslint/recommended
- prettier/react
- prettier/unicorn
- prettier/@typescript-eslint
- plugin:prettier/recommended

plugins:
- "@typescript-eslint"
Expand All @@ -28,6 +25,8 @@ rules:

# plugin:unicorn
unicorn/consistent-function-scoping: off
unicorn/no-array-for-each: off
unicorn/no-array-reduce: off
unicorn/no-fn-reference-in-iterator: off
unicorn/no-null: off
unicorn/no-reduce: off
Expand Down
2,036 changes: 1,272 additions & 764 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@
"@types/node": "^14.0.24",
"@types/react": "^16.9.36",
"@types/react-dom": "^16.9.8",
"@typescript-eslint/eslint-plugin": "^4.11.0",
"@typescript-eslint/parser": "^4.11.0",
"@typescript-eslint/eslint-plugin": "^4.28.5",
"@typescript-eslint/parser": "^4.28.5",
"babel-core": "^7.0.0-bridge.0",
"babel-plugin-module-resolver": "^3.0.0",
"benchmark": "^2.1.4",
Expand All @@ -108,12 +108,12 @@
"docsify-cli": "^4.4.3",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"eslint": "^7.16.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-prettier": "^3.3.0",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-unicorn": "^24.0.0",
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jest": "^24.4.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-unicorn": "^30.0.0",
"husky": "^1.3.1",
"identity-obj-proxy": "^3.0.0",
"jest": "^24.0.0",
Expand All @@ -124,7 +124,7 @@
"node-persist": "^3.0.4",
"nodemon": "^1.18.9",
"npm-run-all": "^4.1.5",
"prettier": "^2.2.1",
"prettier": "^2.3.2",
"raf": "^3.4.0",
"react": "^16.7.0",
"react-dom": "^16.7.0",
Expand Down
7 changes: 4 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import svelte from 'rollup-plugin-svelte';
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';
import typescript from 'rollup-plugin-typescript2';
import ts from 'typescript';
const subpackages = require('./subpackages');

const internalDeps = new Set(['svelte']);
Expand All @@ -28,7 +29,7 @@ const plugins = [
babel({ exclude: '**/node_modules/**' }),
resolve({ browser: true, only: [/svelte/] }),
typescript({
typescript: require('typescript'),
typescript: ts,
tsconfigOverride: {
compilerOptions: {
declaration: true,
Expand All @@ -42,15 +43,15 @@ const plugins = [

const serverPlugins = [
resolve(),
typescript({ typescript: require('typescript') }),
typescript({ typescript: ts }),
babel({ exclude: ['**/node_modules/**'] }),
commonjs({ include: 'node_modules/**' }),
];

const minifiedPlugins = [
babel({ exclude: '**/node_modules/**' }),
resolve({ browser: true }),
typescript({ typescript: require('typescript') }),
typescript({ typescript: ts }),
svelte({ extensions: ['.svelte'] }),
commonjs(),
replace({
Expand Down
6 changes: 3 additions & 3 deletions src/ai/ai.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ function IsVictory(cells) {
return symbols.every((i) => i !== null && i === symbols[0]);
};

return positions.map(isRowComplete).some((i) => i === true);
return positions.map((row) => isRowComplete(row)).includes(true);
}

const TicTacToe = ProcessGameConfig({
setup: () => ({
cells: new Array(9).fill(null),
cells: Array.from({ length: 9 }).fill(null),
}),

moves: {
Expand All @@ -60,7 +60,7 @@ const TicTacToe = ProcessGameConfig({
return { winner: ctx.currentPlayer };
}

if (G.cells.filter((t) => t == null).length == 0) {
if (G.cells.filter((t) => t == null).length === 0) {
return { draw: true };
}
},
Expand Down
16 changes: 7 additions & 9 deletions src/ai/mcts-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,12 @@ export class MCTSBot extends Bot {
objectives = this.objectives(G, ctx, playerID);
} else if (ctx.activePlayers) {
for (const playerID in ctx.activePlayers) {
actions = actions.concat(this.enumerate(G, ctx, playerID));
objectives = objectives.concat(this.objectives(G, ctx, playerID));
actions.push(...this.enumerate(G, ctx, playerID));
objectives.push(this.objectives(G, ctx, playerID));
}
} else {
actions = actions.concat(this.enumerate(G, ctx, ctx.currentPlayer));
objectives = objectives.concat(
this.objectives(G, ctx, ctx.currentPlayer)
);
actions = this.enumerate(G, ctx, ctx.currentPlayer);
objectives = this.objectives(G, ctx, ctx.currentPlayer);
}

return {
Expand All @@ -157,7 +155,7 @@ export class MCTSBot extends Bot {
}

// This is a terminal node.
if (node.children.length == 0) {
if (node.children.length === 0) {
return node;
}

Expand All @@ -181,7 +179,7 @@ export class MCTSBot extends Bot {
private expand(node: Node) {
const actions = node.actions;

if (actions.length == 0 || node.state.ctx.gameover !== undefined) {
if (actions.length === 0 || node.state.ctx.gameover !== undefined) {
return node;
}

Expand Down Expand Up @@ -227,7 +225,7 @@ export class MCTSBot extends Bot {
return { score };
}

if (!moves || moves.length == 0) {
if (!moves || moves.length === 0) {
return undefined;
}

Expand Down
25 changes: 12 additions & 13 deletions src/client/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ describe('multiplayer', () => {

subscribeChatMessage() {}
}
const customTransport = () =>
(new CustomTransport() as unknown) as Transport;
const customTransport = () => new CustomTransport() as unknown as Transport;

let client;

Expand Down Expand Up @@ -338,9 +337,7 @@ describe('strip secret only on server', () => {
setup: () => initial,
playerView: (G) => {
const r = { ...G };
r.sum = r.secret.reduce((prev, curr) => {
return prev + curr;
});
r.sum = r.secret.reduce((prev, curr) => prev + curr);
delete r.secret;
return r;
},
Expand Down Expand Up @@ -369,13 +366,15 @@ describe('strip secret only on server', () => {

test('accepts enhancer for store', () => {
let spyDispatcher;
const spyEnhancer = (vanillaCreateStore) => (...args) => {
const vanillaStore = vanillaCreateStore(...args);
return {
...vanillaStore,
dispatch: (spyDispatcher = jest.fn(vanillaStore.dispatch)),
const spyEnhancer =
(vanillaCreateStore) =>
(...args) => {
const vanillaStore = vanillaCreateStore(...args);
return {
...vanillaStore,
dispatch: (spyDispatcher = jest.fn(vanillaStore.dispatch)),
};
};
};
const client = Client({
game: {
moves: {
Expand Down Expand Up @@ -585,7 +584,7 @@ describe('log handling', () => {
});

test('update', () => {
const state = ({ restore: true, _stateID: 0 } as unknown) as State;
const state = { restore: true, _stateID: 0 } as unknown as State;
const deltalog = [
{
action: {},
Expand Down Expand Up @@ -627,7 +626,7 @@ describe('log handling', () => {
test('sync', () => {
const state = { restore: true };
const log = ['0', '1'];
const action = sync(({ state, log } as unknown) as SyncInfo);
const action = sync({ state, log } as unknown as SyncInfo);

client.store.dispatch(action);
client.store.dispatch(action);
Expand Down
Loading

0 comments on commit 4efec1a

Please sign in to comment.