-
Notifications
You must be signed in to change notification settings - Fork 0
feat(eslint-config): migrate to native flat config and upgrade to ESLint 10 / @wordpress/eslint-plugin 25 #140
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
Merged
Merged
Changes from all commits
Commits
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 contains hidden or 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 hidden or 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 hidden or 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,17 +1,13 @@ | ||
| const globals = require( 'globals' ); | ||
| const babelParser = require( '@babel/eslint-parser' ); | ||
| const tsParser = require( '@typescript-eslint/parser' ); | ||
| const tsPlugin = require( '@typescript-eslint/eslint-plugin' ); | ||
| const { fixupConfigRules } = require( '@eslint/compat' ); | ||
| const js = require( '@eslint/js' ); | ||
| const { FlatCompat } = require( '@eslint/eslintrc' ); | ||
| const wordpress = require( '@wordpress/eslint-plugin' ); | ||
| const tseslint = require( 'typescript-eslint' ); | ||
| const resolveImportAliases = require( './utils/resolve-import-aliases' ); | ||
|
|
||
| const compat = new FlatCompat( { | ||
| baseDirectory: __dirname, | ||
| recommendedConfig: js.configs.recommended, | ||
| allConfig: js.configs.all, | ||
| } ); | ||
| // The plugin only registers prettier when `prettier` is installed. Referencing | ||
| // prettier/prettier otherwise throws "Could not find plugin 'prettier'". | ||
| const prettierRegistered = wordpress.configs.recommended.some( | ||
| ( config ) => config.plugins && config.plugins.prettier | ||
| ); | ||
|
|
||
| // Shared between the JS/JSX and TS/TSX configs. | ||
| const sharedGlobals = { | ||
|
|
@@ -29,37 +25,18 @@ const sharedSettings = { | |
|
|
||
| // Formatting is owned by Prettier (`pnpm format`), not ESLint. | ||
| const sharedRules = { | ||
| 'prettier/prettier': 0, | ||
| 'jsdoc/require-param': 0, | ||
| 'import/no-extraneous-dependencies': 0, | ||
| ...( prettierRegistered ? { 'prettier/prettier': 0 } : {} ), | ||
| }; | ||
|
|
||
| module.exports = [ | ||
| ...fixupConfigRules( | ||
| compat.extends( | ||
| 'plugin:@wordpress/eslint-plugin/recommended', | ||
| 'prettier' | ||
| ) | ||
| ), | ||
| ...wordpress.configs.recommended, | ||
| { | ||
| files: [ '**/*.js', '**/*.jsx' ], | ||
| languageOptions: { | ||
| globals: sharedGlobals, | ||
|
|
||
| parser: babelParser, | ||
|
|
||
| parserOptions: { | ||
| requireConfigFile: false, | ||
|
|
||
| babelOptions: { | ||
| presets: [ '@babel/preset-react' ], | ||
| }, | ||
| ecmaFeatures: { | ||
| jsx: true, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| rules: { | ||
| ...sharedRules, | ||
| 'no-unused-expressions': [ | ||
|
|
@@ -70,32 +47,25 @@ module.exports = [ | |
| ], | ||
| 'import/no-unresolved': [ 'error', { ignore: [ '^@wordpress/' ] } ], | ||
| }, | ||
|
|
||
| settings: { | ||
| ...sharedSettings, | ||
| 'import/resolver': { | ||
| alias: resolveImportAliases(), | ||
| }, | ||
| }, | ||
| }, | ||
| // Register TS ourselves so it works regardless of whether the consumer has | ||
| // `typescript` installed. Scoped to TS files to keep the babel parser on JS. | ||
| ...tseslint.configs.recommended.map( ( config ) => ( { | ||
| ...config, | ||
| files: [ '**/*.ts', '**/*.tsx' ], | ||
|
Comment on lines
+59
to
+63
Contributor
Author
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. True maar we gebruiken nooit .mts of .cts bestanden, dus deze laat ik |
||
| } ) ), | ||
| { | ||
| files: [ '**/*.ts', '**/*.tsx' ], | ||
| languageOptions: { | ||
| globals: sharedGlobals, | ||
|
|
||
| // The @typescript-eslint plugin is already registered by | ||
| // @wordpress/eslint-plugin/recommended above; only set the parser. | ||
| parser: tsParser, | ||
|
|
||
| parserOptions: { | ||
| ecmaFeatures: { | ||
| jsx: true, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| rules: { | ||
| ...tsPlugin.configs.recommended.rules, | ||
| ...sharedRules, | ||
| // TS-aware version replaces the core rule. | ||
| 'no-unused-expressions': 0, | ||
|
|
@@ -105,10 +75,9 @@ module.exports = [ | |
| allowTernary: true, | ||
| }, | ||
| ], | ||
| // TypeScript + the bundler resolve modules (incl. path aliases). | ||
| // TS + bundler resolve modules, incl. path aliases. | ||
| 'import/no-unresolved': 0, | ||
| }, | ||
|
|
||
| settings: sharedSettings, | ||
| }, | ||
| ]; | ||
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.
Linting gaat via de @yardinternet/toolkit package, en daar staat hij bij. Hier is ie niet nodig