summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Paul <n@nc0.fr>2024-03-05 11:19:47 +0100
committerNicolas Paul <n@nc0.fr>2024-03-05 11:19:47 +0100
commita3cdbea5ac589a5a7ce08b90bf764a3f46a6ecad (patch)
tree28e54e7855d69cb175ed2069b42a9ac1186db557
parentdf2ca3fe335db02d60b50246145eb279d8ef8fb9 (diff)
Fix ESLint googlejs
GoogleJS ESlint configuration was actually named "closure" and not GoogleJS, as Closure is the public name for JSCompiler. Signed-off-by: Nicolas Paul <n@nc0.fr>
-rw-r--r--.eslintrc.cjs27
-rw-r--r--life2/simulator/src/l2sf.js34
-rw-r--r--life2/simulator/src/life2.js82
-rw-r--r--package.json7
4 files changed, 77 insertions, 73 deletions
diff --git a/.eslintrc.cjs b/.eslintrc.cjs
index f2cffe4..2d782a1 100644
--- a/.eslintrc.cjs
+++ b/.eslintrc.cjs
@@ -19,41 +19,28 @@
/* eslint-env node */
// Named constants for the numbers ESLint uses to indicate lint severity.
-const OFF = 0;
-const WARNING = 1;
-const ERROR = 2;
+// const OFF = 0;
+// const WARNING = 1;
+// const ERROR = 2;
// ESLint configuration object. Options are described at
// http://eslint.org/docs/user-guide/configuring.
const ESLINT_CONFIG = {
- extends : ['eslint-config-googlejs-es6'],
+ extends : ['eslint-config-closure-es6'],
parserOptions : {
ecmaVersion : 6,
sourceType : 'module',
},
env : {
- 'node' : true,
+ node : true,
},
globals : {},
plugins : [
- 'googlejs',
+ 'closure',
],
// The list of rules and options are available at
// http://eslint.org/docs/rules/.
- rules : {
- // Disallow opt_ prefix and var_args as identifiers.
- 'googlejs/camelcase' : [
- ERROR, {
- allowVarArgs : false,
- // TODO: disallow opt_ prefix once closure compiler stops warning about
- // it.
- allowOptPrefix : true,
- allowLeadingUnderscore : true,
- allowTrailingUnderscore : true,
- checkObjectProperties : true,
- }
- ],
- },
+ rules : {},
// ESLint supports adding shared settings into configuration file. The
// settings object will be supplied to every rule that will be executed.
settings : {},
diff --git a/life2/simulator/src/l2sf.js b/life2/simulator/src/l2sf.js
index 94a05ce..4f9918c 100644
--- a/life2/simulator/src/l2sf.js
+++ b/life2/simulator/src/l2sf.js
@@ -1,18 +1,16 @@
-/**
- * @license Copyright 2024 The Life2 Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+// Copyright 2024 The Life2 Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
import {CellStates} from './life2.js';
@@ -36,7 +34,7 @@ export const CellChar = {
/** A cell belonging to team B. */
TEAM_B: 'b',
/** A barrier cell. */
- BARRIER: '#'
+ BARRIER: '#',
};
/**
@@ -57,7 +55,7 @@ export function cellStateToCellChar(cell) {
case CellStates.BARRIER:
return CellChar.BARRIER;
default:
- throw new TypeError('Unknown cell state: ' + cell);
+ throw new TypeError(`Unknown cell state: ${cell}`);
}
}
@@ -79,7 +77,7 @@ export function cellCharToCellState(cell) {
case CellChar.BARRIER:
return CellStates.BARRIER;
default:
- throw new TypeError('Unknown cell character: ' + cell);
+ throw new TypeError(`Unknown cell character: ${cell}`);
}
}
diff --git a/life2/simulator/src/life2.js b/life2/simulator/src/life2.js
index 7d98db0..20e061e 100644
--- a/life2/simulator/src/life2.js
+++ b/life2/simulator/src/life2.js
@@ -1,18 +1,16 @@
-/**
- * @license Copyright 2024 The Life2 Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+// Copyright 2024 The Life2 Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
/**
* @fileoverview Life2.
@@ -34,7 +32,7 @@ export const CellStates = {
/** A cell belonging to team B. */
TEAM_B: 2,
/** A barrier cell. */
- BARRIER: 3
+ BARRIER: 3,
};
/**
@@ -82,7 +80,7 @@ export class World {
* Initializes an empty board filled with empty cells.
* @param {number} width The width of the board.
* @param {number} height The height of the board.
- * @returns {!Array<!Board>} The empty board.
+ * @return {!Array<!Board>} The empty board.
* @throws {RangeError}
* @final @private
*/
@@ -96,13 +94,12 @@ export class World {
* Get the cell at a specific position.
* @param {number} x The x position of the cell.
* @param {number} y The y position of the cell.
- * @returns {!CellStates} The cell at the position.
+ * @return {!CellStates} The cell at the position.
* @throws {RangeError}
* @final
*/
getCell(x, y) {
- if (this.isOutOfBounds_(x, y))
- throw new RangeError('position out of bounds');
+ if (this.isOutOfBounds_(x, y)) throw RangeError('position out of bounds');
return this.board_[x][y];
}
@@ -119,18 +116,20 @@ export class World {
* @final
*/
setCell(x, y, cell) {
- if (this.isOutOfBounds_(x, y))
+ if (this.isOutOfBounds_(x, y)) {
throw new RangeError('position out of bounds');
+ }
- if (cell < CellStates.EMPTY || cell > CellStates.BARRIER)
+ if (cell < CellStates.EMPTY || cell > CellStates.BARRIER) {
throw new TypeError('cell must be a valid Cell');
+ }
this.board_[x][y] = cell;
}
/**
* Get the board.
- * @returns {!Board} The board.
+ * @return {!Board} The board.
* @final
*/
getBoard() {
@@ -141,7 +140,7 @@ export class World {
* Check if a position is out of bounds.
* @param {number} x The x position of the cell.
* @param {number} y The y position of the cell.
- * @returns {boolean} True if the position is out of bounds, false otherwise.
+ * @return {boolean} True if the position is out of bounds, false otherwise.
* @final @private
*/
isOutOfBounds_(x, y) {
@@ -152,17 +151,24 @@ export class World {
* Get the adjacent neighbors of a cell.
* @param {number} x The x position of the cell.
* @param {number} y The y position of the cell.
- * @returns {!Array<!CellStates>} The neighbors of the cell.
+ * @return {!Array<!CellStates>} The neighbors of the cell.
* @throws {RangeError}
* @final @private
*/
getNeighbors_(x, y) {
- if (this.isOutOfBounds_(x, y))
+ if (this.isOutOfBounds_(x, y)) {
throw new RangeError('position out of bounds');
+ }
return [
- (x - 1, y - 1), (x, y - 1), (x + 1, y - 1), (x - 1, y), (x + 1, y),
- (x - 1, y + 1), (x, y + 1), (x + 1, y + 1)
+ (x - 1, y - 1),
+ (x, y - 1),
+ (x + 1, y - 1),
+ (x - 1, y),
+ (x + 1, y),
+ (x - 1, y + 1),
+ (x, y + 1),
+ (x + 1, y + 1),
].filter((x, y) => !this.isOutOfBounds_(x, y))
.map((x, y) => this.getCell(x, y));
}
@@ -170,10 +176,12 @@ export class World {
/**
* Execute the rules of the game to determine the next state of a cell.
* @param {!CellStates} cell The current state of the cell.
- * @returns {!CellStates} The next state of the cell.
+ * @param {number} x The x position of the cell.
+ * @param {number} y The y position of the cell.
+ * @return {!CellStates} The next state of the cell.
* @final @private
*/
- nextCellState_(cell) {
+ nextCellState_(cell, x, y) {
// 1. Barrier cells don't change.
// 2. Empty cells become the team with the most neighbors.
// 3. Filled cells with less than 2 neighbors of the same team become empty.
@@ -189,19 +197,21 @@ export class World {
// (2)
if (cell === CellStates.EMPTY) {
- if (neighborsA.length > neighborsB.length) return CellStates.TEAM_A
- return CellStates.TEAM_B;
+ if (neighborsA.length > neighborsB.length) return CellStates.TEAM_A;
+ return CellStates.TEAM_B;
}
// (3)
if ((cell === CellStates.TEAM_A && neighborsA.length < 2) ||
- (cell === CellStates.TEAM_B && neighborsB.length < 2))
+ (cell === CellStates.TEAM_B && neighborsB.length < 2)) {
return CellStates.EMPTY;
+ }
// (4)
if ((cell === CellStates.TEAM_A && neighborsA.length <= 3) ||
- (cell === CellStates.TEAM_B && neighborsB.length <= 3))
+ (cell === CellStates.TEAM_B && neighborsB.length <= 3)) {
return cell;
+ }
// (5)
return CellStates.EMPTY;
@@ -214,7 +224,9 @@ export class World {
nextState() {
const nextBoard =
this.initializeBoard_(this.width, this.height).forEach((row, x) => {
- row = row.map((cell) => {this.nextCellState_(cell)});
+ row.map((cell, y) => {
+ this.nextCellState_(cell, x, y);
+ });
});
this.board_ = nextBoard;
}
diff --git a/package.json b/package.json
index 63e5233..9d570c1 100644
--- a/package.json
+++ b/package.json
@@ -15,6 +15,13 @@
"workspaces": [
"life2/simulator"
],
+ "scripts": {
+ "lint": "eslint .",
+ "lint:fix": "eslint --fix .",
+ "fmt": "clang-format --dry-run -i *.cjs *.js",
+ "fmt:fix": "clang-format -i *.cjs *.js",
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
"devDependencies": {
"eslint": "8.57.0",
"eslint-config-closure-es6": "0.1.1"