Skip to content

Commit

Permalink
fix(eslint-config): fix import rules
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepolischuk committed Jan 19, 2024
1 parent 984cd4e commit f036c65
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 9 deletions.
42 changes: 37 additions & 5 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ yarn add -D eslint @rambler-tech/eslint-config eslint-config-prettier

## Usage

Create a **.eslinrc** and extend this config. Make sure to put `eslint-config-prettier` last, so it gets the chance to override other configs
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

```
```json
{
"extends": [
"@rambler-tech/eslint-config",
Expand All @@ -28,7 +28,7 @@ Create a **.eslinrc** and extend this config. Make sure to put `eslint-config-pr

or add a key to your **package.json** file.

```
```json
"eslintConfig": {
"extends": [
"@rambler-tech/eslint-config",
Expand All @@ -40,17 +40,22 @@ or add a key to your **package.json** file.

## Included configurations

Use proper configs at the same time depending on your stack. Included configs:
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:

- `@rambler-tech/eslint-config/ts` - TypeScript
- `@rambler-tech/eslint-config/react` - React
- `@rambler-tech/eslint-config/next` - Next.js

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`:

```
```json
"eslintConfig": {
"extends": [
"@rambler-tech/eslint-config",
Expand All @@ -61,3 +66,30 @@ Note that the `@rambler-tech/eslint-config/ts` should be second to last in the l
]
}
```

## 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:

```ts
import App from 'components/app'
```

This config includes [`eslint-import-resolver-webpack`](https://www.npmjs.com/package/eslint-import-resolver-webpack) and [`eslint-import-resolver-typescript`](https://www.npmjs.com/package/eslint-import-resolver-typescript).

To use resolution options from `tsconfig.json` add the following settings to your `.eslintrc.json`.

```json
{
"extends": [
"@rambler-tech/eslint-config",
"@rambler-tech/eslint-config/ts",
"prettier"
],
"settings": {
"import/resolver": {
"typescript": true
}
}
}
```
7 changes: 5 additions & 2 deletions packages/eslint-config/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ module.exports = {
'import/no-cycle': 'error',
'import/no-useless-path-segments': 'error',
'import/no-default-export': 'error',
'import/no-unused-modules': 'off',
'import/no-unresolved': 'off',
'import/no-unused-modules': [
'error',
{missingExports: false, unusedExports: true}
],
'import/no-unresolved': ['error', {caseSensitiveStrict: true}],
'import/no-anonymous-default-export': [
'error',
{allowCallExpression: false}
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"eslint-config-next": "^14.0.4",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-import-resolver-webpack": "^0.13.8",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.28.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-config/ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': [
'error',
{allowExpressions: true}
]
],
'import/no-unresolved': 'off'
}
},
{
Expand Down
80 changes: 79 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,16 @@ array-union@^2.1.0:
resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d"
integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==

array.prototype.find@^2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/array.prototype.find/-/array.prototype.find-2.2.2.tgz#e862cf891e725d8f2a10e5e42d750629faaabd32"
integrity sha512-DRumkfW97iZGOfn+lIXbkVrXL04sfYKX+EfOodo8XboR5sxPDVvOjZTF/rysusa9lmhmSOeD6Vp6RKQP+eP4Tg==
dependencies:
call-bind "^1.0.2"
define-properties "^1.2.0"
es-abstract "^1.22.1"
es-shim-unscopables "^1.0.0"

array.prototype.findlastindex@^1.2.2, array.prototype.findlastindex@^1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/array.prototype.findlastindex/-/array.prototype.findlastindex-1.2.3.tgz#b37598438f97b579166940814e2c0493a4f50207"
Expand Down Expand Up @@ -2224,6 +2234,15 @@ end-of-stream@^1.4.1:
dependencies:
once "^1.4.0"

enhanced-resolve@^0.9.1:
version "0.9.1"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-0.9.1.tgz#4d6e689b3725f86090927ccc86cd9f1635b89e2e"
integrity sha512-kxpoMgrdtkXZ5h0SeraBS1iRntpTpQ3R8ussdb38+UAFnMGX5DDyJXePm+OCHOcoXvHDw7mc2erbJBpDnl7TPw==
dependencies:
graceful-fs "^4.1.2"
memory-fs "^0.2.0"
tapable "^0.1.8"

enhanced-resolve@^5.12.0:
version "5.15.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz#1af946c7d93603eb88e9896cee4904dc012e9c35"
Expand Down Expand Up @@ -2408,6 +2427,36 @@ eslint-import-resolver-typescript@^3.5.2:
is-core-module "^2.11.0"
is-glob "^4.0.3"

eslint-import-resolver-typescript@^3.6.1:
version "3.6.1"
resolved "https://registry.yarnpkg.com/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-3.6.1.tgz#7b983680edd3f1c5bce1a5829ae0bc2d57fe9efa"
integrity sha512-xgdptdoi5W3niYeuQxKmzVDTATvLYqhpwmykwsh7f6HIOStGWEIL9iqZgQDF9u9OEzrRwR8no5q2VT+bjAujTg==
dependencies:
debug "^4.3.4"
enhanced-resolve "^5.12.0"
eslint-module-utils "^2.7.4"
fast-glob "^3.3.1"
get-tsconfig "^4.5.0"
is-core-module "^2.11.0"
is-glob "^4.0.3"

eslint-import-resolver-webpack@^0.13.8:
version "0.13.8"
resolved "https://registry.yarnpkg.com/eslint-import-resolver-webpack/-/eslint-import-resolver-webpack-0.13.8.tgz#5f64d1d653eefa19cdfd0f0165c996b6be7012f9"
integrity sha512-Y7WIaXWV+Q21Rz/PJgUxiW/FTBOWmU8NTLdz+nz9mMoiz5vAev/fOaQxwD7qRzTfE3HSm1qsxZ5uRd7eX+VEtA==
dependencies:
array.prototype.find "^2.2.2"
debug "^3.2.7"
enhanced-resolve "^0.9.1"
find-root "^1.1.0"
hasown "^2.0.0"
interpret "^1.4.0"
is-core-module "^2.13.1"
is-regex "^1.1.4"
lodash "^4.17.21"
resolve "^2.0.0-next.5"
semver "^5.7.2"

eslint-module-utils@^2.7.4, eslint-module-utils@^2.8.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.8.0.tgz#e439fee65fc33f6bba630ff621efc38ec0375c49"
Expand Down Expand Up @@ -2834,6 +2883,11 @@ fill-range@^7.0.1:
dependencies:
to-regex-range "^5.0.1"

find-root@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/find-root/-/find-root-1.1.0.tgz#abcfc8ba76f708c42a97b3d685b7e9450bfb9ce4"
integrity sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng==

find-up@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-2.1.0.tgz#45d1b7e506c717ddd482775a2b77920a3c0c57a7"
Expand Down Expand Up @@ -3521,6 +3575,11 @@ internal-slot@^1.0.5:
has "^1.0.3"
side-channel "^1.0.4"

interpret@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==

ip@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ip/-/ip-2.0.0.tgz#4cf4ab182fee2314c75ede1276f8c80b479936da"
Expand Down Expand Up @@ -4364,6 +4423,11 @@ map-obj@^4.0.0:
resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-4.3.0.tgz#9304f906e93faae70880da102a9f1df0ea8bb05a"
integrity sha512-hdN1wVrZbb29eBGiGjJbeP8JbKjq1urkHJ/LIP/NY48MZ1QVXUsQBV1G1zvYFHn1XE06cwjBsOI2K3Ulnj1YXQ==

memory-fs@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/memory-fs/-/memory-fs-0.2.0.tgz#f2bb25368bc121e391c2520de92969caee0a0290"
integrity sha512-+y4mDxU4rvXXu5UDSGCGNiesFmwCHuefGMoPCO1WYucNYj7DsLqrFaa2fXVI0H+NNiPTwwzKwspn9yTZqUGqng==

meow@^8.0.0, meow@^8.1.2:
version "8.1.2"
resolved "https://registry.yarnpkg.com/meow/-/meow-8.1.2.tgz#bcbe45bda0ee1729d350c03cffc8395a36c4e897"
Expand Down Expand Up @@ -5557,6 +5621,15 @@ resolve@^2.0.0-next.4:
path-parse "^1.0.7"
supports-preserve-symlinks-flag "^1.0.0"

resolve@^2.0.0-next.5:
version "2.0.0-next.5"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-2.0.0-next.5.tgz#6b0ec3107e671e52b68cd068ef327173b90dc03c"
integrity sha512-U7WjGVG9sH8tvjW5SmGbQuui75FiyjAX72HX15DwBBwF9dNiQZRQAg9nnPhYy+TUnE0+VcrttuvNI8oSxZcocA==
dependencies:
is-core-module "^2.13.0"
path-parse "^1.0.7"
supports-preserve-symlinks-flag "^1.0.0"

restore-cursor@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-3.1.0.tgz#39f67c54b3a7a58cea5236d95cf0034239631f7e"
Expand Down Expand Up @@ -5671,7 +5744,7 @@ scslre@^0.3.0:
refa "^0.12.0"
regexp-ast-analysis "^0.7.0"

"semver@2 || 3 || 4 || 5", semver@^5.6.0:
"semver@2 || 3 || 4 || 5", semver@^5.6.0, semver@^5.7.2:
version "5.7.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8"
integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==
Expand Down Expand Up @@ -6039,6 +6112,11 @@ supports-preserve-symlinks-flag@^1.0.0:
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==

tapable@^0.1.8:
version "0.1.10"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.1.10.tgz#29c35707c2b70e50d07482b5d202e8ed446dafd4"
integrity sha512-jX8Et4hHg57mug1/079yitEKWGB3LCwoxByLsNim89LABq8NqgiX+6iYVOsq0vX8uJHkU+DZ5fnq95f800bEsQ==

tapable@^2.2.0:
version "2.2.1"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0"
Expand Down

0 comments on commit f036c65

Please sign in to comment.