Skip to content

Commit e91d6ad

Browse files
authored
feat!: migrate to eslint flat config (#409)
BREAKING CHANGE: migrate to eslint flat config
1 parent b574861 commit e91d6ad

File tree

13 files changed

+176
-120
lines changed

13 files changed

+176
-120
lines changed

.eslintignore

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

.eslintrc.json

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

.vscode/launch.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Debug Jest Tests with yarn",
9+
"type": "node",
10+
"request": "launch",
11+
"runtimeExecutable": "yarn",
12+
"args": [
13+
"test",
14+
"--",
15+
"--runInBand",
16+
"--coverage=false"
17+
],
18+
"runtimeArgs": [
19+
"--inspect-brk"
20+
],
21+
"console": "integratedTerminal",
22+
"internalConsoleOptions": "neverOpen"
23+
},
24+
{
25+
"name": "eslint",
26+
"type": "node",
27+
"request": "launch",
28+
"runtimeExecutable": "yarn",
29+
"cwd": "${workspaceFolder}",
30+
"runtimeArgs": [
31+
"eslint",
32+
"${relativeFile}"
33+
],
34+
"sourceMaps": true,
35+
}
36+
]
37+
}

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"typescript.tsdk": "node_modules/typescript/lib"
2+
"typescript.tsdk": "node_modules/typescript/lib",
3+
"eslint.experimental.useFlatConfig": true
34
}

__tests__/Tests/Lint.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
3+
/* eslint-disable @typescript-eslint/no-unsafe-call */
4+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
15
/**
26
* @Author: Rostislav Simonik <rostislav.simonik@technologystudio.sk>
37
* @Date: 2018-01-09T00:56:40+01:00
48
* @Copyright: Technology Studio
59
**/
610

7-
import { ESLint } from 'eslint'
11+
const { FlatESLint } = require('eslint/use-at-your-own-risk')
812

913
test('shoud not have lint issues', async () => {
10-
const eslint = new ESLint()
14+
const eslint = new FlatESLint()
1115
const results = await eslint.lintFiles(['test/**/*.ts'])
12-
const isWithoutError = results.every((result) => result.errorCount === 0)
16+
const isWithoutError = results.every((result: { errorCount: number }) => result.errorCount === 0)
1317
expect(isWithoutError).toBe(true)
14-
})
18+
}, 20000)

eslint.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const txoConfig = require('./lib/index.js')
2+
3+
/** @type {import('eslint').Linter.FlatConfig[]} */
4+
const config = [
5+
...txoConfig.default,
6+
{
7+
files: ['test/**/*.ts', 'test/**/*.tsx'],
8+
languageOptions: {
9+
parserOptions: {
10+
project: './tsconfig.test.json'
11+
}
12+
}
13+
}
14+
]
15+
16+
module.exports = config

package.json

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,31 @@
1515
"license": "MIT",
1616
"private": false,
1717
"scripts": {
18-
"lint": "eslint --ext .jsx,.js,.ts,.tsx .",
19-
"fixcode": "eslint --ext .jsx,.js,.ts,.tsx . --fix",
18+
"lint": "eslint --max-warnings 0 .",
19+
"fixcode": "eslint . --fix",
2020
"git-hook": "yarn -s lint",
2121
"compile": "tsc",
2222
"prepare": "husky install && yarn compile",
23-
"sanity": "yarn lint && yarn test && tsc --noEmit && yarn outdated && echo 'success'",
23+
"sanity": "yarn lint && yarn test --coverage && tsc --noEmit && yarn outdated && echo 'success'",
2424
"semantic-release": "semantic-release",
25-
"test": "jest"
25+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
2626
},
2727
"engines": {
2828
"node": ">=18.0.0"
2929
},
3030
"dependencies": {
31-
"eslint-config-txo-typescript": "^3.4.0"
32-
},
33-
"peerDependencies": {
31+
"eslint-config-txo-typescript": "^4.0.2",
3432
"eslint-plugin-jsx-a11y": "^6.8.0",
3533
"eslint-plugin-react": "^7.33.2",
3634
"eslint-plugin-react-hooks": "^4.6.0"
3735
},
3836
"devDependencies": {
3937
"@txo/commitlint": "^1.0.5",
4038
"@txo/semantic-release": "^1.0.2",
39+
"@txo/tsconfig": "^1.1.0",
4140
"@types/eslint": "^8.44.7",
4241
"@types/jest": "^29.5.8",
4342
"@types/react": "^18.2.37",
44-
"@typescript-eslint/eslint-plugin": "^6.10.0",
45-
"@typescript-eslint/parser": "^6.10.0",
46-
"eslint": "^8.53.0",
47-
"eslint-plugin-eslint-comments": "^3.2.0",
48-
"eslint-plugin-import": "^2.29.0",
49-
"eslint-plugin-jest": "^27.6.0",
50-
"eslint-plugin-jsx-a11y": "^6.8.0",
51-
"eslint-plugin-n": "^16.3.0",
52-
"eslint-plugin-promise": "^6.1.1",
53-
"eslint-plugin-react": "^7.33.2",
54-
"eslint-plugin-react-hooks": "^4.6.0",
5543
"husky": "^8.0.3",
5644
"jest": "^29.7.0",
5745
"lint-staged": "^15.0.2",

src/configs/jsx-a11y.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
* @Copyright: Technology Studio
55
**/
66

7-
module.exports = {
8-
rules: {
9-
'jsx-a11y/aria-props': 'error',
10-
'jsx-a11y/label-has-associated-control': [
11-
'error',
12-
{
13-
// NOTE: If this error triggers, either disable it or add
14-
// your custom components, labels and attributes via these options
15-
// See https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-associated-control.md
16-
controlComponents: ['Input'],
17-
},
18-
],
19-
'jsx-a11y/mouse-events-have-key-events': 'error',
20-
'jsx-a11y/role-has-required-aria-props': 'error',
21-
'jsx-a11y/role-supports-aria-props': 'error',
22-
},
7+
import type { Linter } from 'eslint'
8+
9+
export const jsxA11yRules: Linter.RulesRecord = {
10+
'jsx-a11y/aria-props': 'error',
11+
'jsx-a11y/label-has-associated-control': [
12+
'error',
13+
{
14+
// NOTE: If this error triggers, either disable it or add
15+
// your custom components, labels and attributes via these options
16+
// See https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-associated-control.md
17+
controlComponents: ['Input'],
18+
},
19+
],
20+
'jsx-a11y/mouse-events-have-key-events': 'error',
21+
'jsx-a11y/role-has-required-aria-props': 'error',
22+
'jsx-a11y/role-supports-aria-props': 'error',
2323
}

src/configs/react.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
* @Copyright: Technology Studio
55
**/
66

7-
module.exports = {
8-
rules: {
9-
'react-hooks/rules-of-hooks': 'error',
10-
'react-hooks/exhaustive-deps': 'error',
11-
'react/jsx-first-prop-new-line': ['error', 'multiline'],
12-
'react/jsx-uses-vars': 'error',
13-
'react/display-name': 'off',
14-
},
7+
import type { Linter } from 'eslint'
8+
9+
export const reactRules: Linter.RulesRecord = {
10+
'react-hooks/rules-of-hooks': 'error',
11+
'react-hooks/exhaustive-deps': 'error',
12+
'react/jsx-first-prop-new-line': ['error', 'multiline'],
13+
'react/jsx-uses-vars': 'error',
14+
'react/display-name': 'off',
1515
}

src/index.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
2+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
3+
/* eslint-disable @typescript-eslint/no-var-requires */
14
/**
25
* @Author: Rostislav Simonik <rostislav.simonik@technologystudio.sk>
36
* @Author: Erik Slovak <erik.slovak@technologystudio.sk>
47
* @Date: 2020-06-10T16:06:00+02:00
58
* @Copyright: Technology Studio
69
**/
710

8-
module.exports = {
9-
extends: [
10-
'txo-typescript',
11-
...[
12-
'./configs/jsx-a11y',
13-
'./configs/react',
14-
].map(relativePath => require.resolve(relativePath)),
15-
],
16-
parser: '@typescript-eslint/parser',
17-
plugins: [
18-
'@typescript-eslint',
19-
'react',
20-
'react-hooks',
21-
'jsx-a11y',
22-
],
23-
parserOptions: {
24-
ecmaVersion: 6,
25-
sourceType: 'module',
26-
ecmaFeatures: {
27-
jsx: true,
11+
import type { Linter } from 'eslint'
12+
13+
import { jsxA11yRules } from './configs/jsx-a11y'
14+
import { reactRules } from './configs/react'
15+
16+
const txoConfig = require('eslint-config-txo-typescript')
17+
const react = require('eslint-plugin-react')
18+
const reactHooksPlugin = require('eslint-plugin-react-hooks')
19+
const jsxA11yPlugin = require('eslint-plugin-jsx-a11y')
20+
21+
const config: Linter.FlatConfig[] = [
22+
...txoConfig.default,
23+
{
24+
files: ['**/*.ts', '**/*.tsx'],
25+
rules: {
26+
...jsxA11yRules,
27+
...reactRules,
28+
},
29+
plugins: {
30+
'jsx-a11y': jsxA11yPlugin,
31+
'react-hooks': reactHooksPlugin,
32+
react,
2833
},
29-
project: './tsconfig.json',
30-
},
31-
rules: {
32-
strict: 'error',
3334
},
34-
}
35+
]
36+
37+
export default config

0 commit comments

Comments
 (0)