Skip to content

Commit

Permalink
📝 update no-extraneous-* document (fixes #148)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed May 3, 2019
1 parent e41a1e0 commit ab40a47
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
31 changes: 25 additions & 6 deletions docs/rules/no-extraneous-import.md
Expand Up @@ -13,7 +13,9 @@ This rule warns `import` declarations of extraneous modules.
{
"rules": {
"node/no-extraneous-import": ["error", {
"allowModules": []
"allowModules": [],
"resolvePaths": [],
"tryExtensions": []
}]
}
}
Expand All @@ -37,20 +39,37 @@ This option is an array of strings as module names.
}
```

### resolvePaths

Adds additional paths to try for when resolving imports.
If a path is relative, it will be resolved from CWD.

Default is `[]`

### tryExtensions

When an import path does not exist, this rule checks whether or not any of `path.js`, `path.json`, and `path.node` exists.
`tryExtensions` option is the extension list this rule uses at the time.

Default is `[".js", ".json", ".node"]`.

## Shared Settings

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

- `allowModules`
- `resolvePaths`
- `tryExtensions`

For Example:

```json
{
```js
// .eslintrc.js
module.exports = {
"settings": {
"node": {
"allowModules": ["electron"]
"allowModules": ["electron"],
"resolvePaths": [__dirname],
"tryExtensions": [".js", ".json", ".node"]
}
},
"rules": {
Expand Down
31 changes: 25 additions & 6 deletions docs/rules/no-extraneous-require.md
Expand Up @@ -13,7 +13,9 @@ This rule warns `require()` of extraneous modules.
{
"rules": {
"node/no-extraneous-require": ["error", {
"allowModules": []
"allowModules": [],
"resolvePaths": [],
"tryExtensions": []
}]
}
}
Expand All @@ -37,20 +39,37 @@ This option is an array of strings as module names.
}
```

### resolvePaths

Adds additional paths to try for when resolving imports.
If a path is relative, it will be resolved from CWD.

Default is `[]`

### tryExtensions

When an import path does not exist, this rule checks whether or not any of `path.js`, `path.json`, and `path.node` exists.
`tryExtensions` option is the extension list this rule uses at the time.

Default is `[".js", ".json", ".node"]`.

## Shared Settings

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

- `allowModules`
- `resolvePaths`
- `tryExtensions`

For Example:

```json
{
```js
// .eslintrc.js
module.exports = {
"settings": {
"node": {
"allowModules": ["electron"]
"allowModules": ["electron"],
"resolvePaths": [__dirname],
"tryExtensions": [".js", ".json", ".node"]
}
},
"rules": {
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/no-extraneous-import.js
Expand Up @@ -9,6 +9,7 @@ const getAllowModules = require("../util/get-allow-modules")
const getConvertPath = require("../util/get-convert-path")
const getImportTargets = require("../util/get-import-export-targets")
const getResolvePaths = require("../util/get-resolve-paths")
const getTryExtensions = require("../util/get-try-extensions")

module.exports = {
meta: {
Expand All @@ -29,6 +30,7 @@ module.exports = {
allowModules: getAllowModules.schema,
convertPath: getConvertPath.schema,
resolvePaths: getResolvePaths.schema,
tryExtensions: getTryExtensions.schema,
},
additionalProperties: false,
},
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/no-extraneous-require.js
Expand Up @@ -9,6 +9,7 @@ const getAllowModules = require("../util/get-allow-modules")
const getConvertPath = require("../util/get-convert-path")
const getRequireTargets = require("../util/get-require-targets")
const getResolvePaths = require("../util/get-resolve-paths")
const getTryExtensions = require("../util/get-try-extensions")

module.exports = {
meta: {
Expand All @@ -29,6 +30,7 @@ module.exports = {
allowModules: getAllowModules.schema,
convertPath: getConvertPath.schema,
resolvePaths: getResolvePaths.schema,
tryExtensions: getTryExtensions.schema,
},
additionalProperties: false,
},
Expand Down

0 comments on commit ab40a47

Please sign in to comment.