Skip to content

Commit

Permalink
Bump typescript-eslint, switch to flat eslint config (#4930)
Browse files Browse the repository at this point in the history
* Bump eslint, typescript-eslint

    npm un @typescript-eslint/parser @typescript-eslint/eslint-plugin
    npm install --save-dev typescript-eslint@latest eslint@latest eslint-config-prettier@latest eslint-plugin-react@latest

https://typescript-eslint.io/blog/announcing-typescript-eslint-v7/

No-Issue

* remove all .eslintrc

* call eslint without --ext

* add globals dev-dep

* eslint.config.mjs: working config

* fix a bunch of no-const/no-var warnings in tests

* no extends

* reportUnusedDisableDirectives
  • Loading branch information
himdel authored Mar 20, 2024
1 parent 7197baa commit 376b9d1
Show file tree
Hide file tree
Showing 19 changed files with 298 additions and 191 deletions.
64 changes: 0 additions & 64 deletions .eslintrc

This file was deleted.

5 changes: 0 additions & 5 deletions config/.eslintrc

This file was deleted.

136 changes: 136 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import eslint from '@eslint/js';
import prettierConfig from 'eslint-config-prettier';
import reactPlugin from 'eslint-plugin-react';
import globals from 'globals';
import {
config,
parser,
configs as tsConfigs,
plugin as tsPlugin,
} from 'typescript-eslint';

// require('eslint-plugin-react/configs/recommended') does the right thing but can't be imported
// and the .configs.recommended export adds flatconfig-invalid .plugins and .parserOptions .. remove
const reactConfig = {
...reactPlugin.configs.recommended,
plugins: { react: reactPlugin }, // fix for plugins: ['react']
};
delete reactConfig.parserOptions;

export default config(
eslint.configs.recommended,
reactConfig,
...tsConfigs.recommended,
...tsConfigs.stylistic,
prettierConfig,
{
files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
plugins: {
'@typescript-eslint': tsPlugin,
react: reactPlugin,
},
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
parser,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
globals: {
...globals.browser,
},
},
settings: {
react: {
version: 'detect',
},
},
linterOptions: {
reportUnusedDisableDirectives: true,
},
rules: {
curly: ['error', 'all'],
'eol-last': ['error', 'always'],
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_' },
],
'@typescript-eslint/consistent-type-imports': [
'error',
{ fixStyle: 'inline-type-imports' },
],
'no-restricted-imports': [
'error',
{
paths: [
{
importNames: [
'Alert',
'Breadcrumb',
'Chip',
'ChipGroup',
'ClipboardCopy',
'ClipboardCopyButton',
'FileUpload',
'Icon',
'LabelGroup',
'LoginForm',
'NavList',
'Pagination',
'Popover',
'SearchInput',
'Spinner',
'Tooltip',
],
message: 'Import from src/components instead.',
name: '@patternfly/react-core',
},
{
importNames: ['CodeEditor'],
message: 'Import from src/components instead.',
name: '@patternfly/react-code-editor',
},
],
},
],
},
},
{
files: ['config/*.js'],
languageOptions: {
globals: {
...globals.node,
},
},
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
{
files: ['src/components/patternfly-wrappers/*.{js,jsx,ts,tsx}'],
rules: {
'no-restricted-imports': 'off',
},
},
{
files: ['test/**/*.{js,jsx,ts,tsx}'],
languageOptions: {
globals: {
...globals.node,
Cypress: 'readonly',
after: 'readonly',
before: 'readonly',
beforeEach: 'readonly',
cy: 'readonly',
describe: 'readonly',
expect: 'readonly',
it: 'readonly',
},
},
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
);
Loading

0 comments on commit 376b9d1

Please sign in to comment.