Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mysticatea/eslint-plugin-node
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v8.0.1
Choose a base ref
...
head repository: mysticatea/eslint-plugin-node
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v9.0.0
Choose a head ref

Commits on Feb 10, 2019

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    0e63e86 View commit details

Commits on Apr 8, 2019

  1. Docs: fix typo (#154)

    ronkorving authored and mysticatea committed Apr 8, 2019
    Copy the full SHA
    84b2646 View commit details

Commits on May 1, 2019

  1. Copy the full SHA
    0eb4927 View commit details
  2. Copy the full SHA
    b0164df View commit details
  3. 🐛 fix a lint error

    mysticatea committed May 1, 2019
    Copy the full SHA
    62212ac View commit details
  4. Copy the full SHA
    c95b2fd View commit details
  5. ⚒ tweak .eslintignore

    mysticatea committed May 1, 2019
    Copy the full SHA
    aec82c7 View commit details
  6. Copy the full SHA
    fe2343f View commit details

Commits on May 2, 2019

  1. Copy the full SHA
    c9b69ed View commit details
  2. Copy the full SHA
    7e0c2c5 View commit details
  3. Copy the full SHA
    5d79f2d View commit details
  4. Copy the full SHA
    02d61cf View commit details
  5. Copy the full SHA
    9006518 View commit details
  6. Copy the full SHA
    2061413 View commit details
  7. ⚒ fix test failing

    mysticatea committed May 2, 2019
    Copy the full SHA
    0972d6e View commit details
  8. ⚒ fix travis.yml

    mysticatea committed May 2, 2019
    Copy the full SHA
    d4f104c View commit details
  9. ⚒ fix coverage setting

    mysticatea committed May 2, 2019
    Copy the full SHA
    3e4542f View commit details
  10. ⚒ tweak eslint setting

    mysticatea committed May 2, 2019
    Copy the full SHA
    a3a6e41 View commit details
  11. Copy the full SHA
    a3e0e29 View commit details
  12. ⚒ tweak glob

    mysticatea committed May 2, 2019
    Copy the full SHA
    9143043 View commit details

Commits on May 3, 2019

  1. Copy the full SHA
    e41a1e0 View commit details
  2. Copy the full SHA
    ab40a47 View commit details
  3. 📝 update documents

    mysticatea committed May 3, 2019
    Copy the full SHA
    a4fbb9a View commit details
  4. Copy the full SHA
    9243079 View commit details
  5. 📝 update decuments

    mysticatea committed May 3, 2019
    Copy the full SHA
    528282a View commit details
  6. Copy the full SHA
    b94731a View commit details
  7. 9.0.0

    mysticatea committed May 3, 2019
    Copy the full SHA
    a84a009 View commit details
Showing with 2,577 additions and 840 deletions.
  1. +5 −2 .eslintignore
  2. +27 −0 .eslintrc.js
  3. +14 −0 .nycrc
  4. +15 −21 .travis.yml
  5. +36 −22 README.md
  6. +12 −6 docs/rules/exports-style.md
  7. +118 −0 docs/rules/file-extension-in-import.md
  8. +21 −7 docs/rules/no-deprecated-api.md
  9. +39 −12 docs/rules/no-extraneous-import.md
  10. +38 −11 docs/rules/no-extraneous-require.md
  11. +14 −6 docs/rules/no-hide-core-modules.md
  12. +15 −7 docs/rules/no-missing-import.md
  13. +15 −7 docs/rules/no-missing-require.md
  14. +13 −5 docs/rules/no-unpublished-bin.md
  15. +15 −7 docs/rules/no-unpublished-import.md
  16. +15 −7 docs/rules/no-unpublished-require.md
  17. +15 −7 docs/rules/no-unsupported-features.md
  18. +18 −6 docs/rules/no-unsupported-features/es-builtins.md
  19. +14 −6 docs/rules/no-unsupported-features/es-syntax.md
  20. +45 −11 docs/rules/no-unsupported-features/node-builtins.md
  21. +8 −2 docs/rules/prefer-global/buffer.md
  22. +8 −2 docs/rules/prefer-global/console.md
  23. +8 −2 docs/rules/prefer-global/process.md
  24. +8 −2 docs/rules/prefer-global/text-decoder.md
  25. +8 −2 docs/rules/prefer-global/text-encoder.md
  26. +8 −2 docs/rules/prefer-global/url-search-params.md
  27. +8 −2 docs/rules/prefer-global/url.md
  28. +60 −0 docs/rules/prefer-promises/dns.md
  29. +60 −0 docs/rules/prefer-promises/fs.md
  30. +11 −3 docs/rules/process-exit-as-throw.md
  31. +15 −6 docs/rules/shebang.md
  32. +72 −0 lib/configs/_commons.js
  33. +30 −0 lib/configs/recommended-module.js
  34. +27 −0 lib/configs/recommended-script.js
  35. +18 −0 lib/configs/recommended.js
  36. +0 −40 lib/configs/recommended.json
  37. +8 −1 lib/index.js
  38. +1 −1 lib/rules/exports-style.js
  39. +126 −0 lib/rules/file-extension-in-import.js
  40. +18 −1 lib/rules/no-deprecated-api.js
  41. +5 −3 lib/rules/no-extraneous-import.js
  42. +4 −2 lib/rules/no-extraneous-require.js
  43. +4 −2 lib/rules/no-hide-core-modules.js
  44. +4 −3 lib/rules/no-missing-import.js
  45. +3 −2 lib/rules/no-missing-require.js
  46. +2 −2 lib/rules/no-unpublished-bin.js
  47. +4 −3 lib/rules/no-unpublished-import.js
  48. +3 −2 lib/rules/no-unpublished-require.js
  49. +3 −3 lib/rules/no-unsupported-features.js
  50. +2 −1 lib/rules/no-unsupported-features/es-builtins.js
  51. +1 −1 lib/rules/no-unsupported-features/es-syntax.js
  52. +49 −18 lib/rules/no-unsupported-features/node-builtins.js
  53. +1 −1 lib/rules/prefer-global/buffer.js
  54. +1 −1 lib/rules/prefer-global/console.js
  55. +1 −1 lib/rules/prefer-global/process.js
  56. +1 −1 lib/rules/prefer-global/text-decoder.js
  57. +1 −1 lib/rules/prefer-global/text-encoder.js
  58. +1 −1 lib/rules/prefer-global/url-search-params.js
  59. +1 −1 lib/rules/prefer-global/url.js
  60. +74 −0 lib/rules/prefer-promises/dns.js
  61. +76 −0 lib/rules/prefer-promises/fs.js
  62. +1 −1 lib/rules/process-exit-as-throw.js
  63. +2 −2 lib/rules/shebang.js
  64. +1 −1 lib/util/check-publish.js
  65. +6 −8 lib/util/check-unsupported-builtins.js
  66. +2 −2 lib/util/get-configured-node-version.js
  67. +6 −4 lib/util/get-import-export-targets.js
  68. +2 −2 lib/util/get-package-json.js
  69. +11 −38 lib/util/get-require-targets.js
  70. +2 −2 lib/util/get-resolve-paths.js
  71. +2 −2 lib/util/get-try-extensions.js
  72. +19 −18 package.json
  73. +79 −0 scripts/update-docs-header-and-footer.js
  74. +0 −34 scripts/update-lib-configs-recommended.js
  75. +5 −1 scripts/update-lib-index.js
  76. +1 −1 scripts/update.js
  77. +2 −0 tests/fixtures/configs/cjs/package.json
  78. +3 −0 tests/fixtures/configs/esm/package.json
  79. 0 tests/fixtures/file-extension-in-import/a.js
  80. 0 tests/fixtures/file-extension-in-import/b.json
  81. 0 tests/fixtures/file-extension-in-import/c.mjs
  82. 0 tests/fixtures/file-extension-in-import/multi.cjs
  83. 0 tests/fixtures/file-extension-in-import/multi.mjs
  84. +163 −0 tests/lib/configs/recommended.js
  85. +15 −15 tests/lib/rules/exports-style.js
  86. +230 −0 tests/lib/rules/file-extension-in-import.js
  87. +96 −96 tests/lib/rules/no-deprecated-api.js
  88. +13 −13 tests/lib/rules/no-extraneous-import.js
  89. +16 −16 tests/lib/rules/no-extraneous-require.js
  90. +35 −35 tests/lib/rules/no-missing-import.js
  91. +63 −49 tests/lib/rules/no-missing-require.js
  92. +37 −37 tests/lib/rules/no-unpublished-bin.js
  93. +37 −37 tests/lib/rules/no-unpublished-import.js
  94. +61 −61 tests/lib/rules/no-unpublished-require.js
  95. +6 −6 tests/lib/rules/no-unsupported-features/es-syntax.js
  96. +41 −47 tests/lib/rules/no-unsupported-features/node-builtins.js
  97. +159 −0 tests/lib/rules/prefer-promises/dns.js
  98. +167 −0 tests/lib/rules/prefer-promises/fs.js
  99. +47 −47 tests/lib/rules/shebang.js
7 changes: 5 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/node_modules
!.*

!.eslintrc.*
/.nyc_output
/coverage
/docs
/node_modules
27 changes: 27 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -8,6 +8,22 @@ const version = require("./package.json").version

module.exports = {
extends: ["plugin:@mysticatea/es2015", "plugin:@mysticatea/+eslint-plugin"],
rules: {
"@mysticatea/eslint-plugin/test-case-property-ordering": [
"error",
[
"filename",
"code",
"output",
"options",
"parser",
"parserOptions",
"globals",
"env",
"errors",
],
],
},
overrides: [
{
files: ["**/rules/*.js"],
@@ -42,5 +58,16 @@ module.exports = {
],
},
},
{
files: ["**/rules/prefer-promises/*.js"],
rules: {
"@mysticatea/eslint-plugin/require-meta-docs-url": [
"error",
{
pattern: `https://github.com/mysticatea/eslint-plugin-node/blob/v${version}/docs/rules/prefer-promises/{{name}}.md`,
},
],
},
},
],
}
14 changes: 14 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"include": [
"lib/**/*.js"
],
"exclude": [
"lib/rules/no-hide-core-modules.js",
"lib/rules/no-unsupported-features.js"
],
"reporter": [
"lcov",
"text"
],
"sourceMap": true
}
36 changes: 15 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
sudo: false

os:
- linux
- osx
- windows

language: node_js
node_js:
- "6.0.0"
- "6"
- "8"
- "8.10.0"
- "10"
- "11"
- "12"

env:
- ESLINT_VERSION=4
- ESLINT_VERSION=5
# env:
# - ESLINT_VERSION=5
# - ESLINT_VERSION=6

matrix:
exclude:
# ESLint 5 supports Node.js 6.14.0 and up.
- node_js: "6.0.0"
env: ESLINT_VERSION=5
# Reduce build jobs.
- os: osx
env: ESLINT_VERSION=4
- os: windows
env: ESLINT_VERSION=4
# matrix:
# exclude:
# # Reduce build jobs.
# - os: osx
# env: ESLINT_VERSION=6
# - os: windows
# env: ESLINT_VERSION=6

before_script:
- npm i --no-save async
- npm i --no-save eslint@$ESLINT_VERSION; true
# - if [ $ESLINT_VERSION = "5" ]; then npm i --no-save eslint@^5.0.0; else true; fi

script:
- if [ $ESLINT_VERSION = "5" ]; then npm run lint; else true; fi
# - if [ $ESLINT_VERSION = "5" ]; then npm run -s lint; else true; fi
- npm run -s lint
- npm test

after_success:
58 changes: 36 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -14,23 +14,29 @@ Additional ESLint's rules for Node.js
$ npm install --save-dev eslint eslint-plugin-node
```

- Requires Node.js `>=6.0.0`
- Requires ESLint `>=4.19.1` (`plugin:node/recommended` preset requires `>=5.0.0`)
- Requires Node.js `>=8.10.0`
- Requires ESLint `>=5.16.0`

**Note:** It recommends a use of [the "engines" field of package.json](https://docs.npmjs.com/files/package.json#engines). The "engines" field is used by `node/no-unsupported-features/*` rules.

**.eslintrc.json** (An example)

```json
{
"extends": ["eslint:recommended", "plugin:node/recommended"],
"extends": [
"eslint:recommended",
"plugin:node/recommended"
],
"rules": {
"node/exports-style": ["error", "module.exports"],
"node/file-extension-in-import": ["error", "always"],
"node/prefer-global/buffer": ["error", "always"],
"node/prefer-global/console": ["error", "always"],
"node/prefer-global/process": ["error", "always"],
"node/prefer-global/url-search-params": ["error", "always"],
"node/prefer-global/url": ["error", "always"]
"node/prefer-global/url": ["error", "always"],
"node/prefer-promises/dns": "error",
"node/prefer-promises/fs": "error"
}
}
```
@@ -41,8 +47,9 @@ $ npm install --save-dev eslint eslint-plugin-node
{
"name": "your-module",
"version": "1.0.0",
"type": "commonjs",
"engines": {
"node": ">=6.0.0"
"node": ">=8.10.0"
}
}
```
@@ -57,18 +64,18 @@ $ npm install --save-dev eslint eslint-plugin-node

| Rule ID | Description | |
|:--------|:------------|:--:|
| [node/no-extraneous-import](./docs/rules/no-extraneous-import.md) | disallow `import` declarations of extraneous packages | |
| [node/no-extraneous-require](./docs/rules/no-extraneous-require.md) | disallow `require()` expressions of extraneous packages | ⭐️ |
| [node/no-missing-import](./docs/rules/no-missing-import.md) | disallow `import` declarations of missing files | |
| [node/no-missing-require](./docs/rules/no-missing-require.md) | disallow `require()` expressions of missing files | ⭐️ |
| [node/no-unpublished-bin](./docs/rules/no-unpublished-bin.md) | disallow 'bin' files which are ignored by npm | ⭐️ |
| [node/no-unpublished-import](./docs/rules/no-unpublished-import.md) | disallow `import` declarations of private things | |
| [node/no-unpublished-require](./docs/rules/no-unpublished-require.md) | disallow `require()` expressions of private things | ⭐️ |
| [node/no-extraneous-import](./docs/rules/no-extraneous-import.md) | disallow `import` declarations which import extraneous modules | ⭐️ |
| [node/no-extraneous-require](./docs/rules/no-extraneous-require.md) | disallow `require()` expressions which import extraneous modules | ⭐️ |
| [node/no-missing-import](./docs/rules/no-missing-import.md) | disallow `import` declarations which import non-existence modules | ⭐️ |
| [node/no-missing-require](./docs/rules/no-missing-require.md) | disallow `require()` expressions which import non-existence modules | ⭐️ |
| [node/no-unpublished-bin](./docs/rules/no-unpublished-bin.md) | disallow `bin` files that npm ignores | ⭐️ |
| [node/no-unpublished-import](./docs/rules/no-unpublished-import.md) | disallow `import` declarations which import private modules | ⭐️ |
| [node/no-unpublished-require](./docs/rules/no-unpublished-require.md) | disallow `require()` expressions which import private modules | ⭐️ |
| [node/no-unsupported-features/es-builtins](./docs/rules/no-unsupported-features/es-builtins.md) | disallow unsupported ECMAScript built-ins on the specified version | ⭐️ |
| [node/no-unsupported-features/es-syntax](./docs/rules/no-unsupported-features/es-syntax.md) | disallow unsupported ECMAScript syntax on the specified version | ⭐️ |
| [node/no-unsupported-features/node-builtins](./docs/rules/no-unsupported-features/node-builtins.md) | disallow unsupported Node.js built-in APIs on the specified version | ⭐️ |
| [node/process-exit-as-throw](./docs/rules/process-exit-as-throw.md) | make `process.exit()` expressions the same code path as `throw` | ⭐️ |
| [node/shebang](./docs/rules/shebang.md) | enforce the correct usage of shebang | ⭐️✒️ |
| [node/shebang](./docs/rules/shebang.md) | suggest correct usage of shebang | ⭐️✒️ |

### Best Practices

@@ -81,13 +88,16 @@ $ npm install --save-dev eslint eslint-plugin-node
| Rule ID | Description | |
|:--------|:------------|:--:|
| [node/exports-style](./docs/rules/exports-style.md) | enforce either `module.exports` or `exports` | |
| [node/file-extension-in-import](./docs/rules/file-extension-in-import.md) | enforce the style of file extensions in `import` declarations | ✒️ |
| [node/prefer-global/buffer](./docs/rules/prefer-global/buffer.md) | enforce either `Buffer` or `require("buffer").Buffer` | |
| [node/prefer-global/console](./docs/rules/prefer-global/console.md) | enforce either `console` or `require("console")` | |
| [node/prefer-global/process](./docs/rules/prefer-global/process.md) | enforce either `process` or `require("process")` | |
| [node/prefer-global/text-decoder](./docs/rules/prefer-global/text-decoder.md) | enforce either `TextDecoder` or `require("util").TextDecoder` | |
| [node/prefer-global/text-encoder](./docs/rules/prefer-global/text-encoder.md) | enforce either `TextEncoder` or `require("util").TextEncoder` | |
| [node/prefer-global/url-search-params](./docs/rules/prefer-global/url-search-params.md) | enforce either `URLSearchParams` or `require("url").URLSearchParams` | |
| [node/prefer-global/url](./docs/rules/prefer-global/url.md) | enforce either `URL` or `require("url").URL` | |
| [node/prefer-promises/dns](./docs/rules/prefer-promises/dns.md) | enforce `require("dns").promises` | |
| [node/prefer-promises/fs](./docs/rules/prefer-promises/fs.md) | enforce `require("fs").promises` | |

### Deprecated rules

@@ -96,21 +106,25 @@ These rules have been deprecated in accordance with the [deprecation policy](htt
| Rule ID | Replaced by |
|:--------|:------------|
| [node/no-hide-core-modules](./docs/rules/no-hide-core-modules.md) | (nothing) |
| [node/no-unsupported-features](./docs/rules/no-unsupported-features.md) | [node/no-unsupported-features/es-syntax](./docs/rules/no-unsupported-features/es-syntax.md) and [node/no-unsupported-features/es-builtins](./docs/rules/no-unsupported-features/es-builtins.md) |
| [node/no-unsupported-features](./docs/rules/no-unsupported-features.md) | [node/node/no-unsupported-features/es-syntax](./docs/rules/node/no-unsupported-features/es-syntax.md) and [node/node/no-unsupported-features/es-builtins](./docs/rules/node/no-unsupported-features/es-builtins.md) |

<!--RULES_TABLE_END-->

## 🔧 Configs

This plugin provides `plugin:node/recommended` preset config.
This preset config:
This plugin provides three configs:

- enables the environment of ES2015 (ES6) and Node.js.
- enables rules which are given :star: in the above table.
- enables [no-process-exit](http://eslint.org/docs/rules/no-process-exit) rule because [the official document](https://nodejs.org/api/process.html#process_process_exit_code) does not recommend a use of `process.exit()`.
- adds `{ecmaVersion: 2019}` into `parserOptions`.
- adds `Atomics` and `SharedArrayBuffer` into `globals`.
- adds this plugin into `plugins`.
- `plugin:node/recommended` condiders both CommonJS and ES Modules. If [`"type":"module"` field](https://medium.com/@nodejs/announcing-a-new-experimental-modules-1be8d2d6c2ff#b023) existed in package.json then it considers files as ES Modules. Otherwise it considers files as CommonJS. In addition, it considers `*.mjs` files as ES Modules and `*.cjs` files as CommonJS.
- `plugin:node/recommended-module` considers all files as ES Modules.
- `plugin:node/recommended-script` considers all files as CommonJS.

Those preset config:

- enable [no-process-exit](http://eslint.org/docs/rules/no-process-exit) rule because [the official document](https://nodejs.org/api/process.html#process_process_exit_code) does not recommend a use of `process.exit()`.
- enable plugin rules which are given :star: in the above table.
- add `{ecmaVersion: 2019}` and etc into `parserOptions`.
- add proper globals into `globals`.
- add this plugin into `plugins`.

## 👫 FAQ

18 changes: 12 additions & 6 deletions docs/rules/exports-style.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# enforce either `module.exports` or `exports` (exports-style)
# node/exports-style
> enforce either `module.exports` or `exports`
`module.exports` and `exports` are the same instance by default.
But those come to be different if one of them is modified.
@@ -13,7 +14,7 @@ exports.bar = 2

In this case, `exports.bar` will be lost since only the instance of `module.exports` will be exported.

## Rule Details
## 📖 Rule Details

This rule enforces the export style.

@@ -22,7 +23,7 @@ If you use `exports`, this rule disallows `module.exports`.

You can select it by an option.

## Options
### Options

This rule has a string option.

@@ -42,7 +43,7 @@ This rule has a string option.
- `"exports"` requires `exports` and disallows `module.exports`.
- `allowBatchAssign` (default is `false`) allows `module.exports = exports = obj` if this is `true`.

### module.exports
#### module.exports

Examples of :-1: **incorrect** code for the `"module.exports"` option:

@@ -66,7 +67,7 @@ module.exports = {
module.exports.baz = 3
```

### exports
#### exports

Examples of :-1: **incorrect** code for the `"exports"` option:

@@ -90,7 +91,7 @@ exports.foo = 1
exports.bar = 2
```

### allowBatchAssign
#### allowBatchAssign

Examples of :+1: **correct** code for the `"exports"` and `{"allowBatchAssign": true}` option:

@@ -104,3 +105,8 @@ module.exports = exports = function foo() {

exports.bar = 1
```

## 🔎 Implementation

- [Rule source](../../lib/rules/exports-style.js)
- [Test source](../../tests/lib/rules/exports-style.js)
Loading