From 0b634e308f1060b77b337ed1d47a0b84311fd337 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 2 Sep 2024 16:47:13 +0200 Subject: [PATCH] feat(lint): unify configuration for linting tools (#21) * feat(lint): unify configuration for linting tools * feat(lint): unify configuration for linting tools --- sample/src/components/counter/Counter.tsx | 1 - sample/src/containers/welcome/Welcome.tsx | 3 +- sample/src/main.tsx | 1 - sample/src/pages/home-page/HomePage.tsx | 1 - sample/vite.config.ts | 3 +- src/.eslintrc.js | 126 ++++++++++++++++------ src/.prettierrc.js | 12 +-- 7 files changed, 98 insertions(+), 49 deletions(-) diff --git a/sample/src/components/counter/Counter.tsx b/sample/src/components/counter/Counter.tsx index 6b973a7..a66ceb5 100644 --- a/sample/src/components/counter/Counter.tsx +++ b/sample/src/components/counter/Counter.tsx @@ -1,5 +1,4 @@ import { useCounter } from '../../hooks/useCounter'; - import { StyledButton, StyledCounter } from './Counter.styles'; export function Counter() { diff --git a/sample/src/containers/welcome/Welcome.tsx b/sample/src/containers/welcome/Welcome.tsx index 0828653..1a4b54a 100644 --- a/sample/src/containers/welcome/Welcome.tsx +++ b/sample/src/containers/welcome/Welcome.tsx @@ -1,6 +1,5 @@ -import { WelcomeProps } from './Welcome.types'; - import { StyledWelcome } from './Welcome.styles'; +import { WelcomeProps } from './Welcome.types'; export function Welcome({ children, message = 'Welcome!' }: WelcomeProps) { return ( diff --git a/sample/src/main.tsx b/sample/src/main.tsx index c56c0b0..fbc6427 100644 --- a/sample/src/main.tsx +++ b/sample/src/main.tsx @@ -2,7 +2,6 @@ import { StrictMode } from 'react'; import ReactDOM from 'react-dom/client'; import { App } from './App'; - import './styles/index.css'; ReactDOM.createRoot(document.getElementById('root')!).render( diff --git a/sample/src/pages/home-page/HomePage.tsx b/sample/src/pages/home-page/HomePage.tsx index bdb26c5..d87cf29 100644 --- a/sample/src/pages/home-page/HomePage.tsx +++ b/sample/src/pages/home-page/HomePage.tsx @@ -1,6 +1,5 @@ import { Counter } from '../../components/counter'; import { Welcome } from '../../containers/welcome'; - import { StyledHomePage } from './HomePage.styles'; export function HomePage() { diff --git a/sample/vite.config.ts b/sample/vite.config.ts index 4e7004e..56f6a02 100644 --- a/sample/vite.config.ts +++ b/sample/vite.config.ts @@ -1,6 +1,7 @@ -import react from '@vitejs/plugin-react'; import { defineConfig } from 'vite'; +import react from '@vitejs/plugin-react'; + // https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], diff --git a/src/.eslintrc.js b/src/.eslintrc.js index 499b803..552a9b0 100644 --- a/src/.eslintrc.js +++ b/src/.eslintrc.js @@ -2,54 +2,116 @@ module.exports = { env: { browser: true, commonjs: true, - es2021: true, + es6: true, jest: true, }, extends: [ - 'eslint:recommended', 'plugin:@typescript-eslint/recommended', - 'plugin:import/recommended', - 'plugin:import/typescript', 'plugin:jest/recommended', 'plugin:prettier/recommended', - 'plugin:react/recommended', + 'prettier', 'plugin:react-hooks/recommended', ], + globals: { + Landbot: false, + LandbotFrameWidget: false, + LandbotFullpage: false, + __dirname: false, + process: false, + }, + ignorePatterns: [ + 'src/plugin/*', + 'babel.config.js', + 'prettier.config.js', + 'commitlint.config.js', + '.eslintrc.js', + 'LOCAL_SETTINGS.js', + ], + overrides: [ + { + files: ['./src/**/*.{ts,tsx}'], + rules: { + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/no-empty-interface': [ + 'error', + { + allowSingleExtends: true, + }, + ], + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/no-unused-vars': [ + 'error', + { + argsIgnorePattern: '^_', + caughtErrorsIgnorePattern: '^_', + varsIgnorePattern: '^_', + }, + ], + 'no-unused-vars': 'off', + 'no-undef-init': 'warn', + }, + }, + ], parser: '@typescript-eslint/parser', parserOptions: { - ecmaFeatures: { - jsx: true, - }, - ecmaVersion: 'latest', + ecmaVersion: 2018, + project: './tsconfig.json', + sourceType: 'module', }, - plugins: ['@typescript-eslint', 'check-file', 'import', 'jest', 'prettier', 'react'], + plugins: ['react', '@typescript-eslint', 'prettier', 'import', 'jest'], + root: true, rules: { - '@typescript-eslint/no-explicit-any': 'error', - '@typescript-eslint/no-unused-vars': 'error', - 'check-file/folder-naming-convention': ['error', { 'src/**/': 'KEBAB_CASE' }], - 'check-file/folder-match-with-fex': [ + '@typescript-eslint/no-unused-vars': [ 'error', { - '*.test.{js,jsx,ts,tsx}': '!**/__tests__/', - '*.test.{js,jsx,ts,tsx}': '!**/__test__/', + argsIgnorePattern: '^_', + caughtErrorsIgnorePattern: '^_', + varsIgnorePattern: '^_', }, ], - 'import/no-default-export': 'off', - 'prettier/prettier': ['error', require('./.prettierrc.js')], - 'react/jsx-uses-react': 'off', - 'react/react-in-jsx-scope': 'off', - }, - overrides: [ - { - files: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.js', 'src/**/*.jsx'], - rules: { - 'import/no-default-export': 'error', + 'import/no-extraneous-dependencies': 'off', + 'linebreak-style': 'off', + 'no-console': 'error', + 'no-restricted-imports': [ + 'error', + { + paths: [ + { + importNames: ['default', 'pricing'], + message: + "Please use the context 'usePricingContext' from 'src/context' instead of the instance from 'core/pricing'.", + name: 'core/pricing', + }, + { + importNames: ['default'], + message: + "Please use the context 'useSettingsContext' from 'src/context' instead of the instance from 'core/SETTINGS'.", + name: 'core/SETTINGS', + }, + { + importNames: ['faker'], + message: "Please import { faker } from '@faker-js/faker/locale/en' instead due to performance issues", + name: '@faker-js/faker', + }, + { + message: "Please use more specific import: import format from 'date-fns/format'", + name: 'date-fns', + }, + ], + patterns: [ + { + group: ['analytics.legacy', './analytics.legacy'], + message: "Please import analytics from 'core/analytics' instead", + }, + ], }, - }, - ], - settings: { - react: { - version: 'detect', - }, + ], + 'prettier/prettier': [ + 'error', + { + endOfLine: 'auto', + }, + ], }, }; diff --git a/src/.prettierrc.js b/src/.prettierrc.js index 60f47ff..36db17c 100644 --- a/src/.prettierrc.js +++ b/src/.prettierrc.js @@ -1,18 +1,8 @@ module.exports = { - semi: true, - trailingComma: 'all', singleQuote: true, printWidth: 120, - tabWidth: 2, - endOfLine: 'lf', plugins: [require.resolve('@trivago/prettier-plugin-sort-imports')], - importOrder: [ - '^(react|react-dom(.*))$', - '', - '@/(.*)', - '^[./].*(?