Skip to content

Commit

Permalink
Upgrade ESLint and migrate to flat config
Browse files Browse the repository at this point in the history
  • Loading branch information
spautz committed Oct 25, 2024
1 parent 5974cdc commit 47ba984
Show file tree
Hide file tree
Showing 6 changed files with 5,281 additions and 2,250 deletions.
41 changes: 0 additions & 41 deletions .eslintrc.cjs

This file was deleted.

6 changes: 2 additions & 4 deletions demos/vite-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"____ FROM VITE _____________________________________________________": "",
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint": "eslint . --max-warnings 0 --report-unused-disable-directives",
"lint:fix": "eslint . --max-warnings 0 --report-unused-disable-directives --fix",
"preview": "vite preview",
"____ WORKSPACE INTEGRATION _________________________________________": "",
"clean": "rimraf ./build",
Expand All @@ -30,9 +31,6 @@
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3",
"eslint": "^8.56.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"typescript": "^5.6.3",
"vite": "^5.4.10"
}
Expand Down
1 change: 0 additions & 1 deletion demos/vite-react-app/src/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'react';
import { afterEach, describe, expect, test, vitest } from 'vitest';
import { cleanup, fireEvent, render, screen, Screen } from '@testing-library/react';

Expand Down
68 changes: 68 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { fixupPluginRules } from '@eslint/compat';
import eslintJs from '@eslint/js';
import eslintConfigPrettier from 'eslint-config-prettier';
import eslintConfigReactApp from 'eslint-config-react-app';
import eslintPluginFlowtype from 'eslint-plugin-flowtype';
import eslintPluginImport from 'eslint-plugin-import';
import eslintPluginJsxA11y from 'eslint-plugin-jsx-a11y';
import reactRecommended from 'eslint-plugin-react/configs/recommended.js';
import eslintPluginReactHooks from 'eslint-plugin-react-hooks';
import typescriptEslint from 'typescript-eslint';

const buildOutputs = [
'.docusaurus',
'build',
'coverage',
'dist',
'legacy-types',
'node_modules',
'storybook-static',
];
const projectDirectoriesToIgnore = `{${buildOutputs.join(',')}}/**`;

const eslintConfig = [
{
ignores: [
projectDirectoriesToIgnore,
`demos/*/${projectDirectoriesToIgnore}`,
`docs-website/${projectDirectoriesToIgnore}`,
`packages/*/${projectDirectoriesToIgnore}`,
// Each external-test has its own eslint config, following the conventions of its framework, so they're not included
'external-tests/*/**',
],
},
{
plugins: {
// These plugins are all needed for eslint-config-react-app
flowtype: fixupPluginRules(eslintPluginFlowtype),
'jsx-a11y': eslintPluginJsxA11y,
import: fixupPluginRules(eslintPluginImport),
'react-hooks': eslintPluginReactHooks,
},
linterOptions: {
reportUnusedDisableDirectives: true,
},
settings: {
react: {
version: 'detect',
},
},
},

eslintJs.configs.recommended,
eslintConfigPrettier,
reactRecommended,
...typescriptEslint.configs.recommended,

// Overrides:
{
files: ['**/*.{js,ts,jsx,tsx,cjs,mjs}'],
rules: {
...eslintConfigReactApp.rules,
...eslintConfigReactApp.overrides[0].rules,
'react/react-in-jsx-scope': 'off',
},
},
];

export default eslintConfig;
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
"changelog:status:ci": "changeset status --since=origin/main --verbose",
"format": "prettier --write .",
"format:verify": "prettier --list-different .",
"lint": "eslint . --max-warnings 0",
"lint:fix": "eslint . --max-warnings 0 --fix",
"lint": "eslint . --max-warnings 0 --report-unused-disable-directives",
"lint:fix": "eslint . --max-warnings 0 --report-unused-disable-directives --fix",
"release:prep": "pnpm run changelog:status && changeset version",
"test": "pnpm run test:coverage",
"test:clean": "rimraf ./coverage",
Expand All @@ -70,6 +70,7 @@
"@arethetypeswrong/cli": "0.16.4",
"@changesets/cli": "2.27.9",
"@changesets/types": "6.0.0",
"@eslint/compat": "1.2.1",
"@size-limit/preset-small-lib": "11.1.6",
"@testing-library/jest-dom": "^6.6.2",
"@types/node": "22.7.9",
Expand All @@ -78,16 +79,20 @@
"@vitest/coverage-v8": "2.1.3",
"changesets-format-with-issue-links": "0.3.0",
"downlevel-dts": "0.11.0",
"eslint": "8.56.0",
"eslint": "9.13.0",
"eslint-config-prettier": "9.1.0",
"eslint-config-react-app": "7.0.1",
"eslint-plugin-react": "7.37.2",
"eslint-plugin-react-hooks": "5.0.0",
"husky": "9.1.6",
"lint-staged": "15.2.10",
"prettier": "3.3.3",
"publint": "0.2.11",
"publint": "0.2.12",
"rimraf": "5.0.10",
"size-limit": "11.1.6",
"tsup": "8.3.0",
"typescript": "5.6.3",
"typescript-eslint": "8.11.0",
"vitest": "2.1.3",
"yalc": "1.0.0-pre.53"
},
Expand Down
Loading

0 comments on commit 47ba984

Please sign in to comment.