Skip to content

Commit

Permalink
Fix eslint config (#5720)
Browse files Browse the repository at this point in the history
## Summary

Because we use ESlint rules that require a parses, proper amendments to
the `.eslintrc.js` had to be made. Because of that we can also finally
extend main `.eslintrc.js` config in sub-directiories.

You can read more
[here](https://stackoverflow.com/questions/58510287/parseroptions-project-has-been-set-for-typescript-eslint-parser).

As a note, I recommend `eslint --print-config <file>` to debug if the
rules are actually extended etc.

## Test plan

🚀
  • Loading branch information
tjzel committed May 8, 2024
1 parent 80a31af commit 42cb2bd
Show file tree
Hide file tree
Showing 29 changed files with 267 additions and 89 deletions.
5 changes: 0 additions & 5 deletions .eslintignore
@@ -1,8 +1,3 @@
.eslintrc.js
scripts/*.js
docs/*
plugin/*
eslintrc.js
jest.config.js
eslintPlugin/*
mock.js
77 changes: 43 additions & 34 deletions .eslintrc.js
@@ -1,13 +1,49 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
},
overrides: [
{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
},
extends: ['plugin:@typescript-eslint/recommended-type-checked'],
rules: {
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-ignore': 'allow-with-description',
'ts-expect-error': 'allow-with-description',
},
],
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_' },
],
'@typescript-eslint/no-var-requires': 'warn',
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'type-imports' },
],
'@typescript-eslint/consistent-type-exports': [
'error',
{ fixMixedExportsWithInlineTypeSpecifier: false },
],
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-duplicate-type-constituents': 'error',
'@typescript-eslint/no-shadow': 'error',
},
},
],
extends: [
'standard',
'plugin:@typescript-eslint/recommended-type-checked',
'prettier',
'plugin:import/typescript',
'plugin:react-hooks/recommended',
Expand All @@ -32,43 +68,16 @@ module.exports = {
},
},
rules: {
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'object-shorthand': 'error',
curly: 'error',
curly: ['error', 'all'],
'no-case-declarations': 'error',
'@typescript-eslint/no-shadow': 'error',
'import/no-unresolved': 'error',
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
'react/jsx-uses-vars': 'error',
'react/jsx-uses-react': 'error',
'no-use-before-define': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-ignore': 'allow-with-description',
'ts-expect-error': 'allow-with-description',
},
],
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-var-requires': 'warn',
// '@typescript-eslint/no-duplicate-type-constituents': 'error', // TODO this currently breaks ESLint for VSCode in plugin
eqeqeq: 'error',
'no-unreachable': 'error',
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'type-imports' },
],
'@typescript-eslint/consistent-type-exports': [
'error',
{ fixMixedExportsWithInlineTypeSpecifier: false },
],
'tsdoc/syntax': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
},
};
2 changes: 1 addition & 1 deletion Example/package.json
Expand Up @@ -38,7 +38,7 @@
"@types/react": "^18.2.6",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.6.3",
"eslint": "^8.19.0",
"eslint": "^8.0.0-0",
"jest": "^29.6.3",
"patch-package": "^8.0.0",
"prettier": "2.8.8",
Expand Down
4 changes: 2 additions & 2 deletions Example/yarn.lock
Expand Up @@ -3161,7 +3161,7 @@ __metadata:
"@types/react": "npm:^18.2.6"
"@types/react-test-renderer": "npm:^18.0.0"
babel-jest: "npm:^29.6.3"
eslint: "npm:^8.19.0"
eslint: "npm:^8.0.0-0"
jest: "npm:^29.6.3"
patch-package: "npm:^8.0.0"
prettier: "npm:2.8.8"
Expand Down Expand Up @@ -4874,7 +4874,7 @@ __metadata:
languageName: node
linkType: hard

"eslint@npm:^8.19.0":
"eslint@npm:^8.0.0-0":
version: 8.57.0
resolution: "eslint@npm:8.57.0"
dependencies:
Expand Down
2 changes: 1 addition & 1 deletion FabricExample/package.json
Expand Up @@ -36,7 +36,7 @@
"@types/react": "^18.2.6",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.6.3",
"eslint": "^8.19.0",
"eslint": "^8.0.0-0",
"jest": "^29.6.3",
"prettier": "2.8.8",
"react-test-renderer": "18.2.0",
Expand Down
4 changes: 2 additions & 2 deletions FabricExample/yarn.lock
Expand Up @@ -3143,7 +3143,7 @@ __metadata:
"@types/react": "npm:^18.2.6"
"@types/react-test-renderer": "npm:^18.0.0"
babel-jest: "npm:^29.6.3"
eslint: "npm:^8.19.0"
eslint: "npm:^8.0.0-0"
jest: "npm:^29.6.3"
prettier: "npm:2.8.8"
react: "npm:18.2.0"
Expand Down Expand Up @@ -4848,7 +4848,7 @@ __metadata:
languageName: node
linkType: hard

"eslint@npm:^8.19.0":
"eslint@npm:^8.0.0-0":
version: 8.57.0
resolution: "eslint@npm:8.57.0"
dependencies:
Expand Down
2 changes: 1 addition & 1 deletion MacOSExample/package.json
Expand Up @@ -39,7 +39,7 @@
"@types/react": "^18.2.6",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.6.3",
"eslint": "^8.19.0",
"eslint": "^8.0.0-0",
"jest": "^29.6.3",
"prettier": "2.8.8",
"react-test-renderer": "18.2.0",
Expand Down
4 changes: 2 additions & 2 deletions MacOSExample/yarn.lock
Expand Up @@ -3268,7 +3268,7 @@ __metadata:
"@types/react": "npm:^18.2.6"
"@types/react-test-renderer": "npm:^18.0.0"
babel-jest: "npm:^29.6.3"
eslint: "npm:^8.19.0"
eslint: "npm:^8.0.0-0"
jest: "npm:^29.6.3"
prettier: "npm:2.8.8"
react: "npm:18.2.0"
Expand Down Expand Up @@ -5019,7 +5019,7 @@ __metadata:
languageName: node
linkType: hard

"eslint@npm:^8.19.0":
"eslint@npm:^8.0.0-0":
version: 8.57.0
resolution: "eslint@npm:8.57.0"
dependencies:
Expand Down
2 changes: 1 addition & 1 deletion TVOSExample/package.json
Expand Up @@ -27,7 +27,7 @@
"@types/react": "^18.2.6",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.6.3",
"eslint": "^8.19.0",
"eslint": "^8.0.0-0",
"jest": "^29.6.3",
"prettier": "2.8.8",
"react-test-renderer": "18.2.0",
Expand Down
4 changes: 2 additions & 2 deletions TVOSExample/yarn.lock
Expand Up @@ -3493,7 +3493,7 @@ __metadata:
"@types/react": "npm:^18.2.6"
"@types/react-test-renderer": "npm:^18.0.0"
babel-jest: "npm:^29.6.3"
eslint: "npm:^8.19.0"
eslint: "npm:^8.0.0-0"
expo: "npm:^50.0.2"
jest: "npm:^29.6.3"
prettier: "npm:2.8.8"
Expand Down Expand Up @@ -5545,7 +5545,7 @@ __metadata:
languageName: node
linkType: hard

"eslint@npm:^8.19.0":
"eslint@npm:^8.0.0-0":
version: 8.57.0
resolution: "eslint@npm:8.57.0"
dependencies:
Expand Down
2 changes: 1 addition & 1 deletion WebExample/package.json
Expand Up @@ -29,7 +29,7 @@
"@react-native/metro-config": "0.74.81",
"@react-native/typescript-config": "0.74.81",
"@types/react": "~18.0.14",
"eslint": "^8.19.0",
"eslint": "^8.0.0-0",
"prettier": "^2.4.1",
"typescript": "5.0.4"
},
Expand Down
4 changes: 2 additions & 2 deletions WebExample/yarn.lock
Expand Up @@ -6178,7 +6178,7 @@ __metadata:
languageName: node
linkType: hard

"eslint@npm:^8.19.0":
"eslint@npm:^8.0.0-0":
version: 8.57.0
resolution: "eslint@npm:8.57.0"
dependencies:
Expand Down Expand Up @@ -13267,7 +13267,7 @@ __metadata:
"@react-native/metro-config": "npm:0.74.81"
"@react-native/typescript-config": "npm:0.74.81"
"@types/react": "npm:~18.0.14"
eslint: "npm:^8.19.0"
eslint: "npm:^8.0.0-0"
expo: "npm:~48.0.10"
expo-status-bar: "npm:~1.4.0"
prettier: "npm:^2.4.1"
Expand Down
2 changes: 1 addition & 1 deletion __tests__/plugin.test.ts
Expand Up @@ -3,7 +3,7 @@ import plugin from '../plugin';
import { TransformOptions, transformSync } from '@babel/core';
import traverse from '@babel/traverse';
import { strict as assert } from 'assert';
import '../plugin/jestUtils';
import '../plugin/src/jestMatchers';
import { version as packageVersion } from '../package.json';
import { ReanimatedPluginOptions } from '../plugin/src/types';

Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Expand Up @@ -32,7 +32,7 @@
"devDependencies": {
"@tsconfig/react-native": "^3.0.0",
"@types/d3-shape": "^3.1.1",
"eslint": "^8.36.0",
"eslint": "^8.0.0-0",
"eslint-plugin-reanimated": "link:../eslintPlugin",
"patch-package": "^7.0.0",
"prettier": "^2.8.7",
Expand Down
4 changes: 2 additions & 2 deletions app/yarn.lock
Expand Up @@ -693,7 +693,7 @@ __metadata:
languageName: node
linkType: hard

"eslint@npm:^8.36.0":
"eslint@npm:^8.0.0-0":
version: 8.57.0
resolution: "eslint@npm:8.57.0"
dependencies:
Expand Down Expand Up @@ -1716,7 +1716,7 @@ __metadata:
"@tsconfig/react-native": "npm:^3.0.0"
"@types/d3-shape": "npm:^3.1.1"
d3-shape: "npm:^3.2.0"
eslint: "npm:^8.36.0"
eslint: "npm:^8.0.0-0"
eslint-plugin-reanimated: "link:../eslintPlugin"
patch-package: "npm:^7.0.0"
prettier: "npm:^2.8.7"
Expand Down
2 changes: 1 addition & 1 deletion eslintPlugin/package.json
Expand Up @@ -15,7 +15,7 @@
"@typescript-eslint/rule-tester": "^6.19.1",
"@typescript-eslint/utils": "^6.19.1",
"esbuild": "^0.20.0",
"eslint": "^8.56.0",
"eslint": "^8.0.0-0",
"jest": "^29.7.0",
"ts-jest": "^29.1.2",
"typescript": "^5.3.3"
Expand Down
4 changes: 2 additions & 2 deletions eslintPlugin/yarn.lock
Expand Up @@ -2025,7 +2025,7 @@ __metadata:
languageName: node
linkType: hard

"eslint@npm:^8.56.0":
"eslint@npm:^8.0.0-0":
version: 8.57.0
resolution: "eslint@npm:8.57.0"
dependencies:
Expand Down Expand Up @@ -2083,7 +2083,7 @@ __metadata:
"@typescript-eslint/rule-tester": "npm:^6.19.1"
"@typescript-eslint/utils": "npm:^6.19.1"
esbuild: "npm:^0.20.0"
eslint: "npm:^8.56.0"
eslint: "npm:^8.0.0-0"
jest: "npm:^29.7.0"
ts-jest: "npm:^29.1.2"
typescript: "npm:^5.3.3"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -126,7 +126,7 @@
"babel-plugin-module-resolver": "^5.0.0",
"clang-format": "^1.6.0",
"code-tag": "^1.1.0",
"eslint": "^8.56.0",
"eslint": "^8.0.0-0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^17.1.0",
"eslint-import-resolver-babel-module": "^5.3.1",
Expand Down
3 changes: 3 additions & 0 deletions plugin/.eslintignore
@@ -0,0 +1,3 @@
types/*
lib/*
build/*
22 changes: 11 additions & 11 deletions plugin/.eslintrc.js
@@ -1,14 +1,14 @@
module.exports = {
root: true,
extends: '../.eslintrc.js',
extends: [
'standard',
'plugin:@typescript-eslint/recommended', //We overwrite this not to use type-checked rules in plugin
'prettier',
'plugin:import/typescript',
'plugin:react-hooks/recommended',
overrides: [
{
files: ['*.ts'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
},
},
],
rules: {
'curly': 'error',
},
ignorePatterns: ['**/*.d.ts','jestUtils.ts']};
extends: ['../.eslintrc.js'],
};
2 changes: 1 addition & 1 deletion plugin/build/plugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion plugin/package.json
Expand Up @@ -2,8 +2,11 @@
"devDependencies": {
"@react-native/eslint-config": "^0.72.1",
"@types/node": "^18.15.11",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"esbuild": "^0.17.11",
"eslint": "^8.35.0",
"eslint": "^8.0.0-0",
"eslint-plugin-standard": "^5.0.0",
"prettier": "^2.5.1",
"tsc-watch": "^6.0.0",
"typescript": "^4.1.3"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion plugin/src/plugin.ts
Expand Up @@ -17,7 +17,7 @@ module.exports = function (): PluginItem {
try {
fun();
} catch (e) {
throw new Error('[Reanimated] Babel plugin exception: ' + e);
throw new Error(`[Reanimated] Babel plugin exception: ${e as string}`);
}
}

Expand Down

0 comments on commit 42cb2bd

Please sign in to comment.