Skip to content

Commit 9587ee3

Browse files
alexlanzlukasvice
andauthored
Upgrading configuration to support ESLint 9 (#27)
* upgrading configuration to support ESLint 9 * adjust configuration * add prettier and fix lint issues * add pre-commit hook * update tailwind config to new plugin major version * add rules from old config * add unused-imports plugin * enable case sensitive import sorting --------- Co-authored-by: Lukas Weiss <lukas.weiss@aboutbits.it>
1 parent 459f19d commit 9587ee3

22 files changed

Lines changed: 7440 additions & 7169 deletions

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.eslintrc.ts-next.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

.eslintrc.ts-react.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

.eslintrc.ts.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

.githooks/pre-commit

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -o pipefail
5+
6+
npm run lint

configs/formatjs.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { defineConfig } from 'eslint/config'
2+
import formatjsPlugin from 'eslint-plugin-formatjs'
3+
import jsonc from 'eslint-plugin-jsonc'
4+
5+
export default defineConfig([
6+
{
7+
files: ['**/*.{js,cjs,mjs,jsx,ts,tsx}'],
8+
plugins: {
9+
formatjs: formatjsPlugin,
10+
},
11+
rules: {
12+
'formatjs/enforce-default-message': ['error', 'literal'],
13+
'formatjs/enforce-placeholders': 'error',
14+
'formatjs/no-multiple-whitespaces': 'error',
15+
'formatjs/enforce-id': 'error',
16+
},
17+
},
18+
{
19+
files: ['**/translations/*.json'],
20+
language: 'json/json',
21+
plugins: { jsonc },
22+
rules: {
23+
'jsonc/sort-keys': 'error',
24+
},
25+
},
26+
])

configs/jest.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from 'eslint/config'
2+
import jestPlugin from 'eslint-plugin-jest'
3+
4+
export default defineConfig([
5+
{
6+
files: ['**/*.{js,cjs,mjs,jsx,ts,tsx}'],
7+
...jestPlugin.configs['flat/recommended'],
8+
},
9+
])

configs/next.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { dirname } from 'path'
2+
import { fileURLToPath } from 'url'
3+
import { FlatCompat } from '@eslint/eslintrc'
4+
import { defineConfig } from 'eslint/config'
5+
6+
const __filename = fileURLToPath(import.meta.url)
7+
const __dirname = dirname(__filename)
8+
9+
const compat = new FlatCompat({
10+
baseDirectory: __dirname,
11+
})
12+
13+
export default defineConfig([
14+
// coreWebVitals includes Next recommended rules
15+
...compat.extends('plugin:@next/next/core-web-vitals'),
16+
{
17+
files: ['**/*.{js,cjs,mjs,jsx,ts,tsx}'],
18+
rules: {
19+
'@next/next/no-img-element': 'off',
20+
},
21+
},
22+
])
23+
24+
// Alternative/modern approach:
25+
// Working, but has some issues with the Next lint command (running with `next build`).
26+
// This approach can probably be used with Next 16, as they removed Next lint completely.
27+
//
28+
// import next from '@next/eslint-plugin-next'
29+
// import { defineConfig } from 'eslint/config'
30+
// export default defineConfig([
31+
// {
32+
// files: ['**/*.{js,cjs,mjs,jsx,ts,tsx}'],
33+
// // coreWebVitals includes Next recommended rules
34+
// ...next.flatConfig.coreWebVitals,
35+
// rules: {
36+
// '@next/next/no-img-element': 'off',
37+
// },
38+
// },
39+
// ])

configs/react.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { defineConfig } from 'eslint/config'
2+
import jsxA11y from 'eslint-plugin-jsx-a11y'
3+
import reactPlugin from 'eslint-plugin-react'
4+
import reactHooks from 'eslint-plugin-react-hooks'
5+
6+
export default defineConfig([
7+
{
8+
languageOptions: {
9+
parserOptions: {
10+
ecmaFeatures: {
11+
jsx: true,
12+
},
13+
},
14+
},
15+
files: ['**/*.{js,cjs,mjs,jsx,ts,tsx}'],
16+
extends: [
17+
reactPlugin.configs.flat.recommended,
18+
reactPlugin.configs.flat['jsx-runtime'],
19+
reactHooks.configs['recommended-latest'],
20+
jsxA11y.flatConfigs.strict,
21+
],
22+
settings: {
23+
react: {
24+
version: 'detect',
25+
},
26+
},
27+
rules: {
28+
'react/jsx-curly-brace-presence': [
29+
'error',
30+
{ props: 'never', children: 'never', propElementValues: 'always' },
31+
],
32+
'react/self-closing-comp': [
33+
'error',
34+
{
35+
component: true,
36+
html: true,
37+
},
38+
],
39+
'react-hooks/rules-of-hooks': 'error',
40+
'react-hooks/exhaustive-deps': 'error',
41+
'jsx-a11y/no-autofocus': 'off',
42+
},
43+
},
44+
])

configs/storybook.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { defineConfig } from 'eslint/config'
2+
import * as mdx from 'eslint-plugin-mdx'
3+
import { configs as storybookConfigs } from 'eslint-plugin-storybook'
4+
import { configs as tseslintConfigs } from 'typescript-eslint'
5+
6+
export default defineConfig([
7+
{
8+
files: ['**/*.{js,cjs,mjs,jsx,ts,tsx}'],
9+
extends: [storybookConfigs['flat/recommended']],
10+
},
11+
{
12+
ignores: ['!.storybook'],
13+
},
14+
{
15+
...mdx.flat,
16+
processor: mdx.createRemarkProcessor({
17+
lintCodeBlocks: false, // Disable linting of code blocks as it shows irrelevant errors.
18+
}),
19+
},
20+
{
21+
...mdx.flatCodeBlocks,
22+
extends: [tseslintConfigs.disableTypeChecked],
23+
rules: {
24+
'import/no-unresolved': 'off',
25+
},
26+
},
27+
])

0 commit comments

Comments
 (0)