From e7878e9cf66ce125f0c9617663d3e92db03fe454 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Thu, 28 Sep 2017 21:28:19 +0900 Subject: [PATCH] Update: fix missing deprecated APIs in v6 (fixes #92) --- docs/rules/no-deprecated-api.md | 6 ++++-- lib/rules/no-deprecated-api.js | 17 ++++++++++++++--- lib/util/deprecated-apis.js | 12 ++++++++++++ tests/lib/rules/no-deprecated-api.js | 10 ++++++++++ 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/docs/rules/no-deprecated-api.md b/docs/rules/no-deprecated-api.md index 00bc1327..1829fc46 100644 --- a/docs/rules/no-deprecated-api.md +++ b/docs/rules/no-deprecated-api.md @@ -44,7 +44,9 @@ This rule reports the following deprecated API. - [lchownSync](https://nodejs.org/dist/v8.0.0/docs/api/fs.html#fs_fs_lchownsync_path_uid_gid) - globals - [require.extensions](https://nodejs.org/dist/v0.12.0/docs/api/globals.html#globals_require_extensions) - - `Intl.v8BreakIterator` (undocumented) + - [GLOBAL](https://nodejs.org/api/deprecations.html#deprecations_dep0016_global_root) + - [root](https://nodejs.org/api/deprecations.html#deprecations_dep0016_global_root) + - [Intl.v8BreakIterator](https://nodejs.org/api/deprecations.html#deprecations_dep0017_intl_v8breakiterator) - http - [createClient](https://nodejs.org/dist/v0.10.0/docs/api/http.html#http_http_createclient_port_host) - module @@ -62,7 +64,7 @@ This rule reports the following deprecated API. - `stripVTControlCharacters` (undocumented) - repl - [process.env.NODE_REPL_HISTORY_FILE](https://nodejs.org/dist/v4.0.0/docs/api/repl.html#repl_node_repl_history_file) -- sys (undocumented) +- [sys](https://nodejs.org/api/deprecations.html#deprecations_dep0025_require_sys) - tls - [CleartextStream](https://nodejs.org/dist/v0.10.0/docs/api/tls.html#tls_class_tls_cleartextstream) (this class was removed on v0.11.3, but never deprecated in documents) diff --git a/lib/rules/no-deprecated-api.js b/lib/rules/no-deprecated-api.js index 391d1c04..f6e1d711 100644 --- a/lib/rules/no-deprecated-api.js +++ b/lib/rules/no-deprecated-api.js @@ -274,7 +274,10 @@ function create(context) { */ function reportProperty(node, path, key, info) { const ignored = info.global ? ignoredGlobalItems : ignoredModuleItems - const name = `${path.join(".")}.${key}` + + path.push(key) + const name = path.join(".") + path.pop() if (ignored.indexOf(name) === -1) { report(node, `'${name}'`, info) @@ -405,8 +408,16 @@ function create(context) { } varStack.push(variable) - for (const reference of variable.references.filter(r => r.isRead())) { - checkProperties(reference.identifier, path, infoMap) + if (infoMap.$deprecated) { + const key = path.pop() + for (const reference of variable.references.filter(r => r.isRead())) { + reportProperty(reference.identifier, path, key, infoMap) + } + } + else { + for (const reference of variable.references.filter(r => r.isRead())) { + checkProperties(reference.identifier, path, infoMap) + } } varStack.pop() diff --git a/lib/util/deprecated-apis.js b/lib/util/deprecated-apis.js index 1ed3f2ee..3a7ed828 100644 --- a/lib/util/deprecated-apis.js +++ b/lib/util/deprecated-apis.js @@ -337,6 +337,12 @@ module.exports = { replacedBy: "'Buffer.alloc()' or 'Buffer.from()' (use 'https://www.npmjs.com/package/safe-buffer' for '<4.5.0')", }, }, + GLOBAL: { + $deprecated: true, + global: true, + since: 6, + replacedBy: "'global'", + }, Intl: { v8BreakIterator: { $deprecated: true, @@ -353,6 +359,12 @@ module.exports = { replacedBy: "compiling them ahead of time", }, }, + root: { + $deprecated: true, + global: true, + since: 6, + replacedBy: "'global'", + }, process: { EventEmitter: { $deprecated: true, diff --git a/tests/lib/rules/no-deprecated-api.js b/tests/lib/rules/no-deprecated-api.js index 9b607616..c4c45eab 100644 --- a/tests/lib/rules/no-deprecated-api.js +++ b/tests/lib/rules/no-deprecated-api.js @@ -592,6 +592,11 @@ ruleTester.run("no-deprecated-api", rule, { env: {node: true}, errors: ["'Buffer()' was deprecated since v6. Use 'Buffer.alloc()' or 'Buffer.from()' (use 'https://www.npmjs.com/package/safe-buffer' for '<4.5.0') instead."], }, + { + code: "GLOBAL; /*globals GLOBAL*/", + env: {node: true}, + errors: ["'GLOBAL' was deprecated since v6. Use 'global' instead."], + }, { code: "Intl.v8BreakIterator;", env: {node: true}, @@ -602,6 +607,11 @@ ruleTester.run("no-deprecated-api", rule, { env: {node: true}, errors: ["'require.extensions' was deprecated since v0.12. Use compiling them ahead of time instead."], }, + { + code: "root;", + env: {node: true}, + errors: ["'root' was deprecated since v6. Use 'global' instead."], + }, { code: "process.EventEmitter;", env: {node: true},