Skip to content

Commit

Permalink
[chore] update eslint & pass to flat config & sanitize config
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumejparis committed Dec 11, 2023
1 parent 88b01e7 commit 11b70c1
Show file tree
Hide file tree
Showing 5 changed files with 240 additions and 2,407 deletions.
7 changes: 0 additions & 7 deletions openex-front/.eslintignore

This file was deleted.

71 changes: 0 additions & 71 deletions openex-front/.eslintrc.cjs

This file was deleted.

119 changes: 119 additions & 0 deletions openex-front/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import path from 'path';
import { fileURLToPath } from 'url';
import stylistic from '@stylistic/eslint-plugin';
import reactRefresh from 'eslint-plugin-react-refresh';
import globals from 'globals';
import js from '@eslint/js';
// import tsParser from '@typescript-eslint/parser';
import reactRecommended from 'eslint-plugin-react/configs/recommended.js';
import customRules from 'eslint-plugin-custom-rules';

// import eslint-plugin-react-hooks & @typescript-eslint/eslint-plugin & customRules to not let tools report them as unused
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import eslintPluginReactHooks from 'eslint-plugin-react-hooks';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import tsEslintEslintPlugin from '@typescript-eslint/eslint-plugin';

import { FlatCompat } from '@eslint/eslintrc';

// mimic CommonJS variables -- not needed if using CommonJS
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname,
});

// TODO add eslint-plugin-import when https://github.com/import-js/eslint-plugin-import/issues/2556 is done

export default [
// rules recommended by @eslint/js
js.configs.recommended,

// rules recommended by eslint-plugin-react
{
...reactRecommended,
settings: {
react: {
version: 'detect',
},
},
},

// rules recommended by @stylistic/eslint-plugin
stylistic.configs.customize({
semi: true,
}),

// rules recommended by @typescript-eslint/eslint-plugin
...compat.extends('plugin:@typescript-eslint/recommended'),

// rules recommended by eslint-plugin-react-hooks
...compat.extends('plugin:react-hooks/recommended'),

// eslint-plugin-custom-rules config
{
plugins: {
'custom-rules': customRules,
},
rules: {
'custom-rules/classes-rule': 1,
},
},

// other config
{
languageOptions: {
globals: {
...globals.browser,
...globals.commonjs,
...globals.es2020,
process: true,
},
},
plugins: {
'react-refresh': reactRefresh,
},
rules: {
// react-refresh rules
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],

// react rules
'react/no-unused-prop-types': 0,
'react/prop-types': 0,

// @typescript-eslint rules
'@typescript-eslint/naming-convention': ['error', {
selector: 'variable',
format: ['camelCase', 'UPPER_CASE'],
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
filter: {
regex: '/([^_]*)/',
match: true,
},
}],
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],

// @stylistic rules
'@stylistic/arrow-parens': 'off',
'@stylistic/quote-props': ['error', 'as-needed'],
'@stylistic/brace-style': ['error', '1tbs'],
},
},

// ignores patterns
{
ignores: ['src/static/ext', 'packages', 'builder/prod/build', 'builder/dev/build'],
},
];
15 changes: 5 additions & 10 deletions openex-front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"@mui/lab": "5.0.0-alpha.155",
"@mui/material": "5.14.20",
"@mui/styles": "5.14.20",
"@mui/utils": "5.14.20",
"@mui/x-date-pickers": "6.18.3",
"@redux-devtools/extension": "3.2.6",
"@uiw/react-md-editor": "4.0.1",
Expand Down Expand Up @@ -64,7 +63,6 @@
"zod": "3.22.4"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "7.23.3",
"@eslint/eslintrc": "2.1.4",
"@eslint/js": "8.55.0",
"@stylistic/eslint-plugin": "1.5.0",
Expand All @@ -82,15 +80,12 @@
"cross-env": "7.0.3",
"esbuild": "0.19.8",
"eslint": "8.54.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-airbnb-typescript": "17.1.0",
"eslint-config-prettier": "9.0.0",
"eslint-config-react-app": "7.0.1",
"eslint-import-resolver-typescript": "3.6.1",
"eslint-plugin-custom-rules": "link:packages/eslint-plugin-custom-rules",
"eslint-plugin-import": "2.28.1",
"eslint-plugin-prettier": "5.0.1",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-react": "7.33.2",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-react-refresh": "0.4.5",
"express": "4.18.2",
"fs-extra": "11.2.0",
"globals": "13.23.0",
Expand All @@ -107,7 +102,7 @@
"start": "node builder/dev/dev.js",
"dev": "vite",
"build": "node builder/prod/prod.js",
"lint": "cross-env DEBUG=eslint:cli-engine TIMING=1 eslint --max-warnings 0 --cache -c .eslintrc.cjs src",
"lint": "cross-env DEBUG=eslint:cli-engine TIMING=1 eslint --max-warnings 0 --cache -c eslint.config.js src",
"control": "yarn audit --groups dependencies --summary",
"test": "vitest run",
"check-ts": "tsc --noEmit",
Expand Down
Loading

0 comments on commit 11b70c1

Please sign in to comment.