diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..a5c7ce79 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,5 @@ +node_modules +out +docs +!.storybook +.archive \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..18eec8dc --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,100 @@ +{ + // Configuration for JavaScript files + "extends": [ + "airbnb-base", + "next/core-web-vitals", // Needed to avoid warning in next.js build: 'The Next.js plugin was not detected in your ESLint configuration' + "plugin:prettier/recommended" + ], + "rules": { + "prettier/prettier": [ + "error", + { + "singleQuote": true, + "endOfLine": "auto" + } + ] // Avoid conflict rule between Prettier and Airbnb Eslint + }, + "overrides": [ + // Configuration for TypeScript files + { + "files": ["**/*.ts", "**/*.tsx"], + "plugins": [ + "@typescript-eslint", + "unused-imports", + "tailwindcss", + "simple-import-sort" + ], + "extends": [ + "plugin:tailwindcss/recommended", + "airbnb", + "airbnb-typescript", + "next/core-web-vitals", + "plugin:prettier/recommended" + ], + "parserOptions": { + "project": "./tsconfig.json" + }, + "rules": { + "prettier/prettier": [ + "error", + { + "singleQuote": true, + "endOfLine": "auto" + } + ], // Avoid conflict rule between Prettier and Airbnb Eslint + "import/extensions": "off", // Avoid missing file extension errors, TypeScript already provides a similar feature + "react/function-component-definition": "off", // Disable Airbnb's specific function type + "react/destructuring-assignment": "off", // Vscode doesn't support automatically destructuring, it's a pain to add a new variable + "react/require-default-props": "off", // Allow non-defined react props as undefined + "react/jsx-props-no-spreading": "off", // _app.tsx uses spread operator and also, react-hook-form + "@typescript-eslint/comma-dangle": "off", // Avoid conflict rule between Eslint and Prettier + "@typescript-eslint/consistent-type-imports": "error", // Ensure `import type` is used when it's necessary + "no-restricted-syntax": [ + "error", + "ForInStatement", + "LabeledStatement", + "WithStatement" + ], // Overrides Airbnb configuration and enable no-restricted-syntax + "import/prefer-default-export": "off", // Named export is easier to refactor automatically + "simple-import-sort/imports": "error", // Import configuration for `eslint-plugin-simple-import-sort` + "simple-import-sort/exports": "error", // Export configuration for `eslint-plugin-simple-import-sort` + "import/order": "off", // Avoid conflict rule between `eslint-plugin-import` and `eslint-plugin-simple-import-sort` + "@typescript-eslint/no-unused-vars": "off", + "unused-imports/no-unused-imports": "error", + "unused-imports/no-unused-vars": [ + "error", + { "argsIgnorePattern": "^_" } + ] + } + }, + // Configuration for testing + { + "files": ["**/*.test.ts", "**/*.test.tsx"], + "plugins": ["jest", "jest-formatting", "testing-library", "jest-dom"], + "extends": [ + "plugin:jest/recommended", + "plugin:jest-formatting/recommended", + "plugin:testing-library/react", + "plugin:jest-dom/recommended" + ] + }, + // Configuration for e2e testing (Playwright) + { + "files": ["**/*.spec.ts"], + "extends": ["plugin:playwright/recommended"] + }, + // Configuration for Storybook + { + "files": ["*.stories.*"], + "extends": ["plugin:storybook/recommended"], + "rules": { + "import/no-extraneous-dependencies": [ + "error", + { + "devDependencies": true + } + ] + } + } + ] +} diff --git a/lint-staged.config.js b/lint-staged.config.js new file mode 100644 index 00000000..2eea632e --- /dev/null +++ b/lint-staged.config.js @@ -0,0 +1,5 @@ +module.exports = { + '*.{js,jsx,ts,tsx}': ['eslint --fix', 'eslint'], + '**/*.ts?(x)': () => 'npm run check-types', + '*.{json,yaml}': ['prettier --write'], +};