Skip to content

Commit

Permalink
chore(eslint): migrate to flat config and simplify (#2912)
Browse files Browse the repository at this point in the history
* chore(package.json): update related eslint library, update script for eslint.config.js

* chore(pnpm-lock.yaml): reflect changes in package.json

* chore(eslint): migrate eslint configuration .eslintrc.json to eslint.config.js

* chore(examples/demo/package.json): update related eslint library, update script for eslint.config.js

* chore(examples/demo/pnpm-lock.yaml): reflect changes in package.json

* chore(examples/demo/eslint): migrate eslint configuration .eslintrc.cjs to eslint.config.js

* style(examples/demo/utils/copy-to-clipboard.js): add global comment for eslint

* chore(eslint): change file extension 'js' to 'mjs'

* chore(package.json): consise 'lint' scripts

* chore(examples/demo): remove eslint.config.js

* chore(examples/demo/package.json): remove libraries associated wiht eslint, update lint script

* chore(examples/demo/pnpm-lock.yaml): reflect changes in package.json

* chore(examples/demo): reflect 'eslint . --fix' changes based on main 'eslint.config.mjs'

* chore(examples/demo/package.json): add libraries associated wiht eslint, update lint script

* chore(examples/demo/pnpm-lock.yaml): reflect changes in package.json

* chore(examples/demo): add eslint.config.js

* chore(package.json): add mjs in 'eslint', 'test:lint' script

* Update eslint.config.mjs

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>

* Update examples/demo/eslint.config.js

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>

* chore(eslint): remove eslint configuration related to prettier

* chore(package.json): remove eslint-{config,plugin}-prettier

* chore(package.json): add tslib in devDependencies

* chore(eslint): remove duplicate shared-node-browser from globals

* chore(eslint): change 'eslint-import-resolver-alias' to 'eslint-import-resolver-typescript'

* chore(eslint): add 'import/no-named-as-default-member' off

* chore(eslint): remove duplicate rules, rearrange sequentially within a rule

* chore(eslint): remove the ‘off’ settings in ‘eslint-plugin-import’ to ensure clearer usage.

* chore(eslint): remove 'no-console' in rules

* chore(eslint): simplify settings 'import/resolver'

* chore(eslint): remove 'globals' config

* chore(rollup): add 'eslint-disable no-undef'

* chore(package.json): remove 'globals' library

* chore(pnpm-lock.yaml): reflect changes in package.json

* chore(eslint): add 'importPlugin.flatConfigs.recommended'

* chore(eslint): remove duplicate 'languageOptions'

* chore(eslint): remove 'import/extensions', 'import/parsers' to simplify

* chore(eslint): add 'examples/**' in 'ignores'

* chore(package.json): simplify 'lint' scripts

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
  • Loading branch information
sukvvon and dai-shi authored Dec 29, 2024
1 parent ebf2b7a commit 55a7d0a
Show file tree
Hide file tree
Showing 10 changed files with 1,172 additions and 1,014 deletions.
122 changes: 0 additions & 122 deletions .eslintrc.json

This file was deleted.

103 changes: 103 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import eslint from '@eslint/js'
import vitest from '@vitest/eslint-plugin'
import importPlugin from 'eslint-plugin-import'
import jestDom from 'eslint-plugin-jest-dom'
import react from 'eslint-plugin-react'
import reactCompiler from 'eslint-plugin-react-compiler'
import reactHooks from 'eslint-plugin-react-hooks'
import testingLibrary from 'eslint-plugin-testing-library'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{
ignores: ['**/dist/', 'examples/**'],
},
eslint.configs.recommended,
importPlugin.flatConfigs.recommended,
tseslint.configs.recommended,
react.configs.flat.recommended,
react.configs.flat['jsx-runtime'],
{
plugins: {
'react-compiler': reactCompiler,
'react-hooks': reactHooks,
},
settings: {
react: {
version: 'detect',
},
'import/resolver': {
typescript: true,
},
},
rules: {
eqeqeq: 'error',
curly: ['warn', 'multi-line', 'consistent'],
'sort-imports': [
'error',
{
ignoreDeclarationSort: true,
},
],
'import/no-unresolved': ['error', { commonjs: true, amd: true }],
'import/named': 'off',
'import/namespace': 'off',
'import/no-named-as-default-member': 'off',
'import/no-duplicates': 'error',
'import/extensions': ['error', 'always'],
'import/order': [
'error',
{
alphabetize: { order: 'asc', caseInsensitive: true },
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
],
'newlines-between': 'never',
pathGroups: [
{
pattern: 'react',
group: 'builtin',
position: 'before',
},
],
pathGroupsExcludedImportTypes: ['builtin'],
},
],
'@typescript-eslint/no-unused-vars': [
'warn',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
],
'@typescript-eslint/no-explicit-any': 'off',
...reactHooks.configs.recommended.rules,
'react-compiler/react-compiler': 'warn',
},
},
{
files: ['tests/**/*.{ts,tsx}'],
...testingLibrary.configs['flat/react'],
...jestDom.configs['flat/recommended'],
...vitest.configs.recommended,
rules: {
'import/extensions': ['error', 'never'],
'testing-library/no-node-access': 'off',
'vitest/expect-expect': 'off',
'vitest/consistent-test-it': [
'error',
{ fn: 'it', withinDescribe: 'it' },
],
'@typescript-eslint/no-unused-vars': 'off',
},
},
{
files: ['*.js'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
},
},
)
16 changes: 0 additions & 16 deletions examples/demo/.eslintrc.cjs

This file was deleted.

44 changes: 44 additions & 0 deletions examples/demo/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import eslint from '@eslint/js'
import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import globals from 'globals'

export default [
{
ignores: ['dist'],
},
eslint.configs.recommended,
react.configs.flat.recommended,
react.configs.flat['jsx-runtime'],
{
languageOptions: {
globals: {
...globals.browser,
...globals.es2020,
},
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
settings: {
react: {
version: 'detect',
},
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'react/prop-types': 'off',
'react/no-unknown-property': ['off'],
},
},
]
12 changes: 7 additions & 5 deletions examples/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint src --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"lint": "eslint .",
"preview": "vite preview"
},
"prettier": {
Expand All @@ -29,13 +29,15 @@
"zustand": "^4.3.9"
},
"devDependencies": {
"@eslint/js": "^9.17.0",
"@types/react": "^18.2.14",
"@types/react-dom": "^18.2.6",
"@vitejs/plugin-react-swc": "^3.3.2",
"eslint": "^8.44.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.1",
"eslint": "^9.17.0",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-react-refresh": "^0.4.16",
"globals": "^15.14.0",
"vite": "^4.4.0"
}
}
Loading

0 comments on commit 55a7d0a

Please sign in to comment.