Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make linting less badder #3794

Merged
merged 18 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env sh

npm run lint:diff --workspaces
npm run lint:diff
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ jobs:
working-directory: ${{ github.workspace }}


- run: npm run lint --workspaces --if-present
- run: npm run lint
working-directory: ${{ github.workspace }}
5 changes: 0 additions & 5 deletions .prettierignore

This file was deleted.

43 changes: 43 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": true,
"ignore": [
"**/node_modules/**",
"**/dist/**",
"**/coverage/**",
"**/ethereum-tests/**",
"**/config/**",
"**/4844-interop/**",
"**/scripts/**",
"**/rlp/bin/**",
"**/benchmarks/fixture/**"
]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 100
},
"organizeImports": {
"enabled": false
},
"linter": {
"enabled": false,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"semicolons": "asNeeded"
}
}
}
10 changes: 5 additions & 5 deletions config/cli/lint-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
REMOTE=$(git rev-parse --symbolic-full-name --abbrev-ref @{u})

if [ -z "$REMOTE" ]; then
FILESCHANGED=". --ext .js,.jsx,.ts,.tsx"
FILESCHANGED=". --ext .js,.ts"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now ignore tsx here, is this intended? Also for jsx below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we don't use tsx and jsx in our code base. Unless we start writing front-end web apps, we never will, so no point in checking for them.

else
FILESCHANGED=$(git diff --diff-filter=d --name-only --relative $REMOTE | grep -E '\.(js|jsx|ts|tsx)')
FILESCHANGED=$(git diff --diff-filter=d --name-only --relative $REMOTE | grep -E '\.(js|ts)')
fi

echo $FILESCHANGED
Expand All @@ -25,8 +25,8 @@ dim() {
echo "${DIM}$1${NOCOLOR}"
}

dim "> eslint --format codeframe --config ./.eslintrc.cjs . \\ "
dim "\t --ext .js,.jsx,.ts,.tsx \\ "
dim "> eslint --format codeframe --config ./config/eslint.cjs . \\ "
dim "\t --ext .js,.ts \\ "

blue "[Lint]${NOCOLOR} checking..."

Expand All @@ -35,7 +35,7 @@ if [ -z "$FILESCHANGED" ]; then
exit
fi

eslint --format codeframe --config ./.eslintrc.cjs $FILESCHANGED
eslint --format codeframe --config ./config/eslint.cjs $FILESCHANGED

RETURN_CODE=$?

Expand Down
33 changes: 0 additions & 33 deletions config/cli/lint-fix.sh

This file was deleted.

33 changes: 0 additions & 33 deletions config/cli/lint.sh

This file was deleted.

