diff --git a/.eslintrc.json b/.eslintrc.json index eea9c84..9600166 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,3 @@ { - "extends": ["@rambler-tech/eslint-config", "prettier"], - "parserOptions": { - "requireConfigFile": false - } + "extends": ["@rambler-tech/eslint-config"] } diff --git a/package.json b/package.json index 4c07fdb..a3144b8 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "devDependencies": { "@commitlint/cli": "^17", "eslint": "^8.49.0", - "eslint-config-prettier": "^9.0.0", "husky": "^8.0.3", "lerna": "^7.3.0", "lint-staged": "^14.0.1", diff --git a/packages/eslint-config/README.md b/packages/eslint-config/README.md index 09dc04d..fcc639e 100644 --- a/packages/eslint-config/README.md +++ b/packages/eslint-config/README.md @@ -3,70 +3,76 @@ ## Install ``` -npm install -D eslint @rambler-tech/eslint-config eslint-config-prettier +npm install -D eslint @rambler-tech/eslint-config ``` or ``` -yarn add -D eslint @rambler-tech/eslint-config eslint-config-prettier +yarn add -D eslint @rambler-tech/eslint-config ``` ## Usage -Create a `.eslinrc.json` and extend this config. Make sure to put [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) last, so it gets the chance to override other configs +Included base configs: + +- `@rambler-tech/eslint-config` - base JavaScript +- `@rambler-tech/eslint-config/semi` - base with semicolons and trailing commas + +Included special configs: + +- `@rambler-tech/eslint-config/ts` - TypeScript +- `@rambler-tech/eslint-config/react` - React +- `@rambler-tech/eslint-config/next` - Next.js + +Example `.eslintrc.json` for React project: ```json { "extends": [ "@rambler-tech/eslint-config", - "@rambler-tech/eslint-config/ts", - "prettier" + "@rambler-tech/eslint-config/react" ] } ``` -or add a key to your **package.json** file. +Example `.eslintrc.json` for TypeScript project: ```json -"eslintConfig": { +{ "extends": [ "@rambler-tech/eslint-config", - "@rambler-tech/eslint-config/ts", - "prettier" + "@rambler-tech/eslint-config/ts" ] } ``` -## Included configurations - -Use proper configs at the same time depending on your stack. - -Included base configs: - -- `@rambler-tech/eslint-config` - base JavaScript -- `@rambler-tech/eslint-config/semi` - base with semicolons and trailing commas - -Included special configs: +Example `.eslintrc.json` for TypeScript React project: -- `@rambler-tech/eslint-config/ts` - TypeScript -- `@rambler-tech/eslint-config/react` - React -- `@rambler-tech/eslint-config/next` - Next.js +```json +{ + "extends": [ + "@rambler-tech/eslint-config", + "@rambler-tech/eslint-config/react", + "@rambler-tech/eslint-config/ts" + ] +} +``` -Note that the `@rambler-tech/eslint-config/ts` should be second to last in the list (before the 'prettier') since it includes `@typescript-eslint/parser`: +Example `.eslintrc.json` for TypeScript Next.js project: ```json -"eslintConfig": { +{ "extends": [ "@rambler-tech/eslint-config", - "@rambler-tech/eslint-config/react", "@rambler-tech/eslint-config/next", - "@rambler-tech/eslint-config/ts", - "prettier" + "@rambler-tech/eslint-config/ts" ] } ``` +Note that the `@rambler-tech/eslint-config/ts` should be second to last in the list since it includes `@typescript-eslint/parser`: + ## Module resolution Included [`eslint-plugin-import`](https://github.com/import-js/eslint-plugin-import) requires additional settings if you use custom module resolution. For example if you use aliases instead of long relative paths: @@ -83,8 +89,7 @@ To use resolution options from `tsconfig.json` add the following settings to you { "extends": [ "@rambler-tech/eslint-config", - "@rambler-tech/eslint-config/ts", - "prettier" + "@rambler-tech/eslint-config/ts" ], "settings": { "import/resolver": { diff --git a/packages/eslint-config/js.js b/packages/eslint-config/js.js index 1847952..d0aa341 100644 --- a/packages/eslint-config/js.js +++ b/packages/eslint-config/js.js @@ -22,7 +22,8 @@ module.exports = { 'plugin:import/recommended', 'plugin:sonar/recommended', 'plugin:sonarjs/recommended', - 'plugin:security/recommended-legacy' + 'plugin:security/recommended-legacy', + 'prettier' ], plugins: ['promise', 'unicorn', 'todo-with-label'], rules: { diff --git a/packages/eslint-config/next.js b/packages/eslint-config/next.js index 03e17b0..ae3d58e 100644 --- a/packages/eslint-config/next.js +++ b/packages/eslint-config/next.js @@ -7,7 +7,7 @@ require('@rushstack/eslint-patch/modern-module-resolution') module.exports = { - extends: ['next'], + extends: ['./react.js', 'next', 'prettier'], rules: { '@next/next/no-img-element': 0 } diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index d80a2de..8d62839 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -14,6 +14,7 @@ "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", "eslint-config-next": "^14.1.0", + "eslint-config-prettier": "^9.1.0", "eslint-import-resolver-typescript": "^3.6.1", "eslint-import-resolver-webpack": "^0.13.8", "eslint-plugin-import": "^2.29.1", diff --git a/packages/eslint-config/react.js b/packages/eslint-config/react.js index 1eba030..911cb8a 100644 --- a/packages/eslint-config/react.js +++ b/packages/eslint-config/react.js @@ -18,7 +18,8 @@ module.exports = { 'plugin:jsx-a11y/recommended', 'plugin:ssr-friendly/recommended', 'plugin:react-prefer-function-component/recommended', - 'plugin:storybook/recommended' + 'plugin:storybook/recommended', + 'prettier' ], rules: { 'react/prop-types': 'off', diff --git a/packages/eslint-config/semi.js b/packages/eslint-config/semi.js index a77cb0e..11040ff 100644 --- a/packages/eslint-config/semi.js +++ b/packages/eslint-config/semi.js @@ -1,5 +1,5 @@ module.exports = { - extends: '@rambler-tech/eslint-config', + extends: ['./js.js'], rules: { semi: ['error', 'always'], 'comma-dangle': ['error', 'only-multiline'] diff --git a/packages/eslint-config/ts.js b/packages/eslint-config/ts.js index e0987f1..e02c61f 100644 --- a/packages/eslint-config/ts.js +++ b/packages/eslint-config/ts.js @@ -16,7 +16,8 @@ module.exports = { files: ['*.ts', '*.mts', '*.cts', '*.tsx'], extends: [ 'plugin:@typescript-eslint/recommended', - 'plugin:import/typescript' + 'plugin:import/typescript', + 'prettier' ], rules: { 'no-unused-vars': 'off', diff --git a/yarn.lock b/yarn.lock index c4a7d7b..df42a5f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2611,10 +2611,10 @@ eslint-config-next@^14.1.0: eslint-plugin-react "^7.33.2" eslint-plugin-react-hooks "^4.5.0 || 5.0.0-canary-7118f5dd7-20230705" -eslint-config-prettier@^9.0.0: - version "9.0.0" - resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-9.0.0.tgz#eb25485946dd0c66cd216a46232dc05451518d1f" - integrity sha512-IcJsTkJae2S35pRsRAwoCE+925rJJStOdkKnLVgtE+tEpqU0EVVM7OqrwxqgptKdX29NUwC82I5pXsGFIgSevw== +eslint-config-prettier@^9.1.0: + version "9.1.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz#31af3d94578645966c082fcb71a5846d3c94867f" + integrity sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw== eslint-import-resolver-node@^0.3.6, eslint-import-resolver-node@^0.3.7, eslint-import-resolver-node@^0.3.9: version "0.3.9"