Skip to content

Commit

Permalink
chore: upgrade eslint and prettier (#27)
Browse files Browse the repository at this point in the history
* Upgrade eslint and prettier

* Update test workflow

* Use node 18 for benchmark
  • Loading branch information
nazarhussain authored Nov 26, 2024
1 parent f281a16 commit 642b31e
Show file tree
Hide file tree
Showing 12 changed files with 1,212 additions and 891 deletions.
77 changes: 0 additions & 77 deletions .eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

- uses: actions/setup-node@v2-beta
with:
node-version: "14"
node-version: "18"

- name: Install
run: yarn install --frozen-lockfile
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:

- uses: actions/setup-node@v2-beta
with:
node-version: "14"
node-version: "18"

- name: Install
run: yarn install --frozen-lockfile
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ on: [pull_request, push]
jobs:
test:
name: Test
strategy:
fail-fast: false
matrix:
node: [18, 20, 22]
runs-on: ubuntu-latest
steps:
# <common-build> - Uses YAML anchors in the future
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: "14"
node-version: ${{matrix.node}}
- name: Install
run: yarn install --frozen-lockfile
# </common-build>
Expand Down
70 changes: 70 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import js from "@eslint/js";
import ts from "typescript-eslint";
import importPlugin from "eslint-plugin-import";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";

export default ts.config(
js.configs.recommended,
ts.configs.recommended,
importPlugin.flatConfigs.errors,
importPlugin.flatConfigs.warnings,
importPlugin.flatConfigs.typescript,
eslintPluginPrettierRecommended,
{
rules: {
"prettier/prettier": "error",
"constructor-super": "off",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/explicit-function-return-type": ["error", {allowExpressions: true}],
"@typescript-eslint/member-ordering": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-unused-vars": ["error", {varsIgnorePattern: "^_"}],
"@typescript-eslint/ban-ts-comment": "error",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", {accessibility: "no-public"}],
"@typescript-eslint/no-unsafe-assignment": "error",
"@typescript-eslint/no-unsafe-call": "error",
"@typescript-eslint/no-unsafe-member-access": "error",
"@typescript-eslint/no-unsafe-return": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"import/no-extraneous-dependencies": [
"error",
{devDependencies: false, optionalDependencies: false, peerDependencies: false},
],
"func-call-spacing": "error",
"import/no-duplicates": "off",
"new-parens": "error",
"no-caller": "error",
"no-bitwise": "off",
"no-cond-assign": "error",
"no-consecutive-blank-lines": 0,
"no-console": "warn",
"no-var": "error",
"object-curly-spacing": ["error", "never"],
"object-literal-sort-keys": 0,
"no-prototype-builtins": 0,
"prefer-const": "error",
quotes: ["error", "double"],
semi: "error",
},
languageOptions: {
globals: {
BigInt: true,
},
parserOptions: {
ecmaVersion: 10,
project: "./tsconfig.json",
},
},
},
{
files: ["**/test/**/*.ts"],
rules: {
"import/no-extraneous-dependencies": "off",
"@typescript-eslint/no-explicit-any": "off",
"no-console": "off"
},
}
);
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"scripts": {
"build": "tsc -p tsconfig.build.json && chmod +x lib/cli.js",
"test:unit": "mocha test/unit/**/*.test.ts",
"lint": "eslint --color --ext .ts src/ test/",
"lint": "eslint --color src/ test/",
"prepublishOnly": "yarn build",
"benchmark": "node -r ts-node/register src/cli.ts 'test/perf/**/*.test.ts'",
"writeDocs": "ts-node scripts/writeOptionsMd.ts"
Expand All @@ -29,18 +29,19 @@
"@types/node": "^15.12.4",
"@types/rimraf": "^3.0.0",
"@types/yargs": "^17.0.33",
"@typescript-eslint/eslint-plugin": "^4.28.0",
"@typescript-eslint/parser": "^4.28.0",
"chai": "^4.5.0",
"dotenv": "^10.0.0",
"eslint": "^7.29.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-prettier": "^3.4.0",
"eslint": "^9.15.0",
"@eslint/js": "^9.15.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-config-prettier": "^9.1.0",
"mocha": "^10.8.2",
"prettier": "^2.3.1",
"prettier": "^3.4.0",
"rimraf": "^3.0.2",
"ts-node": "^10.9.2",
"typescript": "^5.6.3"
"typescript": "^5.6.3",
"typescript-eslint": "^8.16.0"
},
"dependencies": {
"@actions/cache": "^1.0.7",
Expand Down
1 change: 1 addition & 0 deletions src/history/append.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function addBenchmarkToHistory(history: BenchmarkHistory, newBench: Benchmark, b
// Ensure there are no duplicates for the same commit
history.benchmarks[branch] = history.benchmarks[branch].filter((bench) => {
if (bench.commitSha === newBench.commitSha) {
// eslint-disable-next-line no-console
console.log("Deleting previous benchmark for the same commit");
return false;
} else {
Expand Down
6 changes: 5 additions & 1 deletion src/history/gaCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class GaCacheHistoryProvider extends LocalHistoryProvider implements IHistoryPro
readonly type = HistoryProviderType.GaCache;
private initializePromise: Promise<unknown> | null = null;

constructor(private readonly tmpDir: string, private readonly cacheKey: string) {
constructor(
private readonly tmpDir: string,
private readonly cacheKey: string
) {
super(tmpDir);
}

Expand Down Expand Up @@ -60,6 +63,7 @@ class GaCacheHistoryProvider extends LocalHistoryProvider implements IHistoryPro
}

private async initialize(): Promise<unknown> {
// eslint-disable-next-line no-console
console.log("ENV", process.env);
if (this.initializePromise === null) {
this.initializePromise = cache.restoreCache([this.tmpDir], this.cacheKey);
Expand Down
1 change: 0 additions & 1 deletion src/history/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export function validateBenchmark(data: Benchmark): void {
const validate = ajv.compile(benchmarkSchema);
const valid = validate(data);
if (!valid) {
console.log(data);
throw Error(`Invalid BenchmarkResults ${JSON.stringify(validate.errors, null, 2)}`);
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/mochaPlugin/format.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-console */

export type BenchmarkResult = {
id: string;
averageNs: number;
Expand Down
1 change: 0 additions & 1 deletion src/mochaPlugin/runBenchFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export async function runBenchFn<T, T2>(

const inputAll = opts.before ? await opts.before() : (undefined as unknown as T2);

// eslint-disable-next-line no-constant-condition
while (true) {
const ellapsedMs = Date.now() - startRunMs;
const mustStop = ellapsedMs >= maxMs || runIdx >= maxRuns;
Expand Down
2 changes: 1 addition & 1 deletion test/perf/iteration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("Array iteration", () => {
for (let i = 0, len = arr.length; i < len; i++) {
sum += i;
}
sum;
return sum;
});

itBench("sum array with reduce", () => {
Expand Down
Loading

0 comments on commit 642b31e

Please sign in to comment.