Skip to content

Commit

Permalink
[readme] Clarify how to install the plugin
Browse files Browse the repository at this point in the history
The markup was misleading, as it put several alternatives into one block of code while not making it clear where the alternatives begin and end, forcing the reader to think hard about it.

Also converted most yaml examples to jsonc.

Co-authored-by: jwbth <33615628+jwbth@users.noreply.github.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
  • Loading branch information
jwbth and ljharb committed Mar 28, 2024
1 parent 32a2b89 commit 038c26c
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 64 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
- [Refactor] `exportMapBuilder`: avoid hoisting ([#2989], thanks [@soryy708])
- [Refactor] `ExportMap`: extract "builder" logic to separate files ([#2991], thanks [@soryy708])
- [Docs] [`order`]: update the description of the `pathGroupsExcludedImportTypes` option ([#3036], thanks [@liby])
- [readme] Clarify how to install the plugin ([#2993], thanks [@jwbth])

## [2.29.1] - 2023-12-14

Expand Down Expand Up @@ -1133,6 +1134,7 @@ for info on changes for earlier releases.
[#3011]: https://github.com/import-js/eslint-plugin-import/pull/3011
[#3004]: https://github.com/import-js/eslint-plugin-import/pull/3004
[#2998]: https://github.com/import-js/eslint-plugin-import/pull/2998
[#2993]: https://github.com/import-js/eslint-plugin-import/pull/2993
[#2991]: https://github.com/import-js/eslint-plugin-import/pull/2991
[#2989]: https://github.com/import-js/eslint-plugin-import/pull/2989
[#2987]: https://github.com/import-js/eslint-plugin-import/pull/2987
Expand Down Expand Up @@ -1835,6 +1837,7 @@ for info on changes for earlier releases.
[@jseminck]: https://github.com/jseminck
[@julien1619]: https://github.com/julien1619
[@justinanastos]: https://github.com/justinanastos
[@jwbth]: https://github.com/jwbth
[@k15a]: https://github.com/k15a
[@kentcdodds]: https://github.com/kentcdodds
[@kevin940726]: https://github.com/kevin940726
Expand Down
176 changes: 112 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,35 +108,37 @@ npm install eslint-plugin-import --save-dev

### Config - Legacy (`.eslintrc`)

All rules are off by default. However, you may configure them manually
in your `.eslintrc.(yml|json|js)`, or extend one of the canned configs:
All rules are off by default. However, you may extend one of the preset configs, or configure them manually in your `.eslintrc.(yml|json|js)`.

```yaml
---
extends:
- eslint:recommended
- plugin:import/recommended
# alternatively, 'recommended' is the combination of these two rule sets:
- plugin:import/errors
- plugin:import/warnings

# or configure manually:
plugins:
- import

rules:
import/no-unresolved: [2, { commonjs: true, amd: true }]
import/named: 2
import/namespace: 2
import/default: 2
import/export: 2
# etc...
- Extending a preset config:

```jsonc
{
"extends": [
"eslint:recommended",
"plugin:import/recommended",
],
}
```

- Configuring manually:

```jsonc
{
"rules": {
"import/no-unresolved": ["error", { "commonjs": true, "amd": true }]
"import/named": "error",
"import/namespace": "error",
"import/default": "error",
"import/export": "error",
// etc...
},
},
```

### Config - Flat (`eslint.config.js`)

All rules are off by default. However, you may configure them manually
in your `eslint.config.(js|cjs|mjs)`, or extend one of the canned configs:
All rules are off by default. However, you may configure them manually in your `eslint.config.(js|cjs|mjs)`, or extend one of the preset configs:

```js
import importPlugin from 'eslint-plugin-import';
Expand Down Expand Up @@ -166,18 +168,23 @@ You may use the following snippet or assemble your own config using the granular

Make sure you have installed [`@typescript-eslint/parser`] and [`eslint-import-resolver-typescript`] which are used in the following configuration.

```yaml
extends:
- eslint:recommended
- plugin:import/recommended
# the following lines do the trick
- plugin:import/typescript
settings:
import/resolver:
# You will also need to install and configure the TypeScript resolver
# See also https://github.com/import-js/eslint-import-resolver-typescript#configuration
typescript: true
node: true
```jsonc
{
"extends": [
"eslint:recommended",
"plugin:import/recommended",
// the following lines do the trick
"plugin:import/typescript",
],
"settings": {
"import/resolver": {
// You will also need to install and configure the TypeScript resolver
// See also https://github.com/import-js/eslint-import-resolver-typescript#configuration
"typescript": true,
"node": true,
},
},
}
```

[`@typescript-eslint/parser`]: https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser
Expand Down Expand Up @@ -206,6 +213,16 @@ You can reference resolvers in several ways (in order of precedence):

- as a conventional `eslint-import-resolver` name, like `eslint-import-resolver-foo`:

```jsonc
// .eslintrc
{
"settings": {
// uses 'eslint-import-resolver-foo':
"import/resolver": "foo",
},
}
```

```yaml
# .eslintrc.yml
settings:
Expand All @@ -226,6 +243,15 @@ module.exports = {

- with a full npm module name, like `my-awesome-npm-module`:

```jsonc
// .eslintrc
{
"settings": {
"import/resolver": "my-awesome-npm-module",
},
}
```

```yaml
# .eslintrc.yml
settings:
Expand Down Expand Up @@ -321,11 +347,15 @@ In practice, this means rules other than [`no-unresolved`](./docs/rules/no-unres

`no-unresolved` has its own [`ignore`](./docs/rules/no-unresolved.md#ignore) setting.

```yaml
settings:
import/ignore:
- \.coffee$ # fraught with parse errors
- \.(scss|less|css)$ # can't parse unprocessed CSS modules, either
```jsonc
{
"settings": {
"import/ignore": [
"\.coffee$", // fraught with parse errors
"\.(scss|less|css)$", // can't parse unprocessed CSS modules, either
],
},
}
```

### `import/core-modules`
Expand All @@ -344,10 +374,13 @@ import 'electron' // without extra config, will be flagged as unresolved!
that would otherwise be unresolved. To avoid this, you may provide `electron` as a
core module:

```yaml
# .eslintrc.yml
settings:
import/core-modules: [ electron ]
```jsonc
// .eslintrc
{
"settings": {
"import/core-modules": ["electron"],
},
}
```

In Electron's specific case, there is a shared config named `electron`
Expand Down Expand Up @@ -380,11 +413,15 @@ dependency parser will require and use the map key as the parser instead of the
configured ESLint parser. This is useful if you're inter-op-ing with TypeScript
directly using webpack, for example:

```yaml
# .eslintrc.yml
settings:
import/parsers:
"@typescript-eslint/parser": [ .ts, .tsx ]
```jsonc
// .eslintrc
{
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"],
},
},
}
```

In this case, [`@typescript-eslint/parser`](https://www.npmjs.com/package/@typescript-eslint/parser)
Expand Down Expand Up @@ -414,20 +451,28 @@ For long-lasting processes, like [`eslint_d`] or [`eslint-loader`], however, it'

If you never use [`eslint_d`] or [`eslint-loader`], you may set the cache lifetime to `Infinity` and everything should be fine:

```yaml
# .eslintrc.yml
settings:
import/cache:
lifetime: ∞ # or Infinity
```jsonc
// .eslintrc
{
"settings": {
"import/cache": {
"lifetime": "", // or Infinity, in a JS config
},
},
}
```

Otherwise, set some integer, and cache entries will be evicted after that many seconds have elapsed:

```yaml
# .eslintrc.yml
settings:
import/cache:
lifetime: 5 # 30 is the default
```jsonc
// .eslintrc
{
"settings": {
"import/cache": {
"lifetime": 5, // 30 is the default
},
},
}
```

[`eslint_d`]: https://www.npmjs.com/package/eslint_d
Expand All @@ -441,10 +486,13 @@ By default, any package referenced from [`import/external-module-folders`](#impo

For example, if your packages in a monorepo are all in `@scope`, you can configure `import/internal-regex` like this

```yaml
# .eslintrc.yml
settings:
import/internal-regex: ^@scope/
```jsonc
// .eslintrc
{
"settings": {
"import/internal-regex": "^@scope/",
},
}
```

## SublimeLinter-eslint
Expand Down

0 comments on commit 038c26c

Please sign in to comment.