The URL class of url module is defined as a global variable.
console.log(URL === require("url").URL) //β trueIt will be readable if we use either URL consistently.
This rule enforces which URL we should use.
This rule has a string option.
{
"node/prefer-global/url": ["error", "always" | "never"]
}"always"(default) ... enforces to use the global variableURLrather thanrequire("url").URL."never"... enforces to userequire("url").URLrather than the global variableURL.
Examples of π incorrect code for this rule:
/*eslint node/prefer-global/url: [error]*/
const { URL } = require("url")
const u = new URL(s)Examples of π correct code for this rule:
/*eslint node/prefer-global/url: [error]*/
const u = new URL(s)Examples of π incorrect code for the "never" option:
/*eslint node/prefer-global/url: [error, never]*/
const u = new URL(s)Examples of π correct code for the "never" option:
/*eslint node/prefer-global/url: [error, never]*/
const { URL } = require("url")
const u = new URL(s)