54 changes: 43 additions & 11 deletions config/eslint.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports = {
'github',
'implicit-dependencies',
'import',
'prettier',
'simple-import-sort',
'ethereumjs',
],
Expand All @@ -20,22 +19,27 @@ module.exports = {
'coverage',
'dist',
'node_modules',
'prettier.config.js',
'recipes',
'rlp.cjs',
'scripts',
'typedoc.js',
'webpack.config.js',
'vitest.config.ts',
'vitest.config.browser.ts',
'vitest.config.unit.ts'
'vitest.config.unit.ts',
'vite.*.ts',
'ethereum-tests',
'archive',
'devnets',
'eslint',
'lint-staged.config.js',
'tsconfig.lint.json',
'package.json',
],
extends: [
'typestrict',
'eslint:recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'prettier',
],
rules: {
'no-restricted-imports': ['error', 'ethereum-cryptography/utils.js'],
Expand All @@ -62,17 +66,18 @@ module.exports = {
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/return-await': 'error',
'@typescript-eslint/strict-boolean-expressions': ['error'],
'@typescript-eslint/no-use-before-define': 'warn', // TODO: decide if we care
eqeqeq: 'error',
'github/array-foreach': 'error',
'implicit-dependencies/no-implicit': ['error', { peer: true, dev: true, optional: true }],
'import/default': 'error',
'import/default': 'off',
'import/export': 'error',
'import/exports-last': 'off', // TODO: set to `warn` for fixing and then `error`
'import/extensions': ['error','ignorePackages'],
'import/first': 'error',
'import/group-exports': 'off',
'import/named': 'error',
'import/namespace': 'error',
'import/named': 'off',
'import/namespace': 'off',
'import/no-absolute-path': 'error',
'import/no-anonymous-default-export': 'error',
'import/no-cycle': 'off', // TODO: set to `warn` for fixing and then `error`
Expand Down Expand Up @@ -103,26 +108,53 @@ module.exports = {
'no-dupe-class-members': 'off',
'no-extra-semi': 'off',
'no-redeclare': 'off',
'no-undef': 'off',
'no-unused-vars': 'off',
'no-var': 'error',
'object-shorthand': 'error',
'prefer-const': 'error',
'prettier/prettier': 'error',
'simple-import-sort/exports': 'error',
'sort-imports': ['error', { ignoreDeclarationSort: true }],
'ethereumjs/noBuffer': 'error',
'no-restricted-syntax': 'off',
},
parserOptions: {
extraFileExtensions: ['.json'],
sourceType: 'module',
project: './tsconfig.lint.json',
project: './config/tsconfig.lint.json',
},
overrides: [
{
files: ['test/**/*.ts', 'tests/**/*.ts', 'examples/**/*.ts'],
files: ['**/test/**/*.ts', '**/bin/**.ts', ],
rules: {
'implicit-dependencies/no-implicit': 'off',
'import/no-extraneous-dependencies': 'off',
'no-console': 'off',
'@typescript-eslint/no-floating-promises': 'warn',
},
},
{
files: ['**/examples/**/*', '**/benchmarks/*.ts', ],
rules: {
'implicit-dependencies/no-implicit': 'off',
'import/no-extraneous-dependencies': 'off',
'no-console': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
},
{
files: ['packages/statemanager/src/**', 'packages/vm/src/**', ],
rules: {
'@typescript-eslint/no-use-before-define': 'off',
'no-invalid-this': 'off',
'no-restricted-syntax': 'off',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do these specific packages have these exceptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I carried these over from the previous package-specific lint configs. We can go through them and see if they can be removed.

},
},
{
files: ['packages/wallet/**'],
rules: {
'github/array-foreach': 'warn',
'no-prototype-builtins': 'warn',
},
},
],
Expand Down
5 changes: 0 additions & 5 deletions config/prettier.config.js

This file was deleted.

12 changes: 5 additions & 7 deletions config/tsconfig.lint.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"extends": "./tsconfig.json",
"include": [
"../packages/**/src/**/*.ts",
"../packages/**/test/**/*.ts",
"../packages/**/examples/**/*.ts",
"../packages/**/examples/**/*.cjs",
"../packages/**/examples/**/*.js",
"../packages/**/benchmarks/**/*.ts",
"../packages/**/bin/**/*.ts"
"../packages/**/*.ts",
"../packages/**/*.js",
"../packages/ethereum-tests/**/*.js",
"package.json"
],
"exclude": ["../packages/client/devnets", "../packages/client/archive", "**/ethereum-tests/**/*", "package.json"],
"compilerOptions": {
"noEmit": true
}
Expand Down
2 changes: 1 addition & 1 deletion eslint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const ruleFiles = fs
.filter((file) => file !== 'index.js' && !file.endsWith('test.js'))

const rules = Object.fromEntries(
ruleFiles.map((file) => [path.basename(file, '.js'), require('./' + file)])
ruleFiles.map((file) => [path.basename(file, '.js'), require('./' + file)]),
)

module.exports = { rules }
5 changes: 1 addition & 4 deletions eslint/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"name": "eslint-plugin-ethereumjs",
"version": "0.1.0",
"files": [
"index.js",
"noBuffer.js"
],
"files": ["index.js", "noBuffer.js"],
"main": "index.js"
}
2 changes: 1 addition & 1 deletion lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
'*.{js,json,md,ts}': 'prettier --ignore-unknown --write',
'*.{js,json,md,ts}': 'npx @biomejs/biome check --write',
}
Loading
Loading