• Stars
    star
    958
  • Rank 47,718 (Top 1.0 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Additional ESLint's rules for Node.js

eslint-plugin-node

npm version Downloads/month Build Status Coverage Status Dependency Status

Additional ESLint's rules for Node.js

๐Ÿ’ฟ Install & Usage

$ npm install --save-dev eslint eslint-plugin-node
  • Requires Node.js >=8.10.0
  • Requires ESLint >=5.16.0

Note: It recommends a use of the "engines" field of package.json. The "engines" field is used by node/no-unsupported-features/* rules.

.eslintrc.json (An example)

{
    "extends": [
        "eslint:recommended",
        "plugin:node/recommended"
    ],
    "parserOptions": {
        // Only ESLint 6.2.0 and later support ES2020.
        "ecmaVersion": 2020
    },
    "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-promises/dns": "error",
        "node/prefer-promises/fs": "error"
    }
}

package.json (An example)

{
    "name": "your-module",
    "version": "1.0.0",
    "type": "commonjs",
    "engines": {
        "node": ">=8.10.0"
    }
}

๐Ÿ“– Rules

  • โญ๏ธ - the mark of recommended rules.
  • โœ’๏ธ - the mark of fixable rules.

Possible Errors

Rule ID Description
node/handle-callback-err require error handling in callbacks
node/no-callback-literal ensure Node.js-style error-first callback pattern is followed
node/no-exports-assign disallow the assignment to exports โญ๏ธ
node/no-extraneous-import disallow import declarations which import extraneous modules โญ๏ธ
node/no-extraneous-require disallow require() expressions which import extraneous modules โญ๏ธ
node/no-missing-import disallow import declarations which import non-existence modules โญ๏ธ
node/no-missing-require disallow require() expressions which import non-existence modules โญ๏ธ
node/no-new-require disallow new operators with calls to require
node/no-path-concat disallow string concatenation with __dirname and __filename
node/no-process-exit disallow the use of process.exit()
node/no-unpublished-bin disallow bin files that npm ignores โญ๏ธ
node/no-unpublished-import disallow import declarations which import private modules โญ๏ธ
node/no-unpublished-require disallow require() expressions which import private modules โญ๏ธ
node/no-unsupported-features/es-builtins disallow unsupported ECMAScript built-ins on the specified version โญ๏ธ
node/no-unsupported-features/es-syntax disallow unsupported ECMAScript syntax on the specified version โญ๏ธ
node/no-unsupported-features/node-builtins disallow unsupported Node.js built-in APIs on the specified version โญ๏ธ
node/process-exit-as-throw make process.exit() expressions the same code path as throw โญ๏ธ
node/shebang suggest correct usage of shebang โญ๏ธโœ’๏ธ

Best Practices

Rule ID Description
node/no-deprecated-api disallow deprecated APIs โญ๏ธ

Stylistic Issues

Rule ID Description
node/callback-return require return statements after callbacks
node/exports-style enforce either module.exports or exports
node/file-extension-in-import enforce the style of file extensions in import declarations โœ’๏ธ
node/global-require require require() calls to be placed at top-level module scope
node/no-mixed-requires disallow require calls to be mixed with regular variable declarations
node/no-process-env disallow the use of process.env
node/no-restricted-import disallow specified modules when loaded by import declarations
node/no-restricted-require disallow specified modules when loaded by require
node/no-sync disallow synchronous methods
node/prefer-global/buffer enforce either Buffer or require("buffer").Buffer
node/prefer-global/console enforce either console or require("console")
node/prefer-global/process enforce either process or require("process")
node/prefer-global/text-decoder enforce either TextDecoder or require("util").TextDecoder
node/prefer-global/text-encoder enforce either TextEncoder or require("util").TextEncoder
node/prefer-global/url-search-params enforce either URLSearchParams or require("url").URLSearchParams
node/prefer-global/url enforce either URL or require("url").URL
node/prefer-promises/dns enforce require("dns").promises
node/prefer-promises/fs enforce require("fs").promises

Deprecated rules

These rules have been deprecated in accordance with the deprecation policy, and replaced by newer rules:

Rule ID Replaced by
node/no-hide-core-modules (nothing)
node/no-unsupported-features node/no-unsupported-features/es-syntax and node/no-unsupported-features/es-builtins

๐Ÿ”ง Configs

This plugin provides three configs:

  • plugin:node/recommended considers both CommonJS and ES Modules. If "type":"module" field 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 rule because the official document does not recommend a use of process.exit().
  • enable plugin rules which are given โญ in the above table.
  • add {ecmaVersion: 2019} and etc into parserOptions.
  • add proper globals into globals.
  • add this plugin into plugins.

๐Ÿ‘ซ FAQ

๐Ÿšฅ Semantic Versioning Policy

eslint-plugin-node follows semantic versioning and ESLint's Semantic Versioning Policy.

  • Patch release (intended to not break your lint build)
    • A bug fix in a rule that results in it reporting fewer errors.
    • Improvements to documentation.
    • Non-user-facing changes such as refactoring code, adding, deleting, or modifying tests, and increasing test coverage.
    • Re-releasing after a failed release (i.e., publishing a release that doesn't work for anyone).
  • Minor release (might break your lint build)
    • A bug fix in a rule that results in it reporting more errors.
    • A new rule is created.
    • A new option to an existing rule is created.
    • An existing rule is deprecated.
  • Major release (likely to break your lint build)
    • A support for old Node version is dropped.
    • A support for old ESLint version is dropped.
    • An existing rule is changed in it reporting more errors.
    • An existing rule is removed.
    • An existing option of a rule is removed.
    • An existing config is updated.

๐Ÿ“ฐ Changelog

โค๏ธ Contributing

Welcome contributing!

Please use GitHub's Issues/PRs.

Development Tools

  • npm test runs tests and measures coverage.
  • npm run coverage shows the coverage result of npm test command.
  • npm run clean removes the coverage result of npm test command.

More Repositories

1

npm-run-all

A CLI tool to run multiple npm-scripts in parallel or sequential.
JavaScript
5,679
star
2

cpx

A cli tool to watch and copy file globs.
JavaScript
524
star
3

eslint-plugin-eslint-comments

Additional ESLint rules for directive comments of ESLint.
JavaScript
359
star
4

abort-controller

An implementation of WHATWG AbortController interface.
TypeScript
301
star
5

regexpp

The regular expression parser for ECMAScript.
TypeScript
150
star
6

event-target-shim

An implementation of WHATWG EventTarget interface, plus few extensions.
TypeScript
123
star
7

eslint-plugin-es

ESLint plugin about ECMAScript syntactic features.
JavaScript
106
star
8

eslint-plugin-vue-trial

Experimental ESLint plugin for Vue.js.
JavaScript
90
star
9

eslint-utils

Utilities for ESLint plugins and custom rules.
JavaScript
74
star
10

eslint-gitignore

A utility for ESLint respecting `.gitignore` files.
TypeScript
39
star
11

eslint4b

ESLint which works in browsers.
JavaScript
37
star
12

vue-eslint-editor

A code editor component to play ESLint.
Vue
35
star
13

vue-eslint-demo

The online demo to check `eslint-plugin-vue`.
JavaScript
31
star
14

react-helix

A small library for immutable design and React.
JavaScript
26
star
15

appcache-manifest

A CLI tool to generate HTML5 Application Cache Manifest.
JavaScript
26
star
16

eslint-plugin

ESLint configurations and additional rules for me
JavaScript
25
star
17

eslint-plugin-dprint

An ESLint plugin that fixes code with dprint
TypeScript
24
star
18

template-eslint-plugin

A repository template for ESLint plugins.
JavaScript
17
star
19

if-node-version

Run a shell command if it's on the node of specified versions.
JavaScript
14
star
20

eslint-plugin-ja

ESLint ใฎใ‚จใƒฉใƒผใƒกใƒƒใ‚ปใƒผใ‚ธใ‚’ๆ—ฅๆœฌ่ชžๅŒ–ใ™ใ‚‹้žๅ…ฌๅผใฎๅฎŸ้จ“็š„ใชใƒ—ใƒฉใ‚ฐใ‚คใƒณใงใ™ใ€‚
JavaScript
12
star
21

bre

A Binary-Object Mapper for JavaScript
TypeScript
10
star
22

eaw

The Node.js module to calculate the width of east Asian characters.
JavaScript
10
star
23

eslint-config

Shareable configurations of ESLint for me.
JavaScript
8
star
24

eslint-evaluating-issues

ESLint evaluating feature issues
JavaScript
8
star
25

spy

Just a spy library.
TypeScript
8
star
26

uptodate

A CLI tool to update dependencies in your package.json.
JavaScript
7
star
27

validia

An object validator library that is TypeScript friendly
TypeScript
7
star
28

eslint-ast

The Extensible Type Definition of ESLint AST
TypeScript
6
star
29

Yammer-for-Developers

[Chrome Extension] The code formater and highlighter in Yammer's messages.
JavaScript
5
star
30

typescript-eslint-demo

A playground for @typescript-eslint.
JavaScript
4
star
31

mocha-assert-snapshot

Snapshot test utilities for Mocha.
TypeScript
4
star
32

warun

CLI tool which does Watch and Run.
JavaScript
4
star
33

type-tester

A tester to check expected type errors
TypeScript
4
star
34

eslint-custom-rule-tutorial

JavaScript
3
star
35

event-source-shim

An implementation for `EventSource` of Server-sent events standard.
TypeScript
2
star
36

run-all

CLI tool to execute multiple commands parallelly.
JavaScript
2
star
37

eslint-plugin-utils

Tools to maintain ESLint plugins
2
star
38

react-helix-examples

Examples for react-helix library.
JavaScript
2
star
39

github-actions-sandbox

JavaScript
2
star
40

hetemel

A HTML parser to make AST which fits for linting.
1
star
41

tools

My tools
TypeScript
1
star
42

fs-watcher

Lightweight file system watchers.
TypeScript
1
star
43

webkit-test

HTML
1
star
44

simple-vue-app

A CLI command to build a simple Vue.js SPA with almost no configuration.
JavaScript
1
star
45

.github

1
star
46

ajx

Simple fetch library for me.
JavaScript
1
star
47

string-replace-unexpected-behavior

Is this a bug?
JavaScript
1
star