Skip to content

Commit

Permalink
Updated eslint package, migrated to the new eslint config system (#2196)
Browse files Browse the repository at this point in the history
* updated eslint package, migrated to the new eslint config system

* excluded eslint.config.mjs from sonarCloud coverage check
  • Loading branch information
YaroslavChuiko committed Oct 4, 2024
1 parent 50acd66 commit 411bc86
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 117 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

105 changes: 0 additions & 105 deletions .eslintrc.js

This file was deleted.

147 changes: 147 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import { fixupPluginRules } from '@eslint/compat'
import { FlatCompat } from '@eslint/eslintrc'
import js from '@eslint/js'
import typescriptEslint from '@typescript-eslint/eslint-plugin'
import tsParser from '@typescript-eslint/parser'
import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
import testingLibrary from 'eslint-plugin-testing-library'
import globals from 'globals'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
})

export default [
{
ignores: ['src/assets/*', 'src/stories/assets/*']
},
...compat.extends(
'eslint:recommended',
'plugin:prettier/recommended',
'plugin:react/recommended',
'plugin:storybook/recommended',
'plugin:vitest-globals/recommended'
),
{
plugins: {
react,
'testing-library': testingLibrary,
'react-hooks': fixupPluginRules(reactHooks)
},
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.es2021,
'vitest-globals/env': true
},
ecmaVersion: 2021,
sourceType: 'module',
parserOptions: {
ecmaFeatures: {
jsx: true
}
}
},
settings: {
react: {
version: 'detect'
}
},
rules: {
'prefer-arrow-callback': ['error'],
'react/jsx-boolean-value': 'error',
'react/jsx-closing-bracket-location': 'error',
'react/jsx-equals-spacing': 'error',
'react/jsx-first-prop-new-line': 'error',
'react/jsx-handler-names': 'error',
'react/jsx-key': 'error',
'react/react-in-jsx-scope': 'off',
'react/jsx-pascal-case': 'error',
'react/jsx-sort-props': 'error',
'react/jsx-no-useless-fragment': [
'error',
{
allowExpressions: true
}
],
'react/jsx-max-depth': [
'error',
{
max: 6
}
],
'react/jsx-wrap-multilines': [
'error',
{
declaration: 'parens',
assignment: 'parens',
return: 'parens-new-line',
arrow: 'parens',
condition: 'parens',
logical: 'parens',
prop: 'ignore'
}
],
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'react/prop-types': 'off'
}
},
...compat
.extends(
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking'
)
.map((config) => ({
...config,
files: ['**/*.ts', '**/*.tsx']
})),
{
files: ['**/*.ts', '**/*.tsx'],
plugins: {
'@typescript-eslint': typescriptEslint
},
languageOptions: {
parser: tsParser,
ecmaVersion: 5,
sourceType: 'script',
parserOptions: {
tsconfigRootDir: __dirname,
project: './tsconfig.eslint.json'
}
},
rules: {
'@typescript-eslint/no-restricted-imports': [
'warn',
{
name: 'react-redux',
importNames: ['useSelector', 'useDispatch'],
message:
'Use typed hooks `useAppDispatch` and `useAppSelector` instead.'
}
]
}
},
{
files: ['**/tests/**/*.*.js', '**/tests/**/*.js'],
languageOptions: {
globals: {
...globals.jest
}
}
},
{
files: ['**/*.stories.*'],
rules: {
'import/no-anonymous-default-export': 'off'
}
}
]
20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
},
"devDependencies": {
"@babel/core": "^7.23.2",
"@eslint/compat": "^1.1.1",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.7.0",
"@storybook/addon-actions": "^6.5.16",
"@storybook/addon-essentials": "^6.5.16",
"@storybook/addon-interactions": "^6.5.16",
Expand Down Expand Up @@ -69,15 +72,16 @@
"c8": "^10.1.2",
"cross-env": "^7.0.3",
"css-mediaquery": "^0.1.2",
"eslint": "^8.52.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-storybook": "^0.6.1",
"eslint-plugin-testing-library": "^6.1.0",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-storybook": "^0.8.0",
"eslint-plugin-testing-library": "^6.2.2",
"eslint-plugin-typescript": "^0.14.0",
"eslint-plugin-vitest-globals": "^1.4.0",
"eslint-plugin-vitest-globals": "^1.5.0",
"globals": "^15.8.0",
"husky": "^8.0.3",
"jsdom": "^22.1.0",
"lint-staged": "^15.0.2",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sonar.projectName=SpaceToStudy-Client
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
sonar.sources=.
sonar.exclusions=**/tests/**/*, **/src/stories/*, **/build-story/*
sonar.coverage.exclusions=**/src/constants/*, **/tests/**/*, **/*.styles.ts
sonar.coverage.exclusions=**/src/constants/*, **/tests/**/*, **/*.styles.ts, eslint.config.mjs

sonar.tests=./tests

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"compilerOptions": {
"esModuleInterop": true
},
"include": ["src", "vite.config.ts", "vitest.config.ts", ".eslintrc.js"],
"include": ["src", "vite.config.ts", "vitest.config.ts", "eslint.config.mjs"],
"exclude": ["node_modules", "dist", "coverage", "tests"]
}

0 comments on commit 411bc86

Please sign in to comment.