eslint-plugin-node
Advanced tools
Comparing version 7.0.1 to 11.1.0
@@ -6,7 +6,17 @@ /* DON'T EDIT THIS FILE. This is generated by 'scripts/update-lib-index.js' */ | ||
configs: { | ||
recommended: require("./configs/recommended.json"), | ||
"recommended-module": require("./configs/recommended-module"), | ||
"recommended-script": require("./configs/recommended-script"), | ||
get recommended() { | ||
return require("./configs/recommended")() | ||
}, | ||
}, | ||
rules: { | ||
"callback-return": require("./rules/callback-return"), | ||
"exports-style": require("./rules/exports-style"), | ||
"file-extension-in-import": require("./rules/file-extension-in-import"), | ||
"global-require": require("./rules/global-require"), | ||
"handle-callback-err": require("./rules/handle-callback-err"), | ||
"no-callback-literal": require("./rules/no-callback-literal"), | ||
"no-deprecated-api": require("./rules/no-deprecated-api"), | ||
"no-exports-assign": require("./rules/no-exports-assign"), | ||
"no-extraneous-import": require("./rules/no-extraneous-import"), | ||
@@ -16,2 +26,10 @@ "no-extraneous-require": require("./rules/no-extraneous-require"), | ||
"no-missing-require": require("./rules/no-missing-require"), | ||
"no-mixed-requires": require("./rules/no-mixed-requires"), | ||
"no-new-require": require("./rules/no-new-require"), | ||
"no-path-concat": require("./rules/no-path-concat"), | ||
"no-process-env": require("./rules/no-process-env"), | ||
"no-process-exit": require("./rules/no-process-exit"), | ||
"no-restricted-import": require("./rules/no-restricted-import"), | ||
"no-restricted-require": require("./rules/no-restricted-require"), | ||
"no-sync": require("./rules/no-sync"), | ||
"no-unpublished-bin": require("./rules/no-unpublished-bin"), | ||
@@ -26,4 +44,8 @@ "no-unpublished-import": require("./rules/no-unpublished-import"), | ||
"prefer-global/process": require("./rules/prefer-global/process"), | ||
"prefer-global/text-decoder": require("./rules/prefer-global/text-decoder"), | ||
"prefer-global/text-encoder": require("./rules/prefer-global/text-encoder"), | ||
"prefer-global/url-search-params": require("./rules/prefer-global/url-search-params"), | ||
"prefer-global/url": require("./rules/prefer-global/url"), | ||
"prefer-promises/dns": require("./rules/prefer-promises/dns"), | ||
"prefer-promises/fs": require("./rules/prefer-promises/fs"), | ||
"process-exit-as-throw": require("./rules/process-exit-as-throw"), | ||
@@ -30,0 +52,0 @@ shebang: require("./rules/shebang"), |
@@ -149,4 +149,5 @@ /** | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/exports-style.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/exports-style.md", | ||
}, | ||
type: "suggestion", | ||
fixable: null, | ||
@@ -153,0 +154,0 @@ schema: [ |
@@ -9,2 +9,4 @@ /** | ||
const enumeratePropertyNames = require("../util/enumerate-property-names") | ||
const getConfiguredNodeVersion = require("../util/get-configured-node-version") | ||
const getSemverRange = require("../util/get-semver-range") | ||
@@ -15,30 +17,5 @@ const modules = { | ||
}, | ||
assert: { | ||
deepEqual: { | ||
[READ]: { | ||
since: "10.0.0", | ||
replacedBy: | ||
"'assert.deepStrictEqual' or 'assert.strict.deepEqual'", | ||
}, | ||
}, | ||
equal: { | ||
[READ]: { | ||
since: "10.0.0", | ||
replacedBy: "'assert.strictEqual' or 'assert.strict.equal'", | ||
}, | ||
}, | ||
notDeepEqual: { | ||
[READ]: { | ||
since: "10.0.0", | ||
replacedBy: | ||
"'assert.notDeepStrictEqual' or 'assert.strict.notDeepEqual'", | ||
}, | ||
}, | ||
notEqual: { | ||
[READ]: { | ||
since: "10.0.0", | ||
replacedBy: | ||
"'assert.notStrictEqual' or 'assert.strict.notEqual'", | ||
}, | ||
}, | ||
//eslint-disable-next-line camelcase | ||
_stream_wrap: { | ||
[READ]: { since: "12.0.0", replacedBy: null }, | ||
}, | ||
@@ -50,3 +27,8 @@ //eslint-disable-next-line camelcase | ||
since: "8.2.0", | ||
replacedBy: "'async_hooks.executionAsyncId()'", | ||
replacedBy: [ | ||
{ | ||
name: "'async_hooks.executionAsyncId()'", | ||
supported: "8.1.0", | ||
}, | ||
], | ||
}, | ||
@@ -65,7 +47,13 @@ }, | ||
since: "6.0.0", | ||
replacedBy: "'buffer.Buffer.alloc()' or 'buffer.Buffer.from()'", | ||
replacedBy: [ | ||
{ name: "'buffer.Buffer.alloc()'", supported: "5.10.0" }, | ||
{ name: "'buffer.Buffer.from()'", supported: "5.10.0" }, | ||
], | ||
}, | ||
[CALL]: { | ||
since: "6.0.0", | ||
replacedBy: "'buffer.Buffer.alloc()' or 'buffer.Buffer.from()'", | ||
replacedBy: [ | ||
{ name: "'buffer.Buffer.alloc()'", supported: "5.10.0" }, | ||
{ name: "'buffer.Buffer.from()'", supported: "5.10.0" }, | ||
], | ||
}, | ||
@@ -76,3 +64,8 @@ }, | ||
since: "6.0.0", | ||
replacedBy: "'buffer.Buffer.allocUnsafeSlow()'", | ||
replacedBy: [ | ||
{ | ||
name: "'buffer.Buffer.allocUnsafeSlow()'", | ||
supported: "5.12.0", | ||
}, | ||
], | ||
}, | ||
@@ -88,2 +81,5 @@ }, | ||
crypto: { | ||
_toBuf: { | ||
[READ]: { since: "11.0.0", replacedBy: null }, | ||
}, | ||
Credentials: { | ||
@@ -96,3 +92,8 @@ [READ]: { since: "0.12.0", replacedBy: "'tls.SecureContext'" }, | ||
createCipher: { | ||
[READ]: { since: "10.0.0", replacedBy: "'tls.createCipheriv()'" }, | ||
[READ]: { | ||
since: "10.0.0", | ||
replacedBy: [ | ||
{ name: "'crypto.createCipheriv()'", supported: "0.1.94" }, | ||
], | ||
}, | ||
}, | ||
@@ -102,7 +103,20 @@ createCredentials: { | ||
since: "0.12.0", | ||
replacedBy: "'tls.createSecureContext()'", | ||
replacedBy: [ | ||
{ | ||
name: "'tls.createSecureContext()'", | ||
supported: "0.11.13", | ||
}, | ||
], | ||
}, | ||
}, | ||
createDecipher: { | ||
[READ]: { since: "10.0.0", replacedBy: "'tls.createDecipheriv()'" }, | ||
[READ]: { | ||
since: "10.0.0", | ||
replacedBy: [ | ||
{ | ||
name: "'crypto.createDecipheriv()'", | ||
supported: "0.1.94", | ||
}, | ||
], | ||
}, | ||
}, | ||
@@ -112,5 +126,34 @@ fips: { | ||
since: "10.0.0", | ||
replacedBy: "'crypto.getFips()' and 'crypto.setFips()'", | ||
replacedBy: [ | ||
{ | ||
name: "'crypto.getFips()' and 'crypto.setFips()'", | ||
supported: "10.0.0", | ||
}, | ||
], | ||
}, | ||
}, | ||
prng: { | ||
[READ]: { | ||
since: "11.0.0", | ||
replacedBy: [ | ||
{ name: "'crypto.randomBytes()'", supported: "0.5.8" }, | ||
], | ||
}, | ||
}, | ||
pseudoRandomBytes: { | ||
[READ]: { | ||
since: "11.0.0", | ||
replacedBy: [ | ||
{ name: "'crypto.randomBytes()'", supported: "0.5.8" }, | ||
], | ||
}, | ||
}, | ||
rng: { | ||
[READ]: { | ||
since: "11.0.0", | ||
replacedBy: [ | ||
{ name: "'crypto.randomBytes()'", supported: "0.5.8" }, | ||
], | ||
}, | ||
}, | ||
}, | ||
@@ -125,3 +168,8 @@ domain: { | ||
since: "4.0.0", | ||
replacedBy: "'events.EventEmitter#listenerCount()'", | ||
replacedBy: [ | ||
{ | ||
name: "'events.EventEmitter#listenerCount()'", | ||
supported: "3.2.0", | ||
}, | ||
], | ||
}, | ||
@@ -133,3 +181,8 @@ }, | ||
since: "4.0.0", | ||
replacedBy: "'events.EventEmitter#listenerCount()'", | ||
replacedBy: [ | ||
{ | ||
name: "'events.EventEmitter#listenerCount()'", | ||
supported: "3.2.0", | ||
}, | ||
], | ||
}, | ||
@@ -148,3 +201,6 @@ }, | ||
since: "4.0.0", | ||
replacedBy: "'fs.stat()' or 'fs.access()'", | ||
replacedBy: [ | ||
{ name: "'fs.stat()'", supported: "0.0.2" }, | ||
{ name: "'fs.access()'", supported: "0.11.15" }, | ||
], | ||
}, | ||
@@ -158,12 +214,9 @@ }, | ||
}, | ||
lchown: { | ||
[READ]: { since: "0.4.0", replacedBy: null }, | ||
}, | ||
lchownSync: { | ||
[READ]: { since: "0.4.0", replacedBy: null }, | ||
}, | ||
}, | ||
http: { | ||
createClient: { | ||
[READ]: { since: "0.10.0", replacedBy: "'http.request()'" }, | ||
[READ]: { | ||
since: "0.10.0", | ||
replacedBy: [{ name: "'http.request()'", supported: "0.3.6" }], | ||
}, | ||
}, | ||
@@ -173,4 +226,18 @@ }, | ||
Module: { | ||
createRequireFromPath: { | ||
[READ]: { | ||
since: "12.2.0", | ||
replacedBy: [ | ||
{ | ||
name: "'module.createRequire()'", | ||
supported: "12.2.0", | ||
}, | ||
], | ||
}, | ||
}, | ||
requireRepl: { | ||
[READ]: { since: "6.0.0", replacedBy: "'require(\"repl\")'" }, | ||
[READ]: { | ||
since: "6.0.0", | ||
replacedBy: "'require(\"repl\")'", | ||
}, | ||
}, | ||
@@ -181,4 +248,18 @@ _debug: { | ||
}, | ||
createRequireFromPath: { | ||
[READ]: { | ||
since: "12.2.0", | ||
replacedBy: [ | ||
{ | ||
name: "'module.createRequire()'", | ||
supported: "12.2.0", | ||
}, | ||
], | ||
}, | ||
}, | ||
requireRepl: { | ||
[READ]: { since: "6.0.0", replacedBy: "'require(\"repl\")'" }, | ||
[READ]: { | ||
since: "6.0.0", | ||
replacedBy: "'require(\"repl\")'", | ||
}, | ||
}, | ||
@@ -189,8 +270,21 @@ _debug: { | ||
}, | ||
net: { | ||
_setSimultaneousAccepts: { | ||
[READ]: { since: "12.0.0", replacedBy: null }, | ||
}, | ||
}, | ||
os: { | ||
getNetworkInterfaces: { | ||
[READ]: { since: "0.6.0", replacedBy: "'os.networkInterfaces()'" }, | ||
[READ]: { | ||
since: "0.6.0", | ||
replacedBy: [ | ||
{ name: "'os.networkInterfaces()'", supported: "0.6.0" }, | ||
], | ||
}, | ||
}, | ||
tmpDir: { | ||
[READ]: { since: "7.0.0", replacedBy: "'os.tmpdir()'" }, | ||
[READ]: { | ||
since: "7.0.0", | ||
replacedBy: [{ name: "'os.tmpdir()'", supported: "0.9.9" }], | ||
}, | ||
}, | ||
@@ -200,3 +294,8 @@ }, | ||
_makeLong: { | ||
[READ]: { since: "9.0.0", replacedBy: "'path.toNamespacedPath()'" }, | ||
[READ]: { | ||
since: "9.0.0", | ||
replacedBy: [ | ||
{ name: "'path.toNamespacedPath()'", supported: "9.0.0" }, | ||
], | ||
}, | ||
}, | ||
@@ -206,12 +305,32 @@ }, | ||
EventEmitter: { | ||
[READ]: { since: "0.6.0", replacedBy: "'require(\"events\")'" }, | ||
[READ]: { | ||
since: "0.6.0", | ||
replacedBy: "'require(\"events\")'", | ||
}, | ||
}, | ||
assert: { | ||
[READ]: { since: "10.0.0", replacedBy: "'require(\"assert\")'" }, | ||
[READ]: { | ||
since: "10.0.0", | ||
replacedBy: "'require(\"assert\")'", | ||
}, | ||
}, | ||
binding: { | ||
[READ]: { since: "10.9.0", replacedBy: null }, | ||
}, | ||
env: { | ||
NODE_REPL_HISTORY_FILE: { | ||
[READ]: { since: "4.0.0", replacedBy: "'NODE_REPL_HISTORY'" }, | ||
[READ]: { | ||
since: "4.0.0", | ||
replacedBy: "'NODE_REPL_HISTORY'", | ||
}, | ||
}, | ||
}, | ||
report: { | ||
triggerReport: { | ||
[READ]: { | ||
since: "11.12.0", | ||
replacedBy: "'process.report.writeReport()'", | ||
}, | ||
}, | ||
}, | ||
}, | ||
@@ -244,7 +363,13 @@ punycode: { | ||
since: "6.0.0", | ||
replacedBy: "'buffer.Buffer.alloc()' or 'buffer.Buffer.from()'", | ||
replacedBy: [ | ||
{ name: "'buffer.Buffer.alloc()'", supported: "5.10.0" }, | ||
{ name: "'buffer.Buffer.from()'", supported: "5.10.0" }, | ||
], | ||
}, | ||
[CALL]: { | ||
since: "6.0.0", | ||
replacedBy: "'buffer.Buffer.alloc()' or 'buffer.Buffer.from()'", | ||
replacedBy: [ | ||
{ name: "'buffer.Buffer.alloc()'", supported: "5.10.0" }, | ||
{ name: "'buffer.Buffer.from()'", supported: "5.10.0" }, | ||
], | ||
}, | ||
@@ -255,3 +380,8 @@ }, | ||
since: "6.0.0", | ||
replacedBy: "'buffer.Buffer.allocUnsafeSlow()'", | ||
replacedBy: [ | ||
{ | ||
name: "'buffer.Buffer.allocUnsafeSlow()'", | ||
supported: "5.12.0", | ||
}, | ||
], | ||
}, | ||
@@ -261,3 +391,6 @@ }, | ||
sys: { | ||
[READ]: { since: "0.3.0", replacedBy: "'util' module" }, | ||
[READ]: { | ||
since: "0.3.0", | ||
replacedBy: "'util' module", | ||
}, | ||
}, | ||
@@ -268,3 +401,6 @@ timers: { | ||
since: "10.0.0", | ||
replacedBy: "'setTimeout()' or 'setInterval()'", | ||
replacedBy: [ | ||
{ name: "'setTimeout()'", supported: "0.0.1" }, | ||
{ name: "'setInterval()'", supported: "0.0.1" }, | ||
], | ||
}, | ||
@@ -275,3 +411,6 @@ }, | ||
since: "10.0.0", | ||
replacedBy: "'clearTimeout()' or 'clearInterval()'", | ||
replacedBy: [ | ||
{ name: "'clearTimeout()'", supported: "0.0.1" }, | ||
{ name: "'clearInterval()'", supported: "0.0.1" }, | ||
], | ||
}, | ||
@@ -285,6 +424,12 @@ }, | ||
CryptoStream: { | ||
[READ]: { since: "0.12.0", replacedBy: "'tls.TLSSocket'" }, | ||
[READ]: { | ||
since: "0.12.0", | ||
replacedBy: [{ name: "'tls.TLSSocket'", supported: "0.11.4" }], | ||
}, | ||
}, | ||
SecurePair: { | ||
[READ]: { since: "6.0.0", replacedBy: "'tls.TLSSocket'" }, | ||
[READ]: { | ||
since: "6.0.0", | ||
replacedBy: [{ name: "'tls.TLSSocket'", supported: "0.11.4" }], | ||
}, | ||
}, | ||
@@ -295,6 +440,14 @@ convertNPNProtocols: { | ||
createSecurePair: { | ||
[READ]: { since: "6.0.0", replacedBy: "'tls.TLSSocket'" }, | ||
[READ]: { | ||
since: "6.0.0", | ||
replacedBy: [{ name: "'tls.TLSSocket'", supported: "0.11.4" }], | ||
}, | ||
}, | ||
parseCertString: { | ||
[READ]: { since: "8.6.0", replacedBy: "'querystring.parse()'" }, | ||
[READ]: { | ||
since: "8.6.0", | ||
replacedBy: [ | ||
{ name: "'querystring.parse()'", supported: "0.1.25" }, | ||
], | ||
}, | ||
}, | ||
@@ -311,11 +464,44 @@ }, | ||
}, | ||
url: { | ||
parse: { | ||
[READ]: { | ||
since: "11.0.0", | ||
replacedBy: [ | ||
{ name: "'url.URL' constructor", supported: "6.13.0" }, | ||
], | ||
}, | ||
}, | ||
resolve: { | ||
[READ]: { | ||
since: "11.0.0", | ||
replacedBy: [ | ||
{ name: "'url.URL' constructor", supported: "6.13.0" }, | ||
], | ||
}, | ||
}, | ||
}, | ||
util: { | ||
debug: { | ||
[READ]: { since: "0.12.0", replacedBy: "'console.error()'" }, | ||
[READ]: { | ||
since: "0.12.0", | ||
replacedBy: [ | ||
{ name: "'console.error()'", supported: "0.1.100" }, | ||
], | ||
}, | ||
}, | ||
error: { | ||
[READ]: { since: "0.12.0", replacedBy: "'console.error()'" }, | ||
[READ]: { | ||
since: "0.12.0", | ||
replacedBy: [ | ||
{ name: "'console.error()'", supported: "0.1.100" }, | ||
], | ||
}, | ||
}, | ||
isArray: { | ||
[READ]: { since: "4.0.0", replacedBy: "'Array.isArray()'" }, | ||
[READ]: { | ||
since: "4.0.0", | ||
replacedBy: [ | ||
{ name: "'Array.isArray()'", supported: "0.1.100" }, | ||
], | ||
}, | ||
}, | ||
@@ -326,3 +512,8 @@ isBoolean: { | ||
isBuffer: { | ||
[READ]: { since: "4.0.0", replacedBy: "'Buffer.isBuffer()'" }, | ||
[READ]: { | ||
since: "4.0.0", | ||
replacedBy: [ | ||
{ name: "'Buffer.isBuffer()'", supported: "0.1.101" }, | ||
], | ||
}, | ||
}, | ||
@@ -369,12 +560,26 @@ isDate: { | ||
print: { | ||
[READ]: { since: "0.12.0", replacedBy: "'console.log()'" }, | ||
[READ]: { | ||
since: "0.12.0", | ||
replacedBy: [{ name: "'console.log()'", supported: "0.1.100" }], | ||
}, | ||
}, | ||
pump: { | ||
[READ]: { since: "0.10.0", replacedBy: "'stream.Readable#pipe()'" }, | ||
[READ]: { | ||
since: "0.10.0", | ||
replacedBy: [ | ||
{ name: "'stream.Readable#pipe()'", supported: "0.9.4" }, | ||
], | ||
}, | ||
}, | ||
puts: { | ||
[READ]: { since: "0.12.0", replacedBy: "'console.log()'" }, | ||
[READ]: { | ||
since: "0.12.0", | ||
replacedBy: [{ name: "'console.log()'", supported: "0.1.100" }], | ||
}, | ||
}, | ||
_extend: { | ||
[READ]: { since: "6.0.0", replacedBy: "'Object.assign()'" }, | ||
[READ]: { | ||
since: "6.0.0", | ||
replacedBy: [{ name: "'Object.assign()'", supported: "4.0.0" }], | ||
}, | ||
}, | ||
@@ -392,11 +597,38 @@ }, | ||
since: "6.0.0", | ||
replacedBy: "'Buffer.alloc()' or 'Buffer.from()'", | ||
replacedBy: [ | ||
{ name: "'Buffer.alloc()'", supported: "5.10.0" }, | ||
{ name: "'Buffer.from()'", supported: "5.10.0" }, | ||
], | ||
}, | ||
[CALL]: { | ||
since: "6.0.0", | ||
replacedBy: "'Buffer.alloc()' or 'Buffer.from()'", | ||
replacedBy: [ | ||
{ name: "'Buffer.alloc()'", supported: "5.10.0" }, | ||
{ name: "'Buffer.from()'", supported: "5.10.0" }, | ||
], | ||
}, | ||
}, | ||
COUNTER_NET_SERVER_CONNECTION: { | ||
[READ]: { since: "11.0.0", replacedBy: null }, | ||
}, | ||
COUNTER_NET_SERVER_CONNECTION_CLOSE: { | ||
[READ]: { since: "11.0.0", replacedBy: null }, | ||
}, | ||
COUNTER_HTTP_SERVER_REQUEST: { | ||
[READ]: { since: "11.0.0", replacedBy: null }, | ||
}, | ||
COUNTER_HTTP_SERVER_RESPONSE: { | ||
[READ]: { since: "11.0.0", replacedBy: null }, | ||
}, | ||
COUNTER_HTTP_CLIENT_REQUEST: { | ||
[READ]: { since: "11.0.0", replacedBy: null }, | ||
}, | ||
COUNTER_HTTP_CLIENT_RESPONSE: { | ||
[READ]: { since: "11.0.0", replacedBy: null }, | ||
}, | ||
GLOBAL: { | ||
[READ]: { since: "6.0.0", replacedBy: "'global'" }, | ||
[READ]: { | ||
since: "6.0.0", | ||
replacedBy: [{ name: "'global'", supported: "0.1.27" }], | ||
}, | ||
}, | ||
@@ -417,3 +649,6 @@ Intl: { | ||
root: { | ||
[READ]: { since: "6.0.0", replacedBy: "'global'" }, | ||
[READ]: { | ||
since: "6.0.0", | ||
replacedBy: [{ name: "'global'", supported: "0.1.27" }], | ||
}, | ||
}, | ||
@@ -426,7 +661,20 @@ process: modules.process, | ||
* | ||
* @param {string|null} replacedBy - The text of substitute way. | ||
* @param {string|array|null} replacedBy - The text of substitute way. | ||
* @param {Range} version - The configured version range | ||
* @returns {string} Replacement message. | ||
*/ | ||
function toReplaceMessage(replacedBy) { | ||
return replacedBy ? `. Use ${replacedBy} instead` : "" | ||
function toReplaceMessage(replacedBy, version) { | ||
let message = replacedBy | ||
if (Array.isArray(replacedBy)) { | ||
message = replacedBy | ||
.filter( | ||
({ supported }) => | ||
!version.intersects(getSemverRange(`<${supported}`)) | ||
) | ||
.map(({ name }) => name) | ||
.join(" or ") | ||
} | ||
return message ? `. Use ${message} instead` : "" | ||
} | ||
@@ -449,2 +697,18 @@ | ||
/** | ||
* Parses the options. | ||
* @param {RuleContext} context The rule context. | ||
* @returns {{version:Range,ignoredGlobalItems:Set<string>,ignoredModuleItems:Set<string>}} Parsed | ||
* value. | ||
*/ | ||
function parseOptions(context) { | ||
const raw = context.options[0] || {} | ||
const filePath = context.getFilename() | ||
const version = getConfiguredNodeVersion(raw.version, filePath) | ||
const ignoredModuleItems = new Set(raw.ignoreModuleItems || []) | ||
const ignoredGlobalItems = new Set(raw.ignoreGlobalItems || []) | ||
return Object.freeze({ version, ignoredGlobalItems, ignoredModuleItems }) | ||
} | ||
module.exports = { | ||
@@ -457,4 +721,5 @@ meta: { | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/no-deprecated-api.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-deprecated-api.md", | ||
}, | ||
type: "problem", | ||
fixable: null, | ||
@@ -465,2 +730,5 @@ schema: [ | ||
properties: { | ||
version: { | ||
type: "string", | ||
}, | ||
ignoreModuleItems: { | ||
@@ -491,5 +759,7 @@ type: "array", | ||
create(context) { | ||
const options = context.options[0] || {} | ||
const ignoredModuleItems = new Set(options.ignoreModuleItems || []) | ||
const ignoredGlobalItems = new Set(options.ignoreGlobalItems || []) | ||
const { | ||
ignoredModuleItems, | ||
ignoredGlobalItems, | ||
version, | ||
} = parseOptions(context) | ||
@@ -513,3 +783,3 @@ /** | ||
version: info.since, | ||
replace: toReplaceMessage(info.replacedBy), | ||
replace: toReplaceMessage(info.replacedBy, version), | ||
}, | ||
@@ -516,0 +786,0 @@ }) |
@@ -10,4 +10,5 @@ /** | ||
const getConvertPath = require("../util/get-convert-path") | ||
const getImportTargets = require("../util/get-import-export-targets") | ||
const getResolvePaths = require("../util/get-resolve-paths") | ||
const getTryExtensions = require("../util/get-try-extensions") | ||
const visitImport = require("../util/visit-import") | ||
@@ -18,8 +19,9 @@ module.exports = { | ||
description: | ||
"disallow `import` declarations of extraneous packages", | ||
"disallow `import` declarations which import extraneous modules", | ||
category: "Possible Errors", | ||
recommended: false, | ||
recommended: true, | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/no-extraneous-import.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-extraneous-import.md", | ||
}, | ||
type: "problem", | ||
fixable: null, | ||
@@ -33,2 +35,3 @@ schema: [ | ||
resolvePaths: getResolvePaths.schema, | ||
tryExtensions: getTryExtensions.schema, | ||
}, | ||
@@ -45,12 +48,6 @@ additionalProperties: false, | ||
return { | ||
"Program:exit"(node) { | ||
checkExtraneous( | ||
context, | ||
filePath, | ||
getImportTargets(context, node, false) | ||
) | ||
}, | ||
} | ||
return visitImport(context, {}, targets => { | ||
checkExtraneous(context, filePath, targets) | ||
}) | ||
}, | ||
} |
@@ -10,4 +10,5 @@ /** | ||
const getConvertPath = require("../util/get-convert-path") | ||
const getRequireTargets = require("../util/get-require-targets") | ||
const getResolvePaths = require("../util/get-resolve-paths") | ||
const getTryExtensions = require("../util/get-try-extensions") | ||
const visitRequire = require("../util/visit-require") | ||
@@ -18,8 +19,9 @@ module.exports = { | ||
description: | ||
"disallow `require()` expressions of extraneous packages", | ||
"disallow `require()` expressions which import extraneous modules", | ||
category: "Possible Errors", | ||
recommended: true, | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/no-extraneous-require.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-extraneous-require.md", | ||
}, | ||
type: "problem", | ||
fixable: null, | ||
@@ -33,2 +35,3 @@ schema: [ | ||
resolvePaths: getResolvePaths.schema, | ||
tryExtensions: getTryExtensions.schema, | ||
}, | ||
@@ -45,12 +48,6 @@ additionalProperties: false, | ||
return { | ||
"Program:exit"() { | ||
checkExtraneous( | ||
context, | ||
filePath, | ||
getRequireTargets(context, false) | ||
) | ||
}, | ||
} | ||
return visitRequire(context, {}, targets => { | ||
checkExtraneous(context, filePath, targets) | ||
}) | ||
}, | ||
} |
@@ -14,4 +14,5 @@ /** | ||
const getPackageJson = require("../util/get-package-json") | ||
const getRequireTargets = require("../util/get-require-targets") | ||
const getImportExportTargets = require("../util/get-import-export-targets") | ||
const mergeVisitorsInPlace = require("../util/merge-visitors-in-place") | ||
const visitImport = require("../util/visit-import") | ||
const visitRequire = require("../util/visit-require") | ||
@@ -49,3 +50,3 @@ const CORE_MODULES = new Set([ | ||
]) | ||
const BACK_SLASH = /\\/g | ||
const BACK_SLASH = /\\/gu | ||
@@ -60,4 +61,5 @@ module.exports = { | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/no-hide-core-modules.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-hide-core-modules.md", | ||
}, | ||
type: "problem", | ||
deprecated: true, | ||
@@ -103,45 +105,57 @@ fixable: null, | ||
) | ||
const targets = [] | ||
return { | ||
"Program:exit"(node) { | ||
const targets = [] | ||
.concat( | ||
getRequireTargets(context, true), | ||
getImportExportTargets(context, node, true) | ||
) | ||
.filter(t => CORE_MODULES.has(t.moduleName)) | ||
return [ | ||
visitImport(context, { includeCore: true }, importTargets => | ||
targets.push(...importTargets) | ||
), | ||
visitRequire(context, { includeCore: true }, requireTargets => | ||
targets.push(...requireTargets) | ||
), | ||
{ | ||
"Program:exit"() { | ||
for (const target of targets.filter( | ||
t => | ||
CORE_MODULES.has(t.moduleName) && | ||
t.moduleName === t.name | ||
)) { | ||
const name = target.moduleName | ||
const allowed = | ||
allow.indexOf(name) !== -1 || | ||
(ignoreDirectDependencies && deps.has(name)) || | ||
(ignoreIndirectDependencies && !deps.has(name)) | ||
for (const target of targets) { | ||
const name = target.moduleName | ||
const allowed = | ||
allow.indexOf(name) !== -1 || | ||
(ignoreDirectDependencies && deps.has(name)) || | ||
(ignoreIndirectDependencies && !deps.has(name)) | ||
if (allowed) { | ||
continue | ||
} | ||
if (allowed) { | ||
continue | ||
} | ||
let resolved = "" | ||
try { | ||
resolved = resolve.sync(`${name}/`, { | ||
basedir: dirPath, | ||
}) | ||
} catch (_error) { | ||
continue | ||
} | ||
const resolved = resolve.sync(name, { basedir: dirPath }) | ||
const isCore = resolved === name | ||
if (isCore) { | ||
continue | ||
context.report({ | ||
node: target.node, | ||
loc: target.node.loc, | ||
message: | ||
"Unexpected import of third-party module '{{name}}'.", | ||
data: { | ||
name: path | ||
.relative(dirPath, resolved) | ||
.replace(BACK_SLASH, "/"), | ||
}, | ||
}) | ||
} | ||
context.report({ | ||
node: target.node, | ||
loc: target.node.loc, | ||
message: | ||
"Unexpected import of third-party module '{{name}}'.", | ||
data: { | ||
name: path | ||
.relative(dirPath, resolved) | ||
.replace(BACK_SLASH, "/"), | ||
}, | ||
}) | ||
} | ||
}, | ||
}, | ||
} | ||
].reduce( | ||
(mergedVisitor, thisVisitor) => | ||
mergeVisitorsInPlace(mergedVisitor, thisVisitor), | ||
{} | ||
) | ||
}, | ||
} |
@@ -9,5 +9,5 @@ /** | ||
const getAllowModules = require("../util/get-allow-modules") | ||
const getImportExportTargets = require("../util/get-import-export-targets") | ||
const getResolvePaths = require("../util/get-resolve-paths") | ||
const getTryExtensions = require("../util/get-try-extensions") | ||
const visitImport = require("../util/visit-import") | ||
@@ -17,8 +17,10 @@ module.exports = { | ||
docs: { | ||
description: "disallow `import` declarations of missing files", | ||
description: | ||
"disallow `import` declarations which import non-existence modules", | ||
category: "Possible Errors", | ||
recommended: false, | ||
recommended: true, | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/no-missing-import.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-missing-import.md", | ||
}, | ||
type: "problem", | ||
fixable: null, | ||
@@ -43,8 +45,6 @@ schema: [ | ||
return { | ||
"Program:exit"(node) { | ||
checkExistence(context, getImportExportTargets(context, node)) | ||
}, | ||
} | ||
return visitImport(context, {}, targets => { | ||
checkExistence(context, targets) | ||
}) | ||
}, | ||
} |
@@ -9,5 +9,5 @@ /** | ||
const getAllowModules = require("../util/get-allow-modules") | ||
const getRequireTargets = require("../util/get-require-targets") | ||
const getResolvePaths = require("../util/get-resolve-paths") | ||
const getTryExtensions = require("../util/get-try-extensions") | ||
const visitRequire = require("../util/visit-require") | ||
@@ -17,8 +17,10 @@ module.exports = { | ||
docs: { | ||
description: "disallow `require()` expressions of missing files", | ||
description: | ||
"disallow `require()` expressions which import non-existence modules", | ||
category: "Possible Errors", | ||
recommended: true, | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/no-missing-require.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-missing-require.md", | ||
}, | ||
type: "problem", | ||
fixable: null, | ||
@@ -43,8 +45,6 @@ schema: [ | ||
return { | ||
"Program:exit"() { | ||
checkExistence(context, getRequireTargets(context)) | ||
}, | ||
} | ||
return visitRequire(context, {}, targets => { | ||
checkExistence(context, targets) | ||
}) | ||
}, | ||
} |
@@ -35,8 +35,9 @@ /** | ||
docs: { | ||
description: "disallow 'bin' files which are ignored by npm", | ||
description: "disallow `bin` files that npm ignores", | ||
category: "Possible Errors", | ||
recommended: true, | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/no-unpublished-bin.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-unpublished-bin.md", | ||
}, | ||
type: "problem", | ||
fixable: null, | ||
@@ -72,3 +73,3 @@ schema: [ | ||
const relativePath = getConvertPath(context)( | ||
path.relative(basedir, rawFilePath).replace(/\\/g, "/") | ||
path.relative(basedir, rawFilePath).replace(/\\/gu, "/") | ||
) | ||
@@ -75,0 +76,0 @@ const filePath = path.join(basedir, relativePath) |
@@ -10,5 +10,5 @@ /** | ||
const getConvertPath = require("../util/get-convert-path") | ||
const getImportExportTargets = require("../util/get-import-export-targets") | ||
const getResolvePaths = require("../util/get-resolve-paths") | ||
const getTryExtensions = require("../util/get-try-extensions") | ||
const visitImport = require("../util/visit-import") | ||
@@ -18,8 +18,10 @@ module.exports = { | ||
docs: { | ||
description: "disallow `import` declarations of private things", | ||
description: | ||
"disallow `import` declarations which import private modules", | ||
category: "Possible Errors", | ||
recommended: false, | ||
recommended: true, | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/no-unpublished-import.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-unpublished-import.md", | ||
}, | ||
type: "problem", | ||
fixable: null, | ||
@@ -45,12 +47,6 @@ schema: [ | ||
return { | ||
"Program:exit"(node) { | ||
checkPublish( | ||
context, | ||
filePath, | ||
getImportExportTargets(context, node) | ||
) | ||
}, | ||
} | ||
return visitImport(context, {}, targets => { | ||
checkPublish(context, filePath, targets) | ||
}) | ||
}, | ||
} |
@@ -10,5 +10,5 @@ /** | ||
const getConvertPath = require("../util/get-convert-path") | ||
const getRequireTargets = require("../util/get-require-targets") | ||
const getResolvePaths = require("../util/get-resolve-paths") | ||
const getTryExtensions = require("../util/get-try-extensions") | ||
const visitRequire = require("../util/visit-require") | ||
@@ -18,8 +18,10 @@ module.exports = { | ||
docs: { | ||
description: "disallow `require()` expressions of private things", | ||
description: | ||
"disallow `require()` expressions which import private modules", | ||
category: "Possible Errors", | ||
recommended: true, | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/no-unpublished-require.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-unpublished-require.md", | ||
}, | ||
type: "problem", | ||
fixable: null, | ||
@@ -45,8 +47,6 @@ schema: [ | ||
return { | ||
"Program:exit"() { | ||
checkPublish(context, filePath, getRequireTargets(context)) | ||
}, | ||
} | ||
return visitRequire(context, {}, targets => { | ||
checkPublish(context, filePath, targets) | ||
}) | ||
}, | ||
} |
@@ -35,10 +35,10 @@ /** | ||
const DEFAULT_VERSION = "4.0.0" | ||
const FUNC_TYPE = /^(?:Arrow)?Function(?:Declaration|Expression)$/ | ||
const CLASS_TYPE = /^Class(?:Declaration|Expression)$/ | ||
const DESTRUCTURING_PARENT_TYPE = /^(?:Function(?:Declaration|Expression)|ArrowFunctionExpression|AssignmentExpression|VariableDeclarator)$/ | ||
const TOPLEVEL_SCOPE_TYPE = /^(?:global|function|module)$/ | ||
const BINARY_NUMBER = /^0[bB]/ | ||
const OCTAL_NUMBER = /^0[oO]/ | ||
const UNICODE_ESC = /(\\+)u\{[0-9a-fA-F]+?\}/g | ||
const GET_OR_SET = /^(?:g|s)et$/ | ||
const FUNC_TYPE = /^(?:Arrow)?Function(?:Declaration|Expression)$/u | ||
const CLASS_TYPE = /^Class(?:Declaration|Expression)$/u | ||
const DESTRUCTURING_PARENT_TYPE = /^(?:Function(?:Declaration|Expression)|ArrowFunctionExpression|AssignmentExpression|VariableDeclarator)$/u | ||
const TOPLEVEL_SCOPE_TYPE = /^(?:global|function|module)$/u | ||
const BINARY_NUMBER = /^0[bB]/u | ||
const OCTAL_NUMBER = /^0[oO]/u | ||
const UNICODE_ESC = /(\\+)u\{[0-9a-fA-F]+?\}/gu | ||
const GET_OR_SET = /^(?:g|s)et$/u | ||
const NEW_BUILTIN_TYPES = [ | ||
@@ -145,5 +145,5 @@ "Int8Array", | ||
} | ||
const REGEXP_NAMED_GROUP = /(\\*)\(\?<[_$\w]/ | ||
const REGEXP_LOOKBEHIND = /(\\*)\(\?<[=!]/ | ||
const REGEXP_UNICODE_PROPERTY = /(\\*)\\[pP]{.+?}/ | ||
const REGEXP_NAMED_GROUP = /(\\*)\(\?<[_$\w]/u | ||
const REGEXP_LOOKBEHIND = /(\\*)\(\?<[=!]/u | ||
const REGEXP_UNICODE_PROPERTY = /(\\*)\\[pP]\{.+?\}/u | ||
const FEATURES = { | ||
@@ -1004,3 +1004,3 @@ defaultParameters: { | ||
*/ | ||
function nomalizeScope(initialScope, node) { | ||
function normalizeScope(initialScope, node) { | ||
let scope = getInnermostScope(initialScope, node) | ||
@@ -1052,6 +1052,10 @@ | ||
recommended: false, | ||
replacedBy: ["no-unsupported-ecma-features"], | ||
replacedBy: [ | ||
"node/no-unsupported-features/es-syntax", | ||
"node/no-unsupported-features/es-builtins", | ||
], | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/no-unsupported-features.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-unsupported-features.md", | ||
}, | ||
type: "problem", | ||
deprecated: true, | ||
@@ -1172,3 +1176,3 @@ fixable: null, | ||
}) | ||
} else if (!nomalizeScope(context.getScope(), node).isStrict) { | ||
} else if (!normalizeScope(context.getScope(), node).isStrict) { | ||
context.report({ | ||
@@ -1175,0 +1179,0 @@ node, |
@@ -17,2 +17,5 @@ /** | ||
}, | ||
BigInt: { | ||
[READ]: { supported: "10.4.0" }, | ||
}, | ||
Map: { | ||
@@ -53,2 +56,3 @@ [READ]: { supported: "0.12.0" }, | ||
assign: { [READ]: { supported: "4.0.0" } }, | ||
fromEntries: { [READ]: { supported: "12.0.0" } }, | ||
getOwnPropertySymbols: { [READ]: { supported: "0.12.0" } }, | ||
@@ -63,2 +67,3 @@ is: { [READ]: { supported: "0.10.0" } }, | ||
[READ]: { supported: "0.12.0" }, | ||
allSettled: { [READ]: { supported: "12.9.0" } }, | ||
}, | ||
@@ -102,2 +107,8 @@ Proxy: { | ||
}, | ||
BigInt64Array: { | ||
[READ]: { supported: "10.4.0" }, | ||
}, | ||
BigUint64Array: { | ||
[READ]: { supported: "10.4.0" }, | ||
}, | ||
Float32Array: { | ||
@@ -124,2 +135,5 @@ [READ]: { supported: "0.10.0" }, | ||
}, | ||
globalThis: { | ||
[READ]: { supported: "12.0.0" }, | ||
}, | ||
}, | ||
@@ -136,4 +150,5 @@ } | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/no-unsupported-features/es-builtins.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-unsupported-features/es-builtins.md", | ||
}, | ||
type: "problem", | ||
fixable: null, | ||
@@ -140,0 +155,0 @@ schema: [ |
@@ -12,4 +12,5 @@ /** | ||
const getSemverRange = require("../../util/get-semver-range") | ||
const mergeVisitorsInPlace = require("../../util/merge-visitors-in-place") | ||
const getOrSet = /^(?:g|s)et$/ | ||
const getOrSet = /^(?:g|s)et$/u | ||
const features = { | ||
@@ -353,2 +354,35 @@ //-------------------------------------------------------------------------- | ||
}, | ||
//-------------------------------------------------------------------------- | ||
// ES2020 | ||
//-------------------------------------------------------------------------- | ||
bigint: { | ||
ruleId: "no-bigint", | ||
cases: [ | ||
{ | ||
supported: "10.4.0", | ||
test: info => info.node.type === "Literal", | ||
messageId: "no-bigint", | ||
}, | ||
{ | ||
supported: null, | ||
test: ({ node }) => | ||
node.type === "Literal" && | ||
(node.parent.type === "Property" || | ||
node.parent.type === "MethodDefinition") && | ||
!node.parent.computed && | ||
node.parent.key === node, | ||
messageId: "no-bigint-property-names", | ||
}, | ||
], | ||
}, | ||
dynamicImport: { | ||
ruleId: "no-dynamic-import", | ||
cases: [ | ||
{ | ||
supported: null, | ||
messageId: "no-dynamic-import", | ||
}, | ||
], | ||
}, | ||
} | ||
@@ -377,3 +411,3 @@ const keywords = Object.keys(features) | ||
*/ | ||
function nomalizeScope(initialScope, node) { | ||
function normalizeScope(initialScope, node) { | ||
let scope = getInnermostScope(initialScope, node) | ||
@@ -389,37 +423,2 @@ | ||
/** | ||
* Merge two visitors. | ||
* @param {Visitor} x The visitor which is assigned. | ||
* @param {Visitor} y The visitor which is assigning. | ||
* @returns {Visitor} `x`. | ||
*/ | ||
function merge(x, y) { | ||
for (const key of Object.keys(y)) { | ||
if (typeof x[key] === "function") { | ||
if (x[key]._handlers == null) { | ||
const fs = [x[key], y[key]] | ||
x[key] = dispatch.bind(null, fs) | ||
x[key]._handlers = fs | ||
} else { | ||
x[key]._handlers.push(y[key]) | ||
} | ||
} else { | ||
x[key] = y[key] | ||
} | ||
} | ||
return x | ||
} | ||
/** | ||
* Dispatch all given functions with a node. | ||
* @param {function[]} handlers The function list to call. | ||
* @param {Node} node The AST node to be handled. | ||
* @returns {void} | ||
*/ | ||
function dispatch(handlers, node) { | ||
for (const h of handlers) { | ||
h(node) | ||
} | ||
} | ||
/** | ||
* Define the visitor object as merging the rules of eslint-plugin-es. | ||
@@ -433,3 +432,3 @@ * @param {RuleContext} context The rule context. | ||
get isStrict() { | ||
return nomalizeScope(context.getScope(), this.node).isStrict | ||
return normalizeScope(context.getScope(), this.node).isStrict | ||
}, | ||
@@ -499,3 +498,3 @@ } | ||
} | ||
return merge(visitor, rule.create(thisContext)) | ||
return mergeVisitorsInPlace(visitor, rule.create(thisContext)) | ||
}, {}) | ||
@@ -513,4 +512,5 @@ ) | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/no-unsupported-features/es-syntax.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-unsupported-features/es-syntax.md", | ||
}, | ||
type: "problem", | ||
fixable: null, | ||
@@ -629,2 +629,12 @@ schema: [ | ||
"The omission of 'catch' binding is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.", | ||
//------------------------------------------------------------------ | ||
// ES2020 | ||
//------------------------------------------------------------------ | ||
"no-bigint": | ||
"Bigint literals are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.", | ||
"no-bigint-property-names": | ||
"Bigint literal property names are not supported yet.", | ||
"no-dynamic-import": | ||
"'import()' expressions are not supported yet.", | ||
}, | ||
@@ -631,0 +641,0 @@ }, |
@@ -14,2 +14,5 @@ /** | ||
globals: { | ||
queueMicrotask: { | ||
[READ]: { supported: "12.0.0", experimental: "11.0.0" }, | ||
}, | ||
require: { | ||
@@ -24,3 +27,3 @@ resolve: { | ||
strict: { | ||
[READ]: { supported: "9.9.0" }, | ||
[READ]: { supported: "9.9.0", backported: ["8.13.0"] }, | ||
doesNotReject: { [READ]: { supported: "10.0.0" } }, | ||
@@ -53,5 +56,7 @@ rejects: { [READ]: { supported: "10.0.0" } }, | ||
console: { | ||
clear: { [READ]: { supported: "8.3.0" } }, | ||
count: { [READ]: { supported: "8.3.0" } }, | ||
countReset: { [READ]: { supported: "8.3.0" } }, | ||
clear: { [READ]: { supported: "8.3.0", backported: ["6.13.0"] } }, | ||
count: { [READ]: { supported: "8.3.0", backported: ["6.13.0"] } }, | ||
countReset: { | ||
[READ]: { supported: "8.3.0", backported: ["6.13.0"] }, | ||
}, | ||
debug: { [READ]: { supported: "8.0.0" } }, | ||
@@ -66,2 +71,3 @@ dirxml: { [READ]: { supported: "8.0.0" } }, | ||
profileEnd: { [READ]: { supported: "8.0.0" } }, | ||
timeLog: { [READ]: { supported: "10.7.0" } }, | ||
timeStamp: { [READ]: { supported: "8.0.0" } }, | ||
@@ -77,4 +83,11 @@ timeline: { [READ]: { supported: "8.0.0" } }, | ||
}, | ||
ECDH: { [READ]: { supported: "8.8.0", backported: ["6.13.0"] } }, | ||
KeyObject: { [READ]: { supported: "11.6.0" } }, | ||
createPrivateKey: { [READ]: { supported: "11.6.0" } }, | ||
createPublicKey: { [READ]: { supported: "11.6.0" } }, | ||
createSecretKey: { [READ]: { supported: "11.6.0" } }, | ||
constants: { [READ]: { supported: "6.3.0" } }, | ||
fips: { [READ]: { supported: "6.0.0" } }, | ||
generateKeyPair: { [READ]: { supported: "10.12.0" } }, | ||
generateKeyPairSync: { [READ]: { supported: "10.12.0" } }, | ||
getCurves: { [READ]: { supported: "2.3.0" } }, | ||
@@ -84,8 +97,14 @@ getFips: { [READ]: { supported: "10.0.0" } }, | ||
publicDecrypt: { [READ]: { supported: "1.1.0" } }, | ||
randomFillSync: { [READ]: { supported: "7.10.0" } }, | ||
randomFill: { [READ]: { supported: "7.10.0" } }, | ||
randomFillSync: { | ||
[READ]: { supported: "7.10.0", backported: ["6.13.0"] }, | ||
}, | ||
randomFill: { | ||
[READ]: { supported: "7.10.0", backported: ["6.13.0"] }, | ||
}, | ||
scrypt: { [READ]: { supported: "10.5.0" } }, | ||
scryptSync: { [READ]: { supported: "10.5.0" } }, | ||
setFips: { [READ]: { supported: "10.0.0" } }, | ||
sign: { [READ]: { supported: "12.0.0" } }, | ||
timingSafeEqual: { [READ]: { supported: "6.6.0" } }, | ||
verify: { [READ]: { supported: "12.0.0" } }, | ||
}, | ||
@@ -96,6 +115,19 @@ dns: { | ||
promises: { | ||
[READ]: { supported: "10.6.0" }, | ||
[READ]: { | ||
supported: "11.14.0", | ||
backported: ["10.17.0"], | ||
experimental: "10.6.0", | ||
}, | ||
}, | ||
}, | ||
events: { | ||
EventEmitter: { | ||
once: { | ||
[READ]: { supported: "11.13.0", backported: ["10.16.0"] }, | ||
}, | ||
}, | ||
once: { [READ]: { supported: "11.13.0", backported: ["10.16.0"] } }, | ||
}, | ||
fs: { | ||
Dirent: { [READ]: { supported: "10.10.0" } }, | ||
copyFile: { [READ]: { supported: "8.5.0" } }, | ||
@@ -112,17 +144,51 @@ copyFileSync: { [READ]: { supported: "8.5.0" } }, | ||
promises: { | ||
[READ]: { supported: "10.1.0" }, | ||
[READ]: { | ||
supported: "11.14.0", | ||
backported: ["10.17.0"], | ||
experimental: "10.1.0", | ||
}, | ||
}, | ||
writev: { [READ]: { supported: "12.9.0" } }, | ||
writevSync: { [READ]: { supported: "12.9.0" } }, | ||
}, | ||
http2: { | ||
[READ]: { supported: "8.4.0" }, | ||
[READ]: { | ||
supported: "10.10.0", | ||
backported: ["8.13.0"], | ||
experimental: "8.4.0", | ||
}, | ||
}, | ||
inspector: { | ||
[READ]: { supported: "8.0.0" }, | ||
[READ]: { supported: null, experimental: "8.0.0" }, | ||
}, | ||
module: { | ||
builtinModules: { [READ]: { supported: "9.3.0" } }, | ||
Module: { | ||
builtinModules: { | ||
[READ]: { | ||
supported: "9.3.0", | ||
backported: ["6.13.0", "8.10.0"], | ||
}, | ||
}, | ||
createRequireFromPath: { [READ]: { supported: "10.12.0" } }, | ||
createRequire: { [READ]: { supported: "12.2.0" } }, | ||
syncBuiltinESMExports: { [READ]: { supported: "12.12.0" } }, | ||
}, | ||
builtinModules: { | ||
[READ]: { | ||
supported: "9.3.0", | ||
backported: ["6.13.0", "8.10.0"], | ||
}, | ||
}, | ||
createRequireFromPath: { [READ]: { supported: "10.12.0" } }, | ||
createRequire: { [READ]: { supported: "12.2.0" } }, | ||
syncBuiltinESMExports: { [READ]: { supported: "12.12.0" } }, | ||
}, | ||
os: { | ||
constants: { [READ]: { supported: "6.3.0" } }, | ||
constants: { | ||
[READ]: { supported: "6.3.0" }, | ||
priority: { [READ]: { supported: "10.10.0" } }, | ||
}, | ||
getPriority: { [READ]: { supported: "10.10.0" } }, | ||
homedir: { [READ]: { supported: "2.3.0" } }, | ||
setPriority: { [READ]: { supported: "10.10.0" } }, | ||
userInfo: { [READ]: { supported: "6.0.0" } }, | ||
@@ -135,4 +201,6 @@ }, | ||
[READ]: { supported: "8.5.0" }, | ||
monitorEventLoopDelay: { [READ]: { supported: "11.10.0" } }, | ||
}, | ||
process: { | ||
allowedNodeEnvironmentFlags: { [READ]: { supported: "10.10.0" } }, | ||
argv0: { [READ]: { supported: "6.4.0" } }, | ||
@@ -147,4 +215,14 @@ channel: { [READ]: { supported: "7.1.0" } }, | ||
}, | ||
ppid: { [READ]: { supported: "9.2.0" } }, | ||
hrtime: { | ||
bigint: { [READ]: { supported: "10.7.0" } }, | ||
}, | ||
ppid: { | ||
[READ]: { | ||
supported: "9.2.0", | ||
backported: ["6.13.0", "8.10.0"], | ||
}, | ||
}, | ||
release: { [READ]: { supported: "3.0.0" } }, | ||
report: { [READ]: { supported: null, experimental: "11.8.0" } }, | ||
resourceUsage: { [READ]: { supported: "12.6.0" } }, | ||
setegid: { [READ]: { supported: "2.0.0" } }, | ||
@@ -155,4 +233,17 @@ seteuid: { [READ]: { supported: "2.0.0" } }, | ||
}, | ||
stdout: { | ||
getColorDepth: { [READ]: { supported: "9.9.0" } }, | ||
hasColor: { [READ]: { supported: "11.13.0" } }, | ||
}, | ||
stderr: { | ||
getColorDepth: { [READ]: { supported: "9.9.0" } }, | ||
hasColor: { [READ]: { supported: "11.13.0" } }, | ||
}, | ||
}, | ||
stream: { | ||
Readable: { | ||
from: { | ||
[READ]: { supported: "12.3.0", backported: ["10.17.0"] }, | ||
}, | ||
}, | ||
finished: { [READ]: { supported: "10.0.0" } }, | ||
@@ -165,4 +256,6 @@ pipeline: { [READ]: { supported: "10.0.0" } }, | ||
url: { | ||
URL: { [READ]: { supported: "7.0.0" } }, | ||
URLSearchParams: { [READ]: { supported: "7.5.0" } }, | ||
URL: { [READ]: { supported: "7.0.0", backported: ["6.13.0"] } }, | ||
URLSearchParams: { | ||
[READ]: { supported: "7.5.0", backported: ["6.13.0"] }, | ||
}, | ||
domainToASCII: { [READ]: { supported: "7.4.0" } }, | ||
@@ -174,13 +267,21 @@ domainToUnicode: { [READ]: { supported: "7.4.0" } }, | ||
formatWithOptions: { [READ]: { supported: "10.0.0" } }, | ||
getSystemErrorName: { [READ]: { supported: "9.7.0" } }, | ||
getSystemErrorName: { | ||
[READ]: { supported: "9.7.0", backported: ["8.12.0"] }, | ||
}, | ||
inspect: { | ||
custom: { [READ]: { supported: "6.6.0" } }, | ||
defaultOptions: { [READ]: { supported: "6.4.0" } }, | ||
replDefaults: { [READ]: { supported: "11.12.0" } }, | ||
}, | ||
isDeepStrictEqual: { [READ]: { supported: "9.0.0" } }, | ||
promisify: { [READ]: { supported: "8.0.0" } }, | ||
TextDecoder: { [READ]: { supported: "8.3.0" } }, | ||
TextEncoder: { [READ]: { supported: "8.3.0" } }, | ||
TextDecoder: { | ||
[READ]: { supported: "8.9.0", experimental: "8.3.0" }, | ||
}, | ||
TextEncoder: { | ||
[READ]: { supported: "8.9.0", experimental: "8.3.0" }, | ||
}, | ||
types: { | ||
[READ]: { supported: "10.0.0" }, | ||
isBoxedPrimitive: { [READ]: { supported: "10.11.0" } }, | ||
}, | ||
@@ -190,16 +291,20 @@ }, | ||
[READ]: { supported: "1.0.0" }, | ||
DefaultDeserializer: { [READ]: { supported: "8.0.0" } }, | ||
DefaultSerializer: { [READ]: { supported: "8.0.0" } }, | ||
Deserializer: { [READ]: { supported: "8.0.0" } }, | ||
Serializer: { [READ]: { supported: "8.0.0" } }, | ||
cachedDataVersionTag: { [READ]: { supported: "8.0.0" } }, | ||
deserialize: { [READ]: { supported: "8.0.0" } }, | ||
getHeapCodeStatistics: { [READ]: { supported: "12.8.0" } }, | ||
getHeapSnapshot: { [READ]: { supported: "11.13.0" } }, | ||
getHeapSpaceStatistics: { [READ]: { supported: "6.0.0" } }, | ||
serialize: { [READ]: { supported: "8.0.0" } }, | ||
deserialize: { [READ]: { supported: "8.0.0" } }, | ||
Serializer: { [READ]: { supported: "8.0.0" } }, | ||
Deserializer: { [READ]: { supported: "8.0.0" } }, | ||
DefaultSerializer: { [READ]: { supported: "8.0.0" } }, | ||
DefaultDeserializer: { [READ]: { supported: "8.0.0" } }, | ||
writeHeapSnapshot: { [READ]: { supported: "11.13.0" } }, | ||
}, | ||
vm: { | ||
Module: { [READ]: { supported: "9.6.0" } }, | ||
compileFunction: { [READ]: { supported: "10.10.0" } }, | ||
}, | ||
worker_threads: { | ||
[READ]: { supported: "10.5.0" }, | ||
[READ]: { supported: "12.11.0", experimental: "10.5.0" }, | ||
}, | ||
@@ -210,8 +315,18 @@ }, | ||
Buffer: trackMap.modules.buffer.Buffer, | ||
URL: Object.assign({}, trackMap.modules.url.URL, { | ||
TextDecoder: { | ||
...trackMap.modules.util.TextDecoder, | ||
[READ]: { supported: "11.0.0" }, | ||
}, | ||
TextEncoder: { | ||
...trackMap.modules.util.TextEncoder, | ||
[READ]: { supported: "11.0.0" }, | ||
}, | ||
URL: { | ||
...trackMap.modules.url.URL, | ||
[READ]: { supported: "10.0.0" }, | ||
}), | ||
URLSearchParams: Object.assign({}, trackMap.modules.url.URLSearchParams, { | ||
}, | ||
URLSearchParams: { | ||
...trackMap.modules.url.URLSearchParams, | ||
[READ]: { supported: "10.0.0" }, | ||
}), | ||
}, | ||
console: trackMap.modules.console, | ||
@@ -230,4 +345,5 @@ process: trackMap.modules.process, | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/no-unsupported-features/node-builtins.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-unsupported-features/node-builtins.md", | ||
}, | ||
type: "problem", | ||
fixable: null, | ||
@@ -234,0 +350,0 @@ schema: [ |
@@ -29,4 +29,5 @@ /** | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/prefer-global/buffer.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/prefer-global/buffer.md", | ||
}, | ||
type: "suggestion", | ||
fixable: null, | ||
@@ -33,0 +34,0 @@ schema: [{ enum: ["always", "never"] }], |
@@ -26,4 +26,5 @@ /** | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/prefer-global/console.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/prefer-global/console.md", | ||
}, | ||
type: "suggestion", | ||
fixable: null, | ||
@@ -30,0 +31,0 @@ schema: [{ enum: ["always", "never"] }], |
@@ -26,4 +26,5 @@ /** | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/prefer-global/process.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/prefer-global/process.md", | ||
}, | ||
type: "suggestion", | ||
fixable: null, | ||
@@ -30,0 +31,0 @@ schema: [{ enum: ["always", "never"] }], |
@@ -29,4 +29,5 @@ /** | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/prefer-global/url-search-params.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/prefer-global/url-search-params.md", | ||
}, | ||
type: "suggestion", | ||
fixable: null, | ||
@@ -33,0 +34,0 @@ schema: [{ enum: ["always", "never"] }], |
@@ -28,4 +28,5 @@ /** | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/prefer-global/url.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/prefer-global/url.md", | ||
}, | ||
type: "suggestion", | ||
fixable: null, | ||
@@ -32,0 +33,0 @@ schema: [{ enum: ["always", "never"] }], |
@@ -8,8 +8,13 @@ /** | ||
const CodePathAnalyzer = safeRequire( | ||
"eslint/lib/linter/code-path-analysis/code-path-analyzer", | ||
"eslint/lib/code-path-analysis/code-path-analyzer" | ||
) | ||
const CodePath = safeRequire("eslint/lib/code-path-analysis/code-path") | ||
const CodePathSegment = safeRequire( | ||
"eslint/lib/linter/code-path-analysis/code-path-segment", | ||
"eslint/lib/code-path-analysis/code-path-segment" | ||
) | ||
const CodePath = safeRequire( | ||
"eslint/lib/linter/code-path-analysis/code-path", | ||
"eslint/lib/code-path-analysis/code-path" | ||
) | ||
@@ -21,12 +26,14 @@ const originalLeaveNode = | ||
* Imports a specific module. | ||
* | ||
* @param {string} moduleName - A module name to import. | ||
* @param {...string} moduleNames - module names to import. | ||
* @returns {object|null} The imported object, or null. | ||
*/ | ||
function safeRequire(moduleName) { | ||
try { | ||
return require(moduleName) | ||
} catch (_err) { | ||
return null | ||
function safeRequire(...moduleNames) { | ||
for (const moduleName of moduleNames) { | ||
try { | ||
return require(moduleName) | ||
} catch (_err) { | ||
// Ignore. | ||
} | ||
} | ||
return null | ||
} | ||
@@ -149,4 +156,5 @@ | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/process-exit-as-throw.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/process-exit-as-throw.md", | ||
}, | ||
type: "problem", | ||
fixable: null, | ||
@@ -153,0 +161,0 @@ schema: [], |
@@ -12,5 +12,14 @@ /** | ||
const NODE_SHEBANG = "#!/usr/bin/env node\n" | ||
const SHEBANG_PATTERN = /^(#!.+?)?(\r)?\n/ | ||
const NODE_SHEBANG_PATTERN = /#!\/usr\/bin\/env node(?: [^\r\n]+?)?\n/ | ||
const SHEBANG_PATTERN = /^(#!.+?)?(\r)?\n/u | ||
const NODE_SHEBANG_PATTERN = /#!\/usr\/bin\/env node(?: [^\r\n]+?)?\n/u | ||
function simulateNodeResolutionAlgorithm(filePath, binField) { | ||
const possibilities = [filePath] | ||
let newFilePath = filePath.replace(/\.js$/u, "") | ||
possibilities.push(newFilePath) | ||
newFilePath = newFilePath.replace(/[/\\]index$/u, "") | ||
possibilities.push(newFilePath) | ||
return possibilities.includes(binField) | ||
} | ||
/** | ||
@@ -29,6 +38,12 @@ * Checks whether or not a given path is a `bin` file. | ||
if (typeof binField === "string") { | ||
return filePath === path.resolve(basedir, binField) | ||
return simulateNodeResolutionAlgorithm( | ||
filePath, | ||
path.resolve(basedir, binField) | ||
) | ||
} | ||
return Object.keys(binField).some( | ||
key => filePath === path.resolve(basedir, binField[key]) | ||
return Object.keys(binField).some(key => | ||
simulateNodeResolutionAlgorithm( | ||
filePath, | ||
path.resolve(basedir, binField[key]) | ||
) | ||
) | ||
@@ -59,8 +74,9 @@ } | ||
docs: { | ||
description: "enforce the correct usage of shebang", | ||
description: "suggest correct usage of shebang", | ||
category: "Possible Errors", | ||
recommended: true, | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v7.0.1/docs/rules/shebang.md", | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/shebang.md", | ||
}, | ||
type: "problem", | ||
fixable: "code", | ||
@@ -95,3 +111,3 @@ schema: [ | ||
getConvertPath(context)( | ||
path.relative(basedir, filePath).replace(/\\/g, "/") | ||
path.relative(basedir, filePath).replace(/\\/gu, "/") | ||
) | ||
@@ -98,0 +114,0 @@ ) |
@@ -32,5 +32,5 @@ /** | ||
const basedir = path.dirname(packageInfo.filePath) | ||
// eslint-disable-next-line func-style, require-jsdoc | ||
// eslint-disable-next-line func-style | ||
const toRelative = fullPath => { | ||
const retv = path.relative(basedir, fullPath).replace(/\\/g, "/") | ||
const retv = path.relative(basedir, fullPath).replace(/\\/gu, "/") | ||
return convertPath(retv) | ||
@@ -37,0 +37,0 @@ } |
@@ -7,3 +7,3 @@ /** | ||
const { Range } = require("semver") //eslint-disable-line no-unused-vars | ||
const { Range, lt, major } = require("semver") //eslint-disable-line no-unused-vars | ||
const { ReferenceTracker } = require("eslint-utils") | ||
@@ -14,2 +14,9 @@ const getConfiguredNodeVersion = require("./get-configured-node-version") | ||
/** | ||
* @typedef {Object} SupportInfo | ||
* @property {string | null} supported The stably supported version. If `null` is present, it hasn't been supported yet. | ||
* @property {string[]} [backported] The backported versions. | ||
* @property {string} [experimental] The added version as experimental. | ||
*/ | ||
/** | ||
* Parses the options. | ||
@@ -29,2 +36,46 @@ * @param {RuleContext} context The rule context. | ||
/** | ||
* Check if it has been supported. | ||
* @param {SupportInfo} info The support info. | ||
* @param {Range} configured The configured version range. | ||
*/ | ||
function isSupported({ backported, supported }, configured) { | ||
if ( | ||
backported && | ||
backported.length >= 2 && | ||
!backported.every((v, i) => i === 0 || lt(backported[i - 1], v)) | ||
) { | ||
throw new Error("Invalid BackportConfiguration") | ||
} | ||
if (supported == null) { | ||
return false | ||
} | ||
if (backported == null || backported.length === 0) { | ||
return !configured.intersects(getSemverRange(`<${supported}`)) | ||
} | ||
return !configured.intersects( | ||
getSemverRange( | ||
[...backported, supported] | ||
.map((v, i) => (i === 0 ? `<${v}` : `>=${major(v)}.0.0 <${v}`)) | ||
.join(" || ") | ||
) | ||
) | ||
} | ||
/** | ||
* Get the formatted text of a given supported version. | ||
* @param {SupportInfo} info The support info. | ||
*/ | ||
function supportedVersionToString({ backported, supported }) { | ||
if (supported == null) { | ||
return "(none yet)" | ||
} | ||
if (backported == null || backported.length === 0) { | ||
return supported | ||
} | ||
return `${supported} (backported: ^${backported.join(", ^")})` | ||
} | ||
/** | ||
* Verify the code to report unsupported APIs. | ||
@@ -37,5 +88,3 @@ * @param {RuleContext} context The rule context. | ||
const options = parseOptions(context) | ||
const tracker = new ReferenceTracker(context.getScope(), { | ||
mode: "legacy", | ||
}) | ||
const tracker = new ReferenceTracker(context.getScope(), { mode: "legacy" }) | ||
const references = [ | ||
@@ -49,7 +98,5 @@ ...tracker.iterateCjsReferences(trackMap.modules || {}), | ||
const name = path.join(".") | ||
const supported = options.version.intersects( | ||
getSemverRange(`<${info.supported}`) | ||
) | ||
const supported = isSupported(info, options.version) | ||
if (supported && !options.ignores.has(name)) { | ||
if (!supported && !options.ignores.has(name)) { | ||
context.report({ | ||
@@ -60,3 +107,3 @@ node, | ||
name, | ||
supported: info.supported, | ||
supported: supportedVersionToString(info), | ||
version: options.version.raw, | ||
@@ -63,0 +110,0 @@ }, |
@@ -11,3 +11,3 @@ /** | ||
const ROOT = /^(?:[/.]|\.\.|[A-Z]:\\|\\\\)(?:[/\\]\.\.)*$/ | ||
const ROOT = /^(?:[/.]|\.\.|[A-Z]:\\|\\\\)(?:[/\\]\.\.)*$/u | ||
const cache = new Cache() | ||
@@ -14,0 +14,0 @@ |
@@ -26,3 +26,3 @@ /** | ||
* 2. Look package.json up and parse `engines.node` then return it if it's valid. | ||
* 3. Return `>=6.0.0`. | ||
* 3. Return `>=8.0.0`. | ||
* | ||
@@ -38,4 +38,4 @@ * @param {string|undefined} version The version range text. | ||
getEnginesNode(filename) || | ||
getSemverRange(">=6.0.0") | ||
getSemverRange(">=8.0.0") | ||
) | ||
} |
@@ -112,3 +112,3 @@ /** | ||
const exclude = toStringArray(pattern.exclude) | ||
const fromRegexp = new RegExp(String(pattern.replace[0])) | ||
const fromRegexp = new RegExp(String(pattern.replace[0])) //eslint-disable-line require-unicode-regexp | ||
const toStr = String(pattern.replace[1]) | ||
@@ -115,0 +115,0 @@ |
@@ -15,5 +15,5 @@ /** | ||
const cache = new Cache() | ||
const SLASH_AT_BEGIN_AND_END = /^!?\/+|^!|\/+$/g | ||
const PARENT_RELATIVE_PATH = /^\.\./ | ||
const NEVER_IGNORED = /^(?:readme\.[^.]*|(?:licen[cs]e|changes|changelog|history)(?:\.[^.]*)?)$/i | ||
const SLASH_AT_BEGIN_AND_END = /^!?\/+|^!|\/+$/gu | ||
const PARENT_RELATIVE_PATH = /^\.\./u | ||
const NEVER_IGNORED = /^(?:readme\.[^.]*|(?:licen[cs]e|changes|changelog|history)(?:\.[^.]*)?)$/iu | ||
@@ -28,3 +28,3 @@ /** | ||
*/ | ||
function notAncestorFiles(filePath) { | ||
function isAncestorFiles(filePath) { | ||
return PARENT_RELATIVE_PATH.test(filePath) | ||
@@ -89,14 +89,22 @@ } | ||
const ig = ignore() | ||
ig.add("*") | ||
const igN = ignore() | ||
let hasN = false | ||
for (const file of files) { | ||
if (typeof file === "string" && file) { | ||
const prefix = file.startsWith("!") ? "" : "!" | ||
const body = file.replace(SLASH_AT_BEGIN_AND_END, "") | ||
ig.add(`${prefix}/${body}`) | ||
ig.add(`${prefix}/${body}/**`) | ||
if (file.startsWith("!")) { | ||
igN.add(`${body}`) | ||
igN.add(`${body}/**`) | ||
hasN = true | ||
} else { | ||
ig.add(`/${body}`) | ||
ig.add(`/${body}/**`) | ||
} | ||
} | ||
} | ||
return not(ig.createFilter()) | ||
return hasN | ||
? or(ig.createFilter(), not(igN.createFilter())) | ||
: ig.createFilter() | ||
} | ||
@@ -130,3 +138,3 @@ | ||
/** | ||
* Gets an object to check whether or not a given path should be ignored. | ||
* Gets an object to check whether a given path should be ignored or not. | ||
* The object is created from: | ||
@@ -144,3 +152,3 @@ * | ||
module.exports = function getNpmignore(startPath) { | ||
const retv = { match: notAncestorFiles } | ||
const retv = { match: isAncestorFiles } | ||
@@ -163,3 +171,3 @@ const p = getPackageJson(startPath) | ||
filterNeverIgnoredFiles(p), | ||
or(notAncestorFiles, filesIgnore, npmignoreIgnore) | ||
or(isAncestorFiles, filesIgnore, npmignoreIgnore) | ||
) | ||
@@ -169,3 +177,3 @@ } else if (filesIgnore) { | ||
filterNeverIgnoredFiles(p), | ||
or(notAncestorFiles, filesIgnore) | ||
or(isAncestorFiles, filesIgnore) | ||
) | ||
@@ -175,3 +183,3 @@ } else if (npmignoreIgnore) { | ||
filterNeverIgnoredFiles(p), | ||
or(notAncestorFiles, npmignoreIgnore) | ||
or(isAncestorFiles, npmignoreIgnore) | ||
) | ||
@@ -178,0 +186,0 @@ } |
@@ -42,7 +42,7 @@ /** | ||
* | ||
* @param {string} startPath - A file path to lookup. | ||
* @param {string} [startPath] - A file path to lookup. | ||
* @returns {object|null} A found `package.json` data or `null`. | ||
* This object have additional property `filePath`. | ||
*/ | ||
module.exports = function getPackageJson(startPath) { | ||
module.exports = function getPackageJson(startPath = "a.js") { | ||
const startDir = path.dirname(path.resolve(startPath)) | ||
@@ -49,0 +49,0 @@ let dir = startDir |
@@ -32,5 +32,5 @@ /** | ||
*/ | ||
module.exports = function getResolvePaths(context) { | ||
module.exports = function getResolvePaths(context, optionIndex = 0) { | ||
return ( | ||
get(context.options && context.options[0]) || | ||
get(context.options && context.options[optionIndex]) || | ||
get(context.settings && context.settings.node) || | ||
@@ -37,0 +37,0 @@ DEFAULT_VALUE |
@@ -32,5 +32,5 @@ /** | ||
*/ | ||
module.exports = function getTryExtensions(context) { | ||
module.exports = function getTryExtensions(context, optionIndex = 0) { | ||
return ( | ||
get(context.options && context.options[0]) || | ||
get(context.options && context.options[optionIndex]) || | ||
get(context.settings && context.settings.node) || | ||
@@ -37,0 +37,0 @@ DEFAULT_VALUE |
@@ -57,3 +57,3 @@ /** | ||
constructor(node, name, options) { | ||
const isModule = !/^(?:[./\\]|\w+:)/.test(name) | ||
const isModule = !/^(?:[./\\]|\w+:)/u.test(name) | ||
@@ -60,0 +60,0 @@ /** |
{ | ||
"name": "eslint-plugin-node", | ||
"version": "7.0.1", | ||
"version": "11.1.0", | ||
"description": "Additional ESLint's rules for Node.js", | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=8.10.0" | ||
}, | ||
@@ -13,30 +13,36 @@ "main": "lib/index.js", | ||
"peerDependencies": { | ||
"eslint": ">=4.19.1" | ||
"eslint": ">=5.16.0" | ||
}, | ||
"dependencies": { | ||
"eslint-plugin-es": "^1.3.1", | ||
"eslint-utils": "^1.3.1", | ||
"ignore": "^4.0.2", | ||
"eslint-plugin-es": "^3.0.0", | ||
"eslint-utils": "^2.0.0", | ||
"ignore": "^5.1.1", | ||
"minimatch": "^3.0.4", | ||
"resolve": "^1.8.1", | ||
"semver": "^5.5.0" | ||
"resolve": "^1.10.1", | ||
"semver": "^6.1.0" | ||
}, | ||
"devDependencies": { | ||
"@mysticatea/eslint-plugin": "^5.1.0", | ||
"codecov": "^3.0.4", | ||
"eslint": "^5.1.0", | ||
"fast-glob": "^2.2.2", | ||
"mocha": "^5.2.0", | ||
"nyc": "^12.0.2", | ||
"opener": "^1.4.3", | ||
"rimraf": "^2.6.1" | ||
"@mysticatea/eslint-plugin": "^10.0.3", | ||
"codecov": "^3.3.0", | ||
"eslint": "^6.3.0", | ||
"eslint-plugin-node": "file:.", | ||
"fast-glob": "^2.2.6", | ||
"globals": "^11.12.0", | ||
"mocha": "^6.1.4", | ||
"nyc": "^14.0.0", | ||
"opener": "^1.5.1", | ||
"punycode": "^2.1.1", | ||
"rimraf": "^2.6.3" | ||
}, | ||
"scripts": { | ||
"build": "node scripts/update.js", | ||
"build": "node scripts/update", | ||
"clean": "rimraf .nyc_output coverage", | ||
"codecov": "nyc report -r lcovonly && codecov", | ||
"coverage": "nyc report -r lcov && opener ./coverage/lcov-report/index.html", | ||
"codecov": "nyc report --reporter text-lcov | codecov --pipe --disable=gcov -t $CODECOV_TOKEN", | ||
"coverage": "opener ./coverage/lcov-report/index.html", | ||
"lint": "eslint lib scripts tests/lib .eslintrc.js", | ||
"new": "node scripts/new-rule", | ||
"pretest": "npm run -s lint", | ||
"test": "nyc npm run -s test:_mocha", | ||
"test:_mocha": "_mocha tests/lib/**/*.js --reporter progress", | ||
"test:ci": "nyc npm run -s test:_mocha", | ||
"test:_mocha": "_mocha \"tests/lib/**/*.js\" --reporter progress --timeout 4000", | ||
"preversion": "npm t && npm run -s build", | ||
@@ -43,0 +49,0 @@ "version": "eslint lib/rules --fix && git add lib/rules", |
@@ -5,3 +5,3 @@ # eslint-plugin-node | ||
[![Downloads/month](https://img.shields.io/npm/dm/eslint-plugin-node.svg)](http://www.npmtrends.com/eslint-plugin-node) | ||
[![Build Status](https://travis-ci.org/mysticatea/eslint-plugin-node.svg?branch=master)](https://travis-ci.org/mysticatea/eslint-plugin-node) | ||
[![Build Status](https://github.com/mysticatea/eslint-plugin-node/workflows/CI/badge.svg)](https://github.com/mysticatea/eslint-plugin-node/actions) | ||
[![Coverage Status](https://codecov.io/gh/mysticatea/eslint-plugin-node/branch/master/graph/badge.svg)](https://codecov.io/gh/mysticatea/eslint-plugin-node) | ||
@@ -18,4 +18,4 @@ [![Dependency Status](https://david-dm.org/mysticatea/eslint-plugin-node.svg)](https://david-dm.org/mysticatea/eslint-plugin-node) | ||
- Requires Node.js `>=6.0.0` | ||
- Requires ESLint `>=4.19.1` (`plugin:node/recommended` preset requires `>=5.0.0`) | ||
- Requires Node.js `>=8.10.0` | ||
- Requires ESLint `>=5.16.0` | ||
@@ -26,7 +26,15 @@ **Note:** It recommends a use of [the "engines" field of package.json](https://docs.npmjs.com/files/package.json#engines). The "engines" field is used by `node/no-unsupported-features/*` rules. | ||
```json | ||
```jsonc | ||
{ | ||
"extends": ["eslint:recommended", "plugin:node/recommended"], | ||
"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"], | ||
@@ -37,2 +45,4 @@ "node/prefer-global/console": ["error", "always"], | ||
"node/prefer-global/url": ["error", "always"], | ||
"node/prefer-promises/dns": "error", | ||
"node/prefer-promises/fs": "error" | ||
} | ||
@@ -48,4 +58,5 @@ } | ||
"version": "1.0.0", | ||
"type": "commonjs", | ||
"engines": { | ||
"node": ">=6.0.0" | ||
"node": ">=8.10.0" | ||
} | ||
@@ -65,9 +76,11 @@ } | ||
|:--------|:------------|:--:| | ||
| [node/no-extraneous-import](./docs/rules/no-extraneous-import.md) | disallow `import` declarations of extraneous packages | | | ||
| [node/no-extraneous-require](./docs/rules/no-extraneous-require.md) | disallow `require()` expressions of extraneous packages | ⭐️ | | ||
| [node/no-missing-import](./docs/rules/no-missing-import.md) | disallow `import` declarations of missing files | | | ||
| [node/no-missing-require](./docs/rules/no-missing-require.md) | disallow `require()` expressions of missing files | ⭐️ | | ||
| [node/no-unpublished-bin](./docs/rules/no-unpublished-bin.md) | disallow 'bin' files which are ignored by npm | ⭐️ | | ||
| [node/no-unpublished-import](./docs/rules/no-unpublished-import.md) | disallow `import` declarations of private things | | | ||
| [node/no-unpublished-require](./docs/rules/no-unpublished-require.md) | disallow `require()` expressions of private things | ⭐️ | | ||
| [node/no-callback-literal](./docs/rules/no-callback-literal.md) | ensure Node.js-style error-first callback pattern is followed | | | ||
| [node/no-exports-assign](./docs/rules/no-exports-assign.md) | disallow the assignment to `exports` | ⭐️ | | ||
| [node/no-extraneous-import](./docs/rules/no-extraneous-import.md) | disallow `import` declarations which import extraneous modules | ⭐️ | | ||
| [node/no-extraneous-require](./docs/rules/no-extraneous-require.md) | disallow `require()` expressions which import extraneous modules | ⭐️ | | ||
| [node/no-missing-import](./docs/rules/no-missing-import.md) | disallow `import` declarations which import non-existence modules | ⭐️ | | ||
| [node/no-missing-require](./docs/rules/no-missing-require.md) | disallow `require()` expressions which import non-existence modules | ⭐️ | | ||
| [node/no-unpublished-bin](./docs/rules/no-unpublished-bin.md) | disallow `bin` files that npm ignores | ⭐️ | | ||
| [node/no-unpublished-import](./docs/rules/no-unpublished-import.md) | disallow `import` declarations which import private modules | ⭐️ | | ||
| [node/no-unpublished-require](./docs/rules/no-unpublished-require.md) | disallow `require()` expressions which import private modules | ⭐️ | | ||
| [node/no-unsupported-features/es-builtins](./docs/rules/no-unsupported-features/es-builtins.md) | disallow unsupported ECMAScript built-ins on the specified version | ⭐️ | | ||
@@ -77,3 +90,3 @@ | [node/no-unsupported-features/es-syntax](./docs/rules/no-unsupported-features/es-syntax.md) | disallow unsupported ECMAScript syntax on the specified version | ⭐️ | | ||
| [node/process-exit-as-throw](./docs/rules/process-exit-as-throw.md) | make `process.exit()` expressions the same code path as `throw` | ⭐️ | | ||
| [node/shebang](./docs/rules/shebang.md) | enforce the correct usage of shebang | ⭐️✒️ | | ||
| [node/shebang](./docs/rules/shebang.md) | suggest correct usage of shebang | ⭐️✒️ | | ||
@@ -91,8 +104,22 @@ ### Best Practices | ||
| [node/exports-style](./docs/rules/exports-style.md) | enforce either `module.exports` or `exports` | | | ||
| [node/file-extension-in-import](./docs/rules/file-extension-in-import.md) | enforce the style of file extensions in `import` declarations | ✒️ | | ||
| [node/prefer-global/buffer](./docs/rules/prefer-global/buffer.md) | enforce either `Buffer` or `require("buffer").Buffer` | | | ||
| [node/prefer-global/console](./docs/rules/prefer-global/console.md) | enforce either `console` or `require("console")` | | | ||
| [node/prefer-global/process](./docs/rules/prefer-global/process.md) | enforce either `process` or `require("process")` | | | ||
| [node/prefer-global/text-decoder](./docs/rules/prefer-global/text-decoder.md) | enforce either `TextDecoder` or `require("util").TextDecoder` | | | ||
| [node/prefer-global/text-encoder](./docs/rules/prefer-global/text-encoder.md) | enforce either `TextEncoder` or `require("util").TextEncoder` | | | ||
| [node/prefer-global/url-search-params](./docs/rules/prefer-global/url-search-params.md) | enforce either `URLSearchParams` or `require("url").URLSearchParams` | | | ||
| [node/prefer-global/url](./docs/rules/prefer-global/url.md) | enforce either `URL` or `require("url").URL` | | | ||
| [node/prefer-promises/dns](./docs/rules/prefer-promises/dns.md) | enforce `require("dns").promises` | | | ||
| [node/prefer-promises/fs](./docs/rules/prefer-promises/fs.md) | enforce `require("fs").promises` | | | ||
### Deprecated rules | ||
These rules have been deprecated in accordance with the [deprecation policy](https://eslint.org/docs/user-guide/rule-deprecation), and replaced by newer rules: | ||
| Rule ID | Replaced by | | ||
|:--------|:------------| | ||
| [node/no-hide-core-modules](./docs/rules/no-hide-core-modules.md) | (nothing) | | ||
| [node/no-unsupported-features](./docs/rules/no-unsupported-features.md) | [node/no-unsupported-features/es-syntax](./docs/rules/no-unsupported-features/es-syntax.md) and [node/no-unsupported-features/es-builtins](./docs/rules/no-unsupported-features/es-builtins.md) | | ||
<!--RULES_TABLE_END--> | ||
@@ -102,12 +129,16 @@ | ||
This plugin provides `plugin:node/recommended` preset config. | ||
This preset config: | ||
This plugin provides three configs: | ||
- enables the environment of ES2015 (ES6) and Node.js. | ||
- enables rules which are given :star: in the above table. | ||
- enables [no-process-exit](http://eslint.org/docs/rules/no-process-exit) rule because [the official document](https://nodejs.org/api/process.html#process_process_exit_code) does not recommend a use of `process.exit()`. | ||
- adds `{ecmaVersion: 2019}` into `parserOptions`. | ||
- adds `Atomics` and `SharedArrayBuffer` into `globals`. | ||
- adds this plugin into `plugins`. | ||
- `plugin:node/recommended` condiders both CommonJS and ES Modules. If [`"type":"module"` field](https://medium.com/@nodejs/announcing-a-new-experimental-modules-1be8d2d6c2ff#b023) 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](http://eslint.org/docs/rules/no-process-exit) rule because [the official document](https://nodejs.org/api/process.html#process_process_exit_code) does not recommend a use of `process.exit()`. | ||
- enable plugin rules which are given :star: in the above table. | ||
- add `{ecmaVersion: 2019}` and etc into `parserOptions`. | ||
- add proper globals into `globals`. | ||
- add this plugin into `plugins`. | ||
## 👫 FAQ | ||
@@ -144,3 +175,3 @@ | ||
## 💎 Contributing | ||
## ❤️ Contributing | ||
@@ -147,0 +178,0 @@ Welcome contributing! |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
268687
69
7774
177
11
5
+ Addedeslint-plugin-es@3.0.1(transitive)
+ Addedeslint-utils@2.1.0(transitive)
+ Addedregexpp@3.2.0(transitive)
+ Addedsemver@6.3.1(transitive)
- Removedeslint-plugin-es@1.4.1(transitive)
- Removedeslint-utils@1.4.3(transitive)
- Removedignore@4.0.6(transitive)
- Removedregexpp@2.0.1(transitive)
- Removedsemver@5.7.2(transitive)
Updatedeslint-plugin-es@^3.0.0
Updatedeslint-utils@^2.0.0
Updatedignore@^5.1.1
Updatedresolve@^1.10.1
Updatedsemver@^6.1.0