enforce either
URLSearchParams
orrequire("url").URLSearchParams
The URLSearchParams
class of url
module is defined as a global variable.
console.log(URLSearchParams === require("url").URLSearchParams) //→ true
It will be readable if we use either URLSearchParams
consistently.
This rule enforces which URLSearchParams
we should use.
This rule has a string option.
{
"node/prefer-global/url-search-params": ["error", "always" | "never"]
}
"always"
(default) ... enforces to use the global variableURLSearchParams
rather thanrequire("url").URLSearchParams
."never"
... enforces to userequire("url").URLSearchParams
rather than the global variableURLSearchParams
.
Examples of 👎 incorrect code for this rule:
/*eslint node/prefer-global/url-search-params: [error]*/
const { URLSearchParams } = require("url")
const u = new URLSearchParams(s)
Examples of 👍 correct code for this rule:
/*eslint node/prefer-global/url-search-params: [error]*/
const u = new URLSearchParams(s)
Examples of 👎 incorrect code for the "never"
option:
/*eslint node/prefer-global/url-search-params: [error, never]*/
const u = new URLSearchParams(s)
Examples of 👍 correct code for the "never"
option:
/*eslint node/prefer-global/url-search-params: [error, never]*/
const { URLSearchParams } = require("url")
const u = new URLSearchParams(s)