diff --git a/config/cli/lint-diff.sh b/config/cli/lint-diff.sh index 4c913c33e50..6971ce9f790 100755 --- a/config/cli/lint-diff.sh +++ b/config/cli/lint-diff.sh @@ -25,7 +25,7 @@ dim() { echo "${DIM}$1${NOCOLOR}" } -dim "> eslint --config ./config/eslint.config.mjs ." +dim "> eslint --config ./eslint.config.mjs ." blue "[Lint]${NOCOLOR} checking..." @@ -34,7 +34,7 @@ if [ -z "$FILESCHANGED" ]; then exit fi -eslint --config ./config/eslint.config.mjs $FILESCHANGED +eslint --config ./eslint.config.mjs $FILESCHANGED RETURN_CODE=$? @@ -42,4 +42,4 @@ if [ $RETURN_CODE -eq 0 ]; then blue "[Lint]${GREEN} DONE." else exit $RETURN_CODE -fi \ No newline at end of file +fi diff --git a/config/eslint.config.mjs b/config/eslint.config.mjs deleted file mode 100644 index 877350138b5..00000000000 --- a/config/eslint.config.mjs +++ /dev/null @@ -1,200 +0,0 @@ -import pluginJs from "@eslint/js"; -import tseslint from "typescript-eslint"; -import importPlugin from 'eslint-plugin-import' - -/** @type {import('eslint').Linter.Config[]} */ -export default [ - { - ignores: [ - '**/.eslintrc.cjs', - '**/.eslintrc.js', - '**/eslint.config.mjs', - '**/benchmarks', - '**/coverage', - '**/dist/*', - '**/node_modules', - '**/recipes/**', - '**/rlp.cjs', - '**/scripts/**', - '**/typedoc.*', - '**/vitest.config.*', - '**/vite.*.ts', - '**/ethereum-tests/**', - '**/devnets/**', - '**/eslint/**', - '**/lint-staged.config.js', - '**/tsconfig.lint.json', - '**/package.json', - ] - }, - { files: ["**/*.{js,mjs,cjs,ts,cts,mts}"] }, - { languageOptions: { parser: tseslint.parser, parserOptions: { extraFileExtensions: ['.json'], sourceType: 'module', project: './config/tsconfig.lint.json' } } }, - pluginJs.configs.recommended, - ...tseslint.configs.recommended, - importPlugin.flatConfigs.recommended, - { - rules: { - 'no-restricted-imports': ['error', 'ethereum-cryptography/utils'], - 'no-restricted-syntax': [ - 'error', - { - selector: "ThrowStatement > NewExpression[callee.name='Error']", - message: "Throwing default JS Errors is not allowed. Only throw `EthereumJSError` (see the util package)", - }, - ], - "no-restricted-globals": [ - "error", - { - "name": "Buffer", - "message": "The use of Buffer is not allowed." - } - ], - '@typescript-eslint/consistent-type-imports': 'error', - '@typescript-eslint/naming-convention': [ - 'error', - { - selector: 'interface', - format: ['PascalCase', 'camelCase'], - custom: { - regex: '^I[A-Z]', - match: false, - }, - }, - ], - '@typescript-eslint/no-unnecessary-condition': 'off', - '@typescript-eslint/prefer-nullish-coalescing': 'error', - '@typescript-eslint/restrict-plus-operands': 'off', - '@typescript-eslint/return-await': 'error', - '@typescript-eslint/strict-boolean-expressions': ['error'], - '@typescript-eslint/no-use-before-define': 'off', // TODO: Decide if this is needed - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-unsafe-function-type': 'off', // TODO: Decide if this is needed - '@typescript-eslint/no-unused-expressions': 'off', // TODO: Decide if this is needed - '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }], - '@typescript-eslint/ban-ts-comment': 'warn', // TODO: We should clean up ts comments and replace with ts-expect-error - '@typescript-eslint/no-empty-object-type': ['error', { - allowInterfaces: 'with-single-extends', - allowObjectTypes: 'always' - }], - eqeqeq: 'error', - 'no-console': 'warn', - 'no-debugger': 'error', - 'no-dupe-class-members': 'off', - 'no-extra-semi': 'off', - 'no-unused-vars': 'off', - 'no-var': 'error', - 'object-shorthand': 'error', - 'prefer-const': 'error', - 'import/default': 'off', - 'import/export': 'error', - 'import/exports-last': 'off', - 'import/first': 'error', - 'import/group-exports': 'off', - 'import/named': 'off', - 'import/namespace': 'off', - 'import/no-absolute-path': 'error', - 'import/no-anonymous-default-export': 'error', - 'import/no-cycle': 'error', - 'import/no-default-export': ['error'], - 'import/no-deprecated': 'off', // TODO: set to `warn` for fixing and then `error` - 'import/no-duplicates': 'error', - 'import/no-dynamic-require': 'off', - 'import/no-mutable-exports': 'error', - 'import/no-self-import': 'error', - 'import/no-unused-modules': 'error', - 'import/no-unresolved': 'off', - 'import/no-useless-path-segments': 'error', - 'import/no-webpack-loader-syntax': 'error', - 'import/order': 'off', - - }, - }, - { - files: ["**/*.ts"], - ignores: ["**/examples/*.ts"], - rules: { - "no-restricted-imports": ["error", { - "patterns": [{ - "group": ["../**/*.js", "./**/*.js"], - "message": "use .ts extensions in relative imports" - }] - }], - } - }, - { - plugins: { - i: importPlugin, - }, - files: ['**/src/**/*.ts', '**/bin/**/*.ts'], - rules: { - 'i/no-extraneous-dependencies': 'error', - }, - }, - { - files: ['packages/client/test/sim/**/*.ts'], - rules: { - '@typescript-eslint/no-require-imports': 'off', - 'no-console': 'off', - 'no-undef': 'off', - } - }, - { - files: ['**/*.js', '**/*.cjs', '**/*.cts'], - rules: { - '@typescript-eslint/no-require-imports': 'off', - 'no-undef': 'off', - } - }, - { - files: ['**/examples/**/*.ts', '**/examples/**/*.js', '**/examples/**/*.cjs', '**/benchmarks/*.ts'], - rules: { - 'no-console': 'off', - '@typescript-eslint/no-unused-vars': 'off', - 'no-restricted-syntax': 'off' - }, - }, - { - files: ['packages/statemanager/src/**', 'packages/vm/src/**',], - rules: { - 'no-invalid-this': 'off', - }, - }, - { - files: ['packages/devp2p/**'], - rules: { - 'no-console': 'off', - '@typescript-eslint/no-unused-vars': 'off', - }, - }, - { - files: ['packages/devp2p/src/ext/**', 'packages/client/src/ext/**', '**/test/**/*.ts',], - rules: { - 'no-restricted-syntax': 'off', - "no-restricted-properties": [ - "error", - { - "object": "assert", - "property": "ok", - "message": "Usage of assert.ok is forbidden because it relies on truthiness." - }, - { - "object": "assert", - "property": "notOk", - "message": "Usage of assert.notOk is forbidden because it relies on falseness." - } - ], - }, - }, - { - files: ['packages/wallet/**'], - rules: { - 'no-prototype-builtins': 'warn', - }, - }, - { - files: ['packages/vm/test/util.ts', 'packages/vm/test/tester/**/*.ts', 'packages/vm/examples/**/*.ts'], - rules: { - 'no-console': 'off', - }, - }, -]; \ No newline at end of file diff --git a/eslint.config.mjs b/eslint.config.mjs index ab95f386467..e4a1f56ab6a 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,3 +1,229 @@ -import rootConfig from '../../config/eslint.config.mjs' +import pluginJs from '@eslint/js' +import importPlugin from 'eslint-plugin-import' +import tseslint from 'typescript-eslint' -export default [...rootConfig] +/** @type {import('eslint').Linter.Config[]} */ +export default [ + { + ignores: [ + '**/.eslintrc.cjs', + '**/.eslintrc.js', + '**/eslint.config.mjs', + '**/benchmarks', + '**/coverage', + '**/dist/*', + '**/node_modules', + '**/recipes/**', + '**/rlp.cjs', + '**/scripts/**', + '**/typedoc.*', + '**/vitest.config.*', + '**/vite.*.ts', + '**/ethereum-tests/**', + '**/devnets/**', + '**/eslint/**', + '**/lint-staged.config.js', + '**/tsconfig.lint.json', + '**/package.json', + ], + }, + { files: ['**/*.{js,mjs,cjs,ts,cts,mts}'] }, + { + languageOptions: { + parser: tseslint.parser, + parserOptions: { + extraFileExtensions: ['.json'], + sourceType: 'module', + project: './config/tsconfig.lint.json', + }, + }, + }, + pluginJs.configs.recommended, + ...tseslint.configs.recommended, + importPlugin.flatConfigs.recommended, + { + rules: { + 'no-restricted-imports': ['error', 'ethereum-cryptography/utils'], + 'no-restricted-syntax': [ + 'error', + { + selector: "ThrowStatement > NewExpression[callee.name='Error']", + message: + 'Throwing default JS Errors is not allowed. Only throw `EthereumJSError` (see the util package)', + }, + ], + 'no-restricted-globals': [ + 'error', + { + name: 'Buffer', + message: 'The use of Buffer is not allowed.', + }, + ], + '@typescript-eslint/consistent-type-imports': 'error', + '@typescript-eslint/naming-convention': [ + 'error', + { + selector: 'interface', + format: ['PascalCase', 'camelCase'], + custom: { + regex: '^I[A-Z]', + match: false, + }, + }, + ], + '@typescript-eslint/no-unnecessary-condition': 'off', + '@typescript-eslint/prefer-nullish-coalescing': 'error', + '@typescript-eslint/restrict-plus-operands': 'off', + '@typescript-eslint/return-await': 'error', + '@typescript-eslint/strict-boolean-expressions': ['error'], + '@typescript-eslint/no-use-before-define': 'off', // TODO: Decide if this is needed + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-unsafe-function-type': 'off', // TODO: Decide if this is needed + '@typescript-eslint/no-unused-expressions': 'off', // TODO: Decide if this is needed + '@typescript-eslint/no-unused-vars': [ + 'error', + { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }, + ], + '@typescript-eslint/ban-ts-comment': 'warn', // TODO: We should clean up ts comments and replace with ts-expect-error + '@typescript-eslint/no-empty-object-type': [ + 'error', + { + allowInterfaces: 'with-single-extends', + allowObjectTypes: 'always', + }, + ], + eqeqeq: 'error', + 'no-console': 'warn', + 'no-debugger': 'error', + 'no-dupe-class-members': 'off', + 'no-extra-semi': 'off', + 'no-unused-vars': 'off', + 'no-var': 'error', + 'object-shorthand': 'error', + 'prefer-const': 'error', + 'import/default': 'off', + 'import/export': 'error', + 'import/exports-last': 'off', + 'import/first': 'error', + 'import/group-exports': 'off', + 'import/named': 'off', + 'import/namespace': 'off', + 'import/no-absolute-path': 'error', + 'import/no-anonymous-default-export': 'error', + 'import/no-cycle': 'error', + 'import/no-default-export': ['error'], + 'import/no-deprecated': 'off', // TODO: set to `warn` for fixing and then `error` + 'import/no-duplicates': 'error', + 'import/no-dynamic-require': 'off', + 'import/no-mutable-exports': 'error', + 'import/no-self-import': 'error', + 'import/no-unused-modules': 'error', + 'import/no-unresolved': 'off', + 'import/no-useless-path-segments': 'error', + 'import/no-webpack-loader-syntax': 'error', + 'import/order': 'off', + }, + }, + { + files: ['**/*.ts'], + ignores: ['**/examples/*.ts'], + rules: { + 'no-restricted-imports': [ + 'error', + { + patterns: [ + { + group: ['../**/*.js', './**/*.js'], + message: 'use .ts extensions in relative imports', + }, + ], + }, + ], + }, + }, + { + plugins: { + i: importPlugin, + }, + files: ['**/src/**/*.ts', '**/bin/**/*.ts'], + rules: { + 'i/no-extraneous-dependencies': 'error', + }, + }, + { + files: ['packages/client/test/sim/**/*.ts'], + rules: { + '@typescript-eslint/no-require-imports': 'off', + 'no-console': 'off', + 'no-undef': 'off', + }, + }, + { + files: ['**/*.js', '**/*.cjs', '**/*.cts'], + rules: { + '@typescript-eslint/no-require-imports': 'off', + 'no-undef': 'off', + }, + }, + { + files: [ + '**/examples/**/*.ts', + '**/examples/**/*.js', + '**/examples/**/*.cjs', + '**/benchmarks/*.ts', + ], + rules: { + 'no-console': 'off', + '@typescript-eslint/no-unused-vars': 'off', + 'no-restricted-syntax': 'off', + }, + }, + { + files: ['packages/statemanager/src/**', 'packages/vm/src/**'], + rules: { + 'no-invalid-this': 'off', + }, + }, + { + files: ['packages/devp2p/**'], + rules: { + 'no-console': 'off', + '@typescript-eslint/no-unused-vars': 'off', + }, + }, + { + files: ['packages/devp2p/src/ext/**', 'packages/client/src/ext/**', '**/test/**/*.ts'], + rules: { + 'no-restricted-syntax': 'off', + 'no-restricted-properties': [ + 'error', + { + object: 'assert', + property: 'ok', + message: 'Usage of assert.ok is forbidden because it relies on truthiness.', + }, + { + object: 'assert', + property: 'notOk', + message: 'Usage of assert.notOk is forbidden because it relies on falseness.', + }, + ], + }, + }, + { + files: ['packages/wallet/**'], + rules: { + 'no-prototype-builtins': 'warn', + }, + }, + { + files: [ + 'packages/vm/test/util.ts', + 'packages/vm/test/tester/**/*.ts', + 'packages/vm/examples/**/*.ts', + ], + rules: { + 'no-console': 'off', + }, + }, +] diff --git a/package.json b/package.json index 5721c57126b..3a0c40fb8c8 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "e2e:resolutions": "node ./scripts/e2e-resolutions.js", "examples": "npm run examples --workspaces --if-present", "examples:build": "npm run examples:build --workspaces --if-present", - "lint": "npm run biome && eslint --config ./config/eslint.config.mjs .", - "lint:fix": "npm run biome:fix && eslint --fix --config ./config/eslint.config.mjs .", + "lint": "npm run biome && eslint --config ./eslint.config.mjs .", + "lint:fix": "npm run biome:fix && eslint --fix --config ./eslint.config.mjs .", "lint:diff": "./config/cli/lint-diff.sh", "test": "npm run test --workspaces --if-present", "test:node": "npm run test:node --workspaces --if-present", diff --git a/packages/binarytree/eslint.config.mjs b/packages/binarytree/eslint.config.mjs index 74f7028872a..8afd1af3432 100644 --- a/packages/binarytree/eslint.config.mjs +++ b/packages/binarytree/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/block/eslint.config.mjs b/packages/block/eslint.config.mjs index a6ffefbcaed..1a952f4b29b 100644 --- a/packages/block/eslint.config.mjs +++ b/packages/block/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/blockchain/eslint.config.mjs b/packages/blockchain/eslint.config.mjs index 4dd2cd44db6..2d9b14dde5e 100644 --- a/packages/blockchain/eslint.config.mjs +++ b/packages/blockchain/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/client/eslint.config.mjs b/packages/client/eslint.config.mjs index d7c5ab50901..8a6e9047057 100644 --- a/packages/client/eslint.config.mjs +++ b/packages/client/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/common/eslint.config.mjs b/packages/common/eslint.config.mjs index c2bc0cf7ef4..c0db9e060f5 100644 --- a/packages/common/eslint.config.mjs +++ b/packages/common/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/devp2p/eslint.config.mjs b/packages/devp2p/eslint.config.mjs index cfee32dd2cc..a5ab7a51749 100644 --- a/packages/devp2p/eslint.config.mjs +++ b/packages/devp2p/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/e2store/eslint.config.mjs b/packages/e2store/eslint.config.mjs index a6ffefbcaed..1a952f4b29b 100644 --- a/packages/e2store/eslint.config.mjs +++ b/packages/e2store/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/ethash/eslint.config.mjs b/packages/ethash/eslint.config.mjs index a6ffefbcaed..1a952f4b29b 100644 --- a/packages/ethash/eslint.config.mjs +++ b/packages/ethash/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/evm/eslint.config.mjs b/packages/evm/eslint.config.mjs index 4cc22f458e5..f0d7a7c2bda 100644 --- a/packages/evm/eslint.config.mjs +++ b/packages/evm/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/evm/src/precompiles/05-modexp.ts b/packages/evm/src/precompiles/05-modexp.ts index 626f3b823fd..4ee39375e3d 100644 --- a/packages/evm/src/precompiles/05-modexp.ts +++ b/packages/evm/src/precompiles/05-modexp.ts @@ -14,11 +14,10 @@ import { setLengthRight, } from '@ethereumjs/util' -import { OOGResult } from '../evm.ts' - import { getPrecompileName } from './index.ts' import { gasLimitCheck } from './util.ts' +import { OOGResult } from '../evm.ts' import type { ExecResult } from '../types.ts' import type { PrecompileInput } from './types.ts' @@ -33,7 +32,6 @@ const BIGINT_199680 = BigInt(199680) const BIGINT_2147483647 = BigInt(2147483647) const maxInt = BigInt(Number.MAX_SAFE_INTEGER) - function multiplicationComplexity(x: bigint): bigint { let fac1 let fac2 diff --git a/packages/genesis/eslint.config.mjs b/packages/genesis/eslint.config.mjs index a6ffefbcaed..1a952f4b29b 100644 --- a/packages/genesis/eslint.config.mjs +++ b/packages/genesis/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/mpt/eslint.config.mjs b/packages/mpt/eslint.config.mjs index 455b0e4153f..831a5aa99fe 100644 --- a/packages/mpt/eslint.config.mjs +++ b/packages/mpt/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/rlp/eslint.config.mjs b/packages/rlp/eslint.config.mjs index bd4e0656007..cfe886a3a10 100644 --- a/packages/rlp/eslint.config.mjs +++ b/packages/rlp/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/statemanager/eslint.config.mjs b/packages/statemanager/eslint.config.mjs index 7d300059c21..be8ec70e51e 100644 --- a/packages/statemanager/eslint.config.mjs +++ b/packages/statemanager/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/tx/eslint.config.mjs b/packages/tx/eslint.config.mjs index a6ffefbcaed..1a952f4b29b 100644 --- a/packages/tx/eslint.config.mjs +++ b/packages/tx/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/util/eslint.config.mjs b/packages/util/eslint.config.mjs index a6ffefbcaed..1a952f4b29b 100644 --- a/packages/util/eslint.config.mjs +++ b/packages/util/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/verkle/eslint.config.mjs b/packages/verkle/eslint.config.mjs index 74f7028872a..8afd1af3432 100644 --- a/packages/verkle/eslint.config.mjs +++ b/packages/verkle/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/vm/eslint.config.mjs b/packages/vm/eslint.config.mjs index 190d5daf93c..40bf062e834 100644 --- a/packages/vm/eslint.config.mjs +++ b/packages/vm/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig, diff --git a/packages/wallet/eslint.config.mjs b/packages/wallet/eslint.config.mjs index aac10e643ee..f9c95f0fef6 100644 --- a/packages/wallet/eslint.config.mjs +++ b/packages/wallet/eslint.config.mjs @@ -1,4 +1,4 @@ -import rootConfig from '../../config/eslint.config.mjs' +import rootConfig from '../../eslint.config.mjs' export default [ ...rootConfig,