-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(eslint): add flat configs #114
base: canary
Are you sure you want to change the base?
Changes from 11 commits
e752ec4
c1afd76
ea233a0
1886906
2dec9e4
dce6743
adaeecf
5bb7884
406244b
073998d
cf8513e
0842108
36cb548
f51c34b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'), | ||
], | ||
}; |
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, | ||
}, | ||
}, | ||
}, | ||
]; |
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, | ||
}, | ||
}; |
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)'], | ||
}; |
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} */ | ||
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. You have a typo here. |
||
module.exports = { | ||
...importPlugin.flatConfigs.recommended, | ||
rules: { | ||
...importPlugin.flatConfigs.recommended.rules, | ||
...require('../rules/import').rules, | ||
}, | ||
}; |
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'), | ||
}, | ||
}; |
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', | ||
}, | ||
}; |
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, | ||
}, | ||
}; |
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 (e) { | ||
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, | ||
}, | ||
}, | ||
}, | ||
]; |
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, | ||
}, | ||
}; |
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, | ||
]; |
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'], | ||
}; |
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, | ||
}, | ||
}; |
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, | ||
}, | ||
}, | ||
}, | ||
]; |
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, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const vitest = require('eslint-plugin-vitest'); | ||
|
||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
plugins: { | ||
vitest, | ||
}, | ||
rules: { | ||
...vitest.configs.recommended.rules, | ||
...require('../rules/vitest').rules, | ||
}, | ||
}; |
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', | ||
}, | ||
}; |
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. | ||
|
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')], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
plugins: ['unicorn'], | ||
extends: [require.resolve('./rules/unicorn.js')], | ||
}; |
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.