Skip to content

Commit ab40a47

Browse files
committed
📝 update no-extraneous-* document (fixes #148)
1 parent e41a1e0 commit ab40a47

File tree

4 files changed

+54
-12
lines changed

4 files changed

+54
-12
lines changed

docs/rules/no-extraneous-import.md

+25-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ This rule warns `import` declarations of extraneous modules.
1313
{
1414
"rules": {
1515
"node/no-extraneous-import": ["error", {
16-
"allowModules": []
16+
"allowModules": [],
17+
"resolvePaths": [],
18+
"tryExtensions": []
1719
}]
1820
}
1921
}
@@ -37,20 +39,37 @@ This option is an array of strings as module names.
3739
}
3840
```
3941

42+
### resolvePaths
43+
44+
Adds additional paths to try for when resolving imports.
45+
If a path is relative, it will be resolved from CWD.
46+
47+
Default is `[]`
48+
49+
### tryExtensions
50+
51+
When an import path does not exist, this rule checks whether or not any of `path.js`, `path.json`, and `path.node` exists.
52+
`tryExtensions` option is the extension list this rule uses at the time.
53+
54+
Default is `[".js", ".json", ".node"]`.
55+
4056
## Shared Settings
4157

4258
The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings).
4359
Several rules have the same option, but we can set this option at once.
4460

4561
- `allowModules`
62+
- `resolvePaths`
63+
- `tryExtensions`
4664

47-
For Example:
48-
49-
```json
50-
{
65+
```js
66+
// .eslintrc.js
67+
module.exports = {
5168
"settings": {
5269
"node": {
53-
"allowModules": ["electron"]
70+
"allowModules": ["electron"],
71+
"resolvePaths": [__dirname],
72+
"tryExtensions": [".js", ".json", ".node"]
5473
}
5574
},
5675
"rules": {

docs/rules/no-extraneous-require.md

+25-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ This rule warns `require()` of extraneous modules.
1313
{
1414
"rules": {
1515
"node/no-extraneous-require": ["error", {
16-
"allowModules": []
16+
"allowModules": [],
17+
"resolvePaths": [],
18+
"tryExtensions": []
1719
}]
1820
}
1921
}
@@ -37,20 +39,37 @@ This option is an array of strings as module names.
3739
}
3840
```
3941

42+
### resolvePaths
43+
44+
Adds additional paths to try for when resolving imports.
45+
If a path is relative, it will be resolved from CWD.
46+
47+
Default is `[]`
48+
49+
### tryExtensions
50+
51+
When an import path does not exist, this rule checks whether or not any of `path.js`, `path.json`, and `path.node` exists.
52+
`tryExtensions` option is the extension list this rule uses at the time.
53+
54+
Default is `[".js", ".json", ".node"]`.
55+
4056
## Shared Settings
4157

4258
The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings).
4359
Several rules have the same option, but we can set this option at once.
4460

4561
- `allowModules`
62+
- `resolvePaths`
63+
- `tryExtensions`
4664

47-
For Example:
48-
49-
```json
50-
{
65+
```js
66+
// .eslintrc.js
67+
module.exports = {
5168
"settings": {
5269
"node": {
53-
"allowModules": ["electron"]
70+
"allowModules": ["electron"],
71+
"resolvePaths": [__dirname],
72+
"tryExtensions": [".js", ".json", ".node"]
5473
}
5574
},
5675
"rules": {

lib/rules/no-extraneous-import.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const getAllowModules = require("../util/get-allow-modules")
99
const getConvertPath = require("../util/get-convert-path")
1010
const getImportTargets = require("../util/get-import-export-targets")
1111
const getResolvePaths = require("../util/get-resolve-paths")
12+
const getTryExtensions = require("../util/get-try-extensions")
1213

1314
module.exports = {
1415
meta: {
@@ -29,6 +30,7 @@ module.exports = {
2930
allowModules: getAllowModules.schema,
3031
convertPath: getConvertPath.schema,
3132
resolvePaths: getResolvePaths.schema,
33+
tryExtensions: getTryExtensions.schema,
3234
},
3335
additionalProperties: false,
3436
},

lib/rules/no-extraneous-require.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const getAllowModules = require("../util/get-allow-modules")
99
const getConvertPath = require("../util/get-convert-path")
1010
const getRequireTargets = require("../util/get-require-targets")
1111
const getResolvePaths = require("../util/get-resolve-paths")
12+
const getTryExtensions = require("../util/get-try-extensions")
1213

1314
module.exports = {
1415
meta: {
@@ -29,6 +30,7 @@ module.exports = {
2930
allowModules: getAllowModules.schema,
3031
convertPath: getConvertPath.schema,
3132
resolvePaths: getResolvePaths.schema,
33+
tryExtensions: getTryExtensions.schema,
3234
},
3335
additionalProperties: false,
3436
},

0 commit comments

Comments
 (0)