This repository has been archived by the owner on Feb 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
feat(eslint)!: add flat configs #114
Closed
Closed
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e752ec4
refactor(eslint): divide rules and plugins
appano1 c1afd76
feat(eslint): add flat configs
appano1 ea233a0
feat(eslint): add ignores
appano1 1886906
feat(eslint): add settings for eslint-plugin-import
appano1 2dec9e4
fix(eslint): fix wrong path
appano1 dce6743
fix(eslint): add omitted .rules
appano1 adaeecf
feat(eslint): change eslint-comments to @eslint-community/eslint-comm…
appano1 5bb7884
feat(deps): update eslint packages
appano1 406244b
fix(eslint): change prettier to eslint-config-prettier
appano1 073998d
fix(eslint): change prettier to eslint-config-prettier
appano1 cf8513e
refactor(eslint): add settings to check version of react
appano1 0842108
feat(eslint): change .eslintrc.js to eslint.config.mjs
appano1 36cb548
feat(eslint): update vitest npm version
appano1 f51c34b
fix(eslint): fix eslint errors
appano1 8c2176c
style(eslint): fix typo
appano1 007d859
feat(deps): update npm packages
appano1 134a86b
style(eslint): update description url in comment eslint
appano1 87979ff
feat(deps): update npm packages
appano1 061beae
feat(deps)!: update eslint-plugin-testing-library v7
appano1 273aac4
feat(deps): update @babel/eslint-parser package
appano1 a17e381
feat(deps): update npm packages
appano1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import globals from 'globals'; | ||
import flat from './eslint/flat/index.js'; | ||
|
||
/** @type {import('eslint').Linter.Config[]} */ | ||
export default [ | ||
...flat.configs.recommended, | ||
{ | ||
languageOptions: { | ||
globals: { | ||
...globals.node, | ||
}, | ||
}, | ||
}, | ||
{ | ||
files: ['eslint/rules/**'], | ||
rules: { | ||
'sort-keys': 'error', | ||
}, | ||
}, | ||
{ | ||
files: ['*.config.mjs'], | ||
rules: { | ||
'import/no-default-export': 'off', | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module.exports = { | ||
extends: [ | ||
'plugin:eslint-comments/recommended', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I replaced |
||
'plugin:@eslint-community/eslint-comments/recommended', | ||
require.resolve('./rules/comments'), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const babelParser = require('@babel/eslint-parser'); | ||
const eslint = require('@eslint/js'); | ||
const prettier = require('eslint-config-prettier'); | ||
const commentsConfig = require('./comments'); | ||
const importConfig = require('./import'); | ||
const unicornConfig = require('./unicorn'); | ||
const { ECMA_VERSION, JAVASCRIPT_FILES } = require('./constants'); | ||
|
||
/** | ||
* This is the base for both our browser and Node ESLint config files. | ||
* @type {import('eslint').Linter.Config[]} | ||
*/ | ||
module.exports = [ | ||
eslint.configs.recommended, | ||
prettier, | ||
commentsConfig, | ||
importConfig, | ||
unicornConfig, | ||
{ | ||
rules: { | ||
...require('../rules/best-practice').rules, | ||
...require('../rules/es6').rules, | ||
...require('../rules/possible-errors').rules, | ||
...require('../rules/stylistic').rules, | ||
...require('../rules/variables').rules, | ||
}, | ||
settings: { | ||
'import/resolver': { | ||
typescript: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
files: JAVASCRIPT_FILES, | ||
ignores: ['!.*.js'], | ||
linterOptions: { | ||
reportUnusedDisableDirectives: 'warn', | ||
}, | ||
languageOptions: { | ||
ecmaVersion: ECMA_VERSION, | ||
sourceType: 'module', | ||
parser: babelParser, | ||
parserOptions: { | ||
requireConfigFile: false, | ||
}, | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const comments = require('@eslint-community/eslint-plugin-eslint-comments/configs'); | ||
|
||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
...comments.recommended, | ||
rules: { | ||
...comments.recommended.rules, | ||
...require('../rules/comments').rules, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
ECMA_VERSION: 2021, | ||
JAVASCRIPT_FILES: ['**/*.js?(x)', '**/*.(c|m)?js'], | ||
TYPESCRIPT_FILES: ['**/*.ts?(x)'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const importPlugin = require('eslint-plugin-import'); | ||
|
||
/** @type {improt('eslint').Linter.Config} */ | ||
appano1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
module.exports = { | ||
...importPlugin.flatConfigs.recommended, | ||
rules: { | ||
...importPlugin.flatConfigs.recommended.rules, | ||
...require('../rules/import').rules, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
configs: { | ||
recommended: require('./_base'), | ||
jest: require('./jest'), | ||
'jest-typescript': require('./jest-typescript'), | ||
next: require('./next'), | ||
'playwright-test': require('./playwright-test'), | ||
react: require('./react'), | ||
'testing-library': require('./testing-library'), | ||
typescript: require('./typescript'), | ||
vitest: require('./vitest'), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { TYPESCRIPT_FILES } = require('./constants'); | ||
|
||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
files: TYPESCRIPT_FILES, | ||
rules: { | ||
'@typescript-eslint/unbound-method': 'off', | ||
'jest/unbound-method': 'error', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const jest = require('eslint-plugin-jest'); | ||
|
||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
...jest.configs['flat/recommended'], | ||
rules: { | ||
...jest.configs['flat/recommended'].rules, | ||
...require('../rules/jest').rules, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const next = require('@next/eslint-plugin-next'); | ||
const requirePackage = require('../utils/require-package'); | ||
const { JAVASCRIPT_FILES } = require('./constants'); | ||
|
||
requirePackage('next', '@next/eslint-plugin-next'); | ||
|
||
const babelOptions = { | ||
presets: (() => { | ||
try { | ||
require.resolve('next/babel'); | ||
return ['next/babel']; | ||
} catch { | ||
return []; | ||
} | ||
})(), | ||
}; | ||
|
||
/** @type {import('eslint').Linter.Config[]} */ | ||
module.exports = [ | ||
{ | ||
plugins: { | ||
'@next/next': next, | ||
}, | ||
rules: { | ||
...next.configs.recommended.rules, | ||
}, | ||
languageOptions: { | ||
parserOptions: { | ||
babelOptions, | ||
}, | ||
}, | ||
ignores: ['**/.next/**'], | ||
}, | ||
{ | ||
files: JAVASCRIPT_FILES, | ||
languageOptions: { | ||
parserOptions: { | ||
babelOptions, | ||
}, | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const playwright = require('eslint-plugin-playwright'); | ||
|
||
/** @type {import('eslint').Linter} */ | ||
module.exports = { | ||
...playwright.configs['flat/recommended'], | ||
rules: { | ||
...playwright.configs['flat/recommended'].rules, | ||
...require('../rules/playwright-test').rules, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const react = require('eslint-plugin-react'); | ||
const reactHooks = require('eslint-plugin-react-hooks'); | ||
const jsxA11y = require('eslint-plugin-jsx-a11y'); | ||
const importPlugin = require('eslint-plugin-import'); | ||
const prettier = require('eslint-config-prettier'); | ||
|
||
/** @type {import('eslint').Linter.Config[]} */ | ||
module.exports = [ | ||
react.configs.flat.recommended, | ||
react.configs.flat['jsx-runtime'], | ||
{ | ||
plugins: { | ||
'react-hooks': reactHooks, | ||
}, | ||
rules: { | ||
...reactHooks.configs.recommended.rules, | ||
}, | ||
}, | ||
jsxA11y.flatConfigs.recommended, | ||
{ | ||
rules: { | ||
...require('../rules/react').rules, | ||
...require('../rules/jsx-a11y').rules, | ||
}, | ||
settings: { | ||
react: { | ||
version: 'detect', | ||
}, | ||
}, | ||
}, | ||
importPlugin.flatConfigs.react, | ||
prettier, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const testingLibrary = require('eslint-plugin-testing-library'); | ||
|
||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
...testingLibrary.configs['flat/react'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const tsdoc = require('eslint-plugin-tsdoc'); | ||
|
||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
plugins: { | ||
tsdoc, | ||
}, | ||
rules: { | ||
...require('../rules/tsdoc').rules, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const tseslint = require('typescript-eslint'); | ||
const importPlugin = require('eslint-plugin-import'); | ||
const prettier = require('eslint-config-prettier'); | ||
const requirePackage = require('../utils/require-package'); | ||
const { TYPESCRIPT_FILES } = require('./constants'); | ||
const tsdoc = require('./tsdoc'); | ||
|
||
requirePackage('typescript', 'typescript'); | ||
|
||
/** @type {import('eslint').Linter.Config[]} */ | ||
module.exports = [ | ||
...tseslint.configs.strictTypeChecked, | ||
...tseslint.configs.stylisticTypeChecked, | ||
importPlugin.flatConfigs.typescript, | ||
prettier, | ||
tsdoc, | ||
{ | ||
files: TYPESCRIPT_FILES, | ||
rules: { | ||
...require('../rules/typescript').rules, | ||
...require('../rules/typescript/extension').rules, | ||
...require('../rules/typescript/import').rules, | ||
}, | ||
settings: { | ||
'import/resolver': { | ||
typescript: true, | ||
}, | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const unicorn = require('eslint-plugin-unicorn'); | ||
|
||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
plugins: { | ||
unicorn, | ||
}, | ||
rules: { | ||
...require('../rules/unicorn').rules, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const vitest = require('@vitest/eslint-plugin'); | ||
|
||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
plugins: { | ||
vitest, | ||
}, | ||
rules: { | ||
...vitest.configs.recommended.rules, | ||
...require('../rules/vitest').rules, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
module.exports = { | ||
plugins: ['eslint-comments'], | ||
rules: { | ||
/** | ||
* Require comments on ESlint disable directives. | ||
* | ||
* 🚫 Not fixable - https://mysticatea.github.io/eslint-plugin-eslint-comments/rules/require-description.html | ||
*/ | ||
'eslint-comments/require-description': 'error', | ||
'@eslint-community/eslint-comments/require-description': 'error', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
module.exports = { | ||
plugins: ['unicorn'], | ||
rules: { | ||
/** | ||
* Require consistent filename case for all linted files. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
plugins: ['eslint-plugin-tsdoc'], | ||
extends: [require.resolve('./rules/tsdoc')], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
plugins: ['unicorn'], | ||
extends: [require.resolve('./rules/unicorn.js')], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comments config and a unicorn config to ensure that only pure rules, excluding plugins, are in the rules directory.