Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
New:
prefer-global/*
rules
- Loading branch information
1 parent
217411d
commit 3d79333
Showing
19 changed files
with
821 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# enforce either `Buffer` or `require("buffer").Buffer` (prefer-global/buffer) | ||
|
||
The `Buffer` class of `buffer` module is defined as a global variable. | ||
|
||
```js | ||
console.log(Buffer === require("buffer").Buffer) //→ true | ||
``` | ||
|
||
It will be readable if we use either `Buffer` consistently. | ||
|
||
## Rule Details | ||
|
||
This rule enforces which `Buffer` we should use. | ||
|
||
### Options | ||
|
||
This rule has a string option. | ||
|
||
```json | ||
{ | ||
"node/prefer-global/buffer": ["error", "always" | "never"] | ||
} | ||
``` | ||
|
||
- `"always"` (default) ... enforces to use the global variable `Buffer` rather than `require("buffer").Buffer`. | ||
- `"never"` ... enforces to use `require("buffer").Buffer` rather than the global variable `Buffer`. | ||
|
||
#### always | ||
|
||
Examples of :-1: **incorrect** code for this rule: | ||
|
||
```js | ||
/*eslint node/prefer-global/buffer: [error]*/ | ||
|
||
const { Buffer } = require("buffer") | ||
const b = Buffer.alloc(16) | ||
``` | ||
|
||
Examples of :+1: **correct** code for this rule: | ||
|
||
```js | ||
/*eslint node/prefer-global/buffer: [error]*/ | ||
|
||
const b = Buffer.alloc(16) | ||
``` | ||
|
||
#### never | ||
|
||
Examples of :-1: **incorrect** code for the `"never"` option: | ||
|
||
```js | ||
/*eslint node/prefer-global/buffer: [error, never]*/ | ||
|
||
const b = Buffer.alloc(16) | ||
``` | ||
|
||
Examples of :+1: **correct** code for the `"never"` option: | ||
|
||
```js | ||
/*eslint node/prefer-global/buffer: [error, never]*/ | ||
|
||
const { Buffer } = require("buffer") | ||
const b = Buffer.alloc(16) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# enforce either `console` or `require("console")` (prefer-global/console) | ||
|
||
The `console` module is defined as a global variable. | ||
|
||
```js | ||
console.log(console === require("console")) //→ true | ||
``` | ||
|
||
It will be readable if we use either `console` consistently. | ||
|
||
## Rule Details | ||
|
||
This rule enforces which `console` we should use. | ||
|
||
### Options | ||
|
||
This rule has a string option. | ||
|
||
```json | ||
{ | ||
"node/prefer-global/console": ["error", "always" | "never"] | ||
} | ||
``` | ||
|
||
- `"always"` (default) ... enforces to use the global variable `console` rather than `require("console")`. | ||
- `"never"` ... enforces to use `require("console")` rather than the global variable `console`. | ||
|
||
#### always | ||
|
||
Examples of :-1: **incorrect** code for this rule: | ||
|
||
```js | ||
/*eslint node/prefer-global/console: [error]*/ | ||
|
||
const console = require("console") | ||
console.log("hello") | ||
``` | ||
|
||
Examples of :+1: **correct** code for this rule: | ||
|
||
```js | ||
/*eslint node/prefer-global/console: [error]*/ | ||
|
||
console.log("hello") | ||
``` | ||
|
||
#### never | ||
|
||
Examples of :-1: **incorrect** code for the `"never"` option: | ||
|
||
```js | ||
/*eslint node/prefer-global/console: [error, never]*/ | ||
|
||
console.log("hello") | ||
``` | ||
|
||
Examples of :+1: **correct** code for the `"never"` option: | ||
|
||
```js | ||
/*eslint node/prefer-global/console: [error, never]*/ | ||
|
||
const console = require("console") | ||
console.log("hello") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# enforce either `process` or `require("process")` (prefer-global/process) | ||
|
||
The `process` module is defined as a global variable. | ||
|
||
```js | ||
process.log(process === require("process")) //→ true | ||
``` | ||
|
||
It will be readable if we use either `process` consistently. | ||
|
||
## Rule Details | ||
|
||
This rule enforces which `process` we should use. | ||
|
||
### Options | ||
|
||
This rule has a string option. | ||
|
||
```json | ||
{ | ||
"node/prefer-global/process": ["error", "always" | "never"] | ||
} | ||
``` | ||
|
||
- `"always"` (default) ... enforces to use the global variable `process` rather than `require("process")`. | ||
- `"never"` ... enforces to use `require("process")` rather than the global variable `process`. | ||
|
||
#### always | ||
|
||
Examples of :-1: **incorrect** code for this rule: | ||
|
||
```js | ||
/*eslint node/prefer-global/process: [error]*/ | ||
|
||
const process = require("process") | ||
process.exit(0) | ||
``` | ||
|
||
Examples of :+1: **correct** code for this rule: | ||
|
||
```js | ||
/*eslint node/prefer-global/process: [error]*/ | ||
|
||
process.exit(0) | ||
``` | ||
|
||
#### never | ||
|
||
Examples of :-1: **incorrect** code for the `"never"` option: | ||
|
||
```js | ||
/*eslint node/prefer-global/process: [error, never]*/ | ||
|
||
process.exit(0) | ||
``` | ||
|
||
Examples of :+1: **correct** code for the `"never"` option: | ||
|
||
```js | ||
/*eslint node/prefer-global/process: [error, never]*/ | ||
|
||
const process = require("process") | ||
process.exit(0) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# enforce either `URLSearchParams` or `require("url").URLSearchParams` (prefer-global/url) | ||
|
||
The `URLSearchParams` class of `url` module is defined as a global variable. | ||
|
||
```js | ||
console.log(URLSearchParams === require("url").URLSearchParams) //→ true | ||
``` | ||
|
||
It will be readable if we use either `URLSearchParams` consistently. | ||
|
||
## Rule Details | ||
|
||
This rule enforces which `URLSearchParams` we should use. | ||
|
||
### Options | ||
|
||
This rule has a string option. | ||
|
||
```json | ||
{ | ||
"node/prefer-global/url": ["error", "always" | "never"] | ||
} | ||
``` | ||
|
||
- `"always"` (default) ... enforces to use the global variable `URLSearchParams` rather than `require("url").URLSearchParams`. | ||
- `"never"` ... enforces to use `require("url").URLSearchParams` rather than the global variable `URLSearchParams`. | ||
|
||
#### always | ||
|
||
Examples of :-1: **incorrect** code for this rule: | ||
|
||
```js | ||
/*eslint node/prefer-global/url: [error]*/ | ||
|
||
const { URLSearchParams } = require("url") | ||
const u = new URLSearchParams(s) | ||
``` | ||
|
||
Examples of :+1: **correct** code for this rule: | ||
|
||
```js | ||
/*eslint node/prefer-global/url: [error]*/ | ||
|
||
const u = new URLSearchParams(s) | ||
``` | ||
|
||
#### never | ||
|
||
Examples of :-1: **incorrect** code for the `"never"` option: | ||
|
||
```js | ||
/*eslint node/prefer-global/url: [error, never]*/ | ||
|
||
const u = new URLSearchParams(s) | ||
``` | ||
|
||
Examples of :+1: **correct** code for the `"never"` option: | ||
|
||
```js | ||
/*eslint node/prefer-global/url: [error, never]*/ | ||
|
||
const { URLSearchParams } = require("url") | ||
const u = new URLSearchParams(s) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# enforce either `URL` or `require("url").URL` (prefer-global/url) | ||
|
||
The `URL` class of `url` module is defined as a global variable. | ||
|
||
```js | ||
console.log(URL === require("url").URL) //→ true | ||
``` | ||
|
||
It will be readable if we use either `URL` consistently. | ||
|
||
## Rule Details | ||
|
||
This rule enforces which `URL` we should use. | ||
|
||
### Options | ||
|
||
This rule has a string option. | ||
|
||
```json | ||
{ | ||
"node/prefer-global/url": ["error", "always" | "never"] | ||
} | ||
``` | ||
|
||
- `"always"` (default) ... enforces to use the global variable `URL` rather than `require("url").URL`. | ||
- `"never"` ... enforces to use `require("url").URL` rather than the global variable `URL`. | ||
|
||
#### always | ||
|
||
Examples of :-1: **incorrect** code for this rule: | ||
|
||
```js | ||
/*eslint node/prefer-global/url: [error]*/ | ||
|
||
const { URL } = require("url") | ||
const u = new URL(s) | ||
``` | ||
|
||
Examples of :+1: **correct** code for this rule: | ||
|
||
```js | ||
/*eslint node/prefer-global/url: [error]*/ | ||
|
||
const u = new URL(s) | ||
``` | ||
|
||
#### never | ||
|
||
Examples of :-1: **incorrect** code for the `"never"` option: | ||
|
||
```js | ||
/*eslint node/prefer-global/url: [error, never]*/ | ||
|
||
const u = new URL(s) | ||
``` | ||
|
||
Examples of :+1: **correct** code for the `"never"` option: | ||
|
||
```js | ||
/*eslint node/prefer-global/url: [error, never]*/ | ||
|
||
const { URL } = require("url") | ||
const u = new URL(s) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.