Skip to content
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

chore: migrate to eslint flat config #5493

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
144 changes: 0 additions & 144 deletions .eslintrc.yml

This file was deleted.

209 changes: 209 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
// @ts-check

import pluginImport from 'eslint-plugin-import';
import pluginNoOnlyTests from 'eslint-plugin-no-only-tests';
import pluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import pluginReactHooks from 'eslint-plugin-react-hooks';
import reactJsxRuntime from 'eslint-plugin-react/configs/jsx-runtime.js';
import reactRecommended from 'eslint-plugin-react/configs/recommended.js';
import pluginStorybook from 'eslint-plugin-storybook';
import globals from 'globals';
import tseslint from 'typescript-eslint';

/** @type { import("eslint").Linter.FlatConfig } */
const typescriptConfig = {
files: ['*.ts', '*.tsx'],
parserOptions: {
project: ['./tsconfig.spec.json', './tsconfig.node.json', './packages/*/tsconfig.json'],
settings: {
'import/resolver': {
typescript: true
}
}
},
rules: {
// disabled some rules from the recommended preset
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/no-explicit-any': 'warn',

// consistent type exports/imports
'@typescript-eslint/consistent-type-exports': [
'error',
{
fixMixedExportsWithInlineTypeSpecifier: false
}
],
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
fixStyle: 'separate-type-imports'
}
],

// lots of UI5 Web Components API are promised based but 'fire and forget' is sufficient for us
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-unused-vars': [
'error',
{
varsIgnorePattern: '^_'
}
],

// Performance Improvements: https://typescript-eslint.io/linting/troubleshooting/performance-troubleshooting#eslint-plugin-import
'import/named': 'off',
'import/namespace': 'off',
'import/default': 'off',
'import/no-named-as-default-member': 'off'
}
};

/** @type { import("eslint").Linter.FlatConfig } */
const webComponentsConfig = {
files: ['packages/main/src/webComponents/*/index.tsx'],
rules: {
'@typescript-eslint/no-empty-interface': 'off'
}
};

/** @type { import("eslint").Linter.FlatConfig[] } */
const cypressConfig = [
{
files: ['cypress/**/*', '*.cy.ts', '*.cy.tsx'],
...reactJsxRuntime
},
{
files: ['cypress/**/*'],
rules: {
'@typescript-eslint/no-namespace': 'off'
}
},
{
files: ['*.cy.ts', '*.cy.tsx'],
plugins: { 'no-only-tests': pluginNoOnlyTests },
rules: {
'@typescript-eslint/no-empty-function': 'off',
'react/react-in-jsx-scope': 'off',
'import/order': 'warn',
'import/no-unresolved': 'off',
'react/no-unescaped-entities': 'off',
'@typescript-eslint/unbound-method': 'warn',
'react/display-name': 'off',
'no-only-tests/no-only-tests': 'error'
}
}
];

/** @type { import("eslint").Linter.FlatConfig[] } */
const storybookConfig = [
{
files: ['*.stories.tsx'],
...reactJsxRuntime
},
{
files: ['*.stories.tsx'],
extends: [pluginStorybook.configs.recommended],
rules: {
// inline custom components within stories don't need prop types
'react/prop-types': 'off',
// some samples can include unused vars to show the API / signature
'@typescript-eslint/no-unused-vars': 'warn',
'react/no-unescaped-entities': 'off'
}
}
];

/** @type { import("eslint").Linter.FlatConfig[] } */
const specialComponents = [
// AnalyticalTable
{
files: [
'packages/main/src/components/AnalyticalTable/defaults/**/*.tsx',
'packages/main/src/components/AnalyticalTable/hooks/*.ts',
'packages/main/src/components/AnalyticalTable/hooks/*.tsx',
'packages/main/src/components/AnalyticalTable/TableBody/VirtualTableBodyContainer.tsx'
],
rules: {
'react/prop-types': 'off'
}
}
];

const config = tseslint.config(
...tseslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
reactRecommended,
pluginImport.configs.recommended,
pluginImport.configs.typescript,
{
languageOptions: {
sourceType: 'module',
parserOptions: {
ecmaFeatures: {
jsx: true
}
},
globals: {
...globals.browser
}
},
plugins: {
'react-hooks': pluginReactHooks
},
settings: {
react: {
version: 'detect'
}
},
rules: {
camelcase: [
'error',
{
allow: [
'sap_fiori_3',
'sap_fiori_3_dark',
'sap_fiori_3_hcb',
'sap_fiori_3_hcw',
'sap_belize',
'sap_belize_hcb',
'sap_belize_hcw',
'sap_horizon',
'sap_horizon_dark',
'sap_horizon_hcb',
'sap_horizon_hcw'
]
}
],
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'import/order': [
'error',
{
'newlines-between': 'never',
alphabetize: {
order: 'asc',
caseInsensitive: true
}
}
],
'import/no-duplicates': 'error',
'import/no-unresolved': 'error'
}
},
typescriptConfig,
webComponentsConfig,
...cypressConfig,
...storybookConfig,
...specialComponents,
pluginPrettierRecommended
);

console.log('-> config', config);
export default config;
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"clean": "tsc --build --clean && rimraf temp .out && lerna run clean",
"clean:remove-modules": "yarn clean && rimraf node_modules",
"prettier:all": "prettier --write --config ./prettier.config.cjs \"packages/**/*.{js,jsx,ts,tsx,mdx,json,md}\"",
"lint": "eslint packages --ext .ts,.tsx",
"lint": "eslint packages",
"lerna:version-dryrun": "lerna version --conventional-graduate --no-git-tag-version --no-push",
"wrappers:main": "WITH_WEB_COMPONENT_IMPORT_PATH='../../internal/withWebComponent.js' INTERFACES_IMPORT_PATH='../../types/index.js' node packages/cli/dist/bin/index.js create-wrappers --packageName @ui5/webcomponents --out ./packages/main/src/webComponents --additionalComponentNote 'This is a UI5 Web Component! [Repository](https://github.com/SAP/ui5-webcomponents) | [Documentation](https://sap.github.io/ui5-webcomponents/playground/)'",
"wrappers:fiori": "WITH_WEB_COMPONENT_IMPORT_PATH='../../internal/withWebComponent.js' INTERFACES_IMPORT_PATH='../../types/index.js' node packages/cli/dist/bin/index.js create-wrappers --packageName @ui5/webcomponents-fiori --out ./packages/main/src/webComponents --additionalComponentNote 'This is a UI5 Web Component! [Repository](https://github.com/SAP/ui5-webcomponents) | [Documentation](https://sap.github.io/ui5-webcomponents/playground/)'",
Expand All @@ -44,7 +44,8 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"remark-gfm": "^3.0.1",
"tocbot": "^4.12.0"
"tocbot": "^4.12.0",
"typescript-eslint": "^7.0.1"
},
"devDependencies": {
"@babel/cli": "^7.20.7",
Expand All @@ -55,12 +56,11 @@
"@cypress/code-coverage": "^3.10.0",
"@semantic-release/github": "^9.0.0",
"@testing-library/cypress": "^10.0.0",
"@types/eslint": "^8.56.2",
"@types/node": "^20.0.0",
"@types/react": "^18.2.23",
"@types/react-dom": "^18.2.7",
"@types/turndown": "^5.0.4",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"@ui5/webcomponents-tools": "1.22.0",
"@vitejs/plugin-react": "^4.2.0",
"chromatic": "^10.0.0",
Expand All @@ -73,7 +73,6 @@
"eslint-import-resolver-typescript": "^3.5.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
Expand Down