Skip to content

Latest commit

Β 

History

History
73 lines (46 loc) Β· 1.42 KB

File metadata and controls

73 lines (46 loc) Β· 1.42 KB

n/prefer-global/url

πŸ“ Enforce either URL or require("url").URL.

The URL class of url module is defined as a global variable.

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.

{
    "n/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 πŸ‘Ž incorrect code for this rule:

/*eslint n/prefer-global/url: [error]*/

const { URL } = require("url")
const u = new URL(s)

Examples of πŸ‘ correct code for this rule:

/*eslint n/prefer-global/url: [error]*/

const u = new URL(s)

never

Examples of πŸ‘Ž incorrect code for the "never" option:

/*eslint n/prefer-global/url: [error, never]*/

const u = new URL(s)

Examples of πŸ‘ correct code for the "never" option:

/*eslint n/prefer-global/url: [error, never]*/

const { URL } = require("url")
const u = new URL(s)

πŸ”Ž Implementation