Skip to content

Commit

Permalink
chore(eslint): migrate to flat config and simplify (#2897)
Browse files Browse the repository at this point in the history
* chore(package.json): update eslint and related dependencies, simplify lint scripts

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

* chore(eslint): migrate eslint to flat config, including removal of 'globals', 'prettier' and add 'ignores'

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

* style(tests): remove unused 'eslint-disable'

* chore(package.json): add 'eslint-import-resolver-typescript', remove 'eslint-import-resolver-alias'

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

* chore(eslint): simplify import-related config and sort rules

* chore(package.json): add '@eslint/js'

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

* chore(eslint): remove unused 'rules', sort by the order 'plugins' were added and by name

* chore(eslint): remove duplicate 'languageOptions'

* chore(eslint): add 'react.configs.flat.recommended'

* style(tests): add 'eslint-disable react/no-unscaped-entities'

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

* chore(pnpm-lock.yaml): reflect changes in package.json
  • Loading branch information
sukvvon authored Dec 31, 2024
1 parent 65a8500 commit e198c14
Show file tree
Hide file tree
Showing 18 changed files with 500 additions and 505 deletions.
121 changes: 0 additions & 121 deletions .eslintrc.json

This file was deleted.

1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
module.exports = (api, targets) => {
// https://babeljs.io/docs/en/config-files#config-function-api
const isTestEnv = api.env('test')
Expand Down
102 changes: 102 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
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/', 'website/'],
},
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-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
],
'react-compiler/react-compiler': 'warn',
...reactHooks.configs.recommended.rules,
},
},
{
files: ['tests/**/*.{ts,tsx}'],
...testingLibrary.configs['flat/react'],
...jestDom.configs['flat/recommended'],
...vitest.configs.recommended,
rules: {
'import/extensions': ['error', 'never'],
'@typescript-eslint/no-unused-vars': 'off',
'vitest/expect-expect': 'off',
'vitest/consistent-test-it': [
'error',
{ fn: 'it', withinDescribe: 'it' },
],
},
},
{
files: ['*.js'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
},
},
)
20 changes: 9 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@
"build:react:utils": "rollup -c --config-react_utils --client-only",
"postbuild": "pnpm patch-d-ts && pnpm copy && pnpm patch-ts3.8 && pnpm patch-old-ts && pnpm patch-esm-ts && pnpm patch-readme",
"prettier": "prettier '*.{js,json,md}' '{src,tests,benchmarks,docs}/**/*.{ts,tsx,md,mdx}' --write",
"eslint": "eslint --fix --no-eslintrc --c .eslintrc.json '*.{js,ts}' '{src,tests,benchmarks}/**/*.{ts,tsx}'",
"eslint": "eslint . --fix",
"test": "pnpm run '/^test:.*/'",
"test:format": "prettier '*.{js,json,md}' '{src,tests,benchmarks,docs}/**/*.{ts,tsx,md,mdx}' --list-different",
"test:types": "tsc --noEmit",
"test:lint": "eslint --no-eslintrc --c .eslintrc.json '*.{js,ts}' '{src,tests,benchmarks}/**/*.{ts,tsx}'",
"test:lint": "eslint .",
"test:spec": "vitest run",
"test-build:spec": "vitest run",
"patch-d-ts": "node -e \"var {entries}=require('./rollup.config.js');require('shelljs').find('dist/**/*.d.ts').forEach(f=>{entries.forEach(({find,replacement})=>require('shelljs').sed('-i',new RegExp(' from \\''+find.source.slice(0,-1)+'\\';$'),' from \\''+replacement+'\\';',f));require('shelljs').sed('-i',/ from '(\\.[^']+)\\.ts';$/,' from \\'\\$1\\';',f)})\"",
Expand Down Expand Up @@ -121,6 +121,7 @@
"@babel/plugin-transform-typescript": "^7.26.3",
"@babel/preset-env": "^7.26.0",
"@babel/template": "^7.25.9",
"@eslint/js": "^9.17.0",
"@rollup/plugin-alias": "^5.1.1",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-node-resolve": "^16.0.0",
Expand All @@ -136,22 +137,18 @@
"@types/node": "^22.10.2",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"@vitest/coverage-v8": "^2.1.8",
"@vitest/eslint-plugin": "^1.1.20",
"@vitest/eslint-plugin": "^1.1.21",
"@vitest/ui": "^2.1.8",
"benny": "^3.7.1",
"downlevel-dts": "^0.11.0",
"esbuild": "^0.24.2",
"eslint": "8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint": "9.17.0",
"eslint-import-resolver-typescript": "^3.7.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest-dom": "^5.5.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-compiler": "19.0.0-beta-201e55d-20241215",
"eslint-plugin-react": "^7.37.3",
"eslint-plugin-react-compiler": "19.0.0-beta-55955c9-20241229",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-testing-library": "^7.1.1",
"jest-leak-detector": "^29.7.0",
Expand All @@ -168,6 +165,7 @@
"shx": "^0.3.4",
"ts-expect": "^1.3.0",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.2",
"vitest": "^2.1.8",
"wonka": "^6.3.4"
},
Expand Down
Loading

0 comments on commit e198c14

Please sign in to comment.