Skip to content

Commit

Permalink
Update: fix missing deprecated APIs in v6 (fixes #92)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Sep 28, 2017
1 parent 52ceb11 commit e7878e9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
6 changes: 4 additions & 2 deletions docs/rules/no-deprecated-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
17 changes: 14 additions & 3 deletions lib/rules/no-deprecated-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions lib/util/deprecated-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/no-deprecated-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand Down

0 comments on commit e7878e9

Please sign in to comment.