Skip to content

Commit

Permalink
Breaking: update no-deprecated-api rule
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Feb 5, 2018
1 parent 49c060a commit 400e20a
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/rules/no-deprecated-api.md
Expand Up @@ -24,6 +24,9 @@ const {exists} = require("fs"); /*ERROR: 'fs.exists' was deprecated since
This rule reports the following deprecated API.

- _linklist (undocumented)
- async_hooks
- [currentId](https://nodejs.org/dist/v8.2.0/docs/api/deprecations.html#deprecations_dep0070_async_hooks_currentid)
- [triggerId](https://nodejs.org/dist/v8.2.0/docs/api/deprecations.html#deprecations_dep0071_async_hooks_triggerid)
- buffer
- [Buffer constructors](https://nodejs.org/dist/v6.0.0/docs/api/buffer.html#buffer_class_buffer) (Use [safe-buffer](https://www.npmjs.com/package/safe-buffer) module for `Node@<4.5.0`)
- [SlowBuffer class](https://nodejs.org/dist/v6.0.0/docs/api/buffer.html#buffer_class_slowbuffer)
Expand Down Expand Up @@ -51,9 +54,12 @@ This rule reports the following deprecated API.
- [createClient](https://nodejs.org/dist/v0.10.0/docs/api/http.html#http_http_createclient_port_host)
- module
- `requireRepl` (undocumented)
- [_debug](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0077_module_debug)
- os
- `tmpDir` (undocumented)
- `getNetworkInterfaces` (undocumented)
- path
- [_makeLong](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0080_path_makelong)
- process
- `EventEmitter` (undocumented)
- [punycode](https://nodejs.org/dist/v7.0.0/docs/api/punycode.html)
Expand All @@ -71,6 +77,7 @@ This rule reports the following deprecated API.
- [CryptoStream](https://nodejs.org/dist/v0.12.0/docs/api/tls.html#tls_class_cryptostream)
- [SecurePair](https://nodejs.org/dist/v6.0.0/docs/api/tls.html#tls_class_securepair)
- [createSecurePair](https://nodejs.org/dist/v6.0.0/docs/api/tls.html#tls_tls_createsecurepair_context_isserver_requestcert_rejectunauthorized_options)
- [parseCertString](https://nodejs.org/dist/v8.6.0/docs/api/deprecations.html#deprecations_dep0076_tls_parsecertstring)
- tty
- [setRawMode](https://nodejs.org/dist/v0.10.0/docs/api/tty.html#tty_tty_setrawmode_mode)
- util
Expand Down Expand Up @@ -127,6 +134,8 @@ This rule ignores APIs that `ignoreModuleItems` includes.
This option can include the following values:

- `_linklist`
- `async_hooks.currentId`
- `async_hooks.triggerId`
- `buffer.Buffer()`
- `new buffer.Buffer()`
- `buffer.SlowBuffer`
Expand All @@ -146,7 +155,10 @@ This option can include the following values:
- `http.createClient`
- `module.Module.requireRepl`
- `module.requireRepl`
- `module.Module._debug`
- `module._debug`
- `os.tmpDir`
- `path._makeLong`
- `punycode`
- `readline.codePointAt`
- `readline.getStringWidth`
Expand All @@ -157,6 +169,7 @@ This option can include the following values:
- `tls.CryptoStream`
- `tls.SecurePair`
- `tls.createSecurePair`
- `tls.parseCertString`
- `tty.setRawMode`
- `util.debug`
- `util.error`
Expand Down Expand Up @@ -220,6 +233,8 @@ This rule cannot report the following cases:

### non-static properties

- async_hooks
- [asyncResource.triggerId](https://nodejs.org/dist/v8.2.0/docs/api/deprecations.html#deprecations_dep0072_async_hooks_asyncresource_triggerid)
- buffer
- [buf.parent](https://nodejs.org/dist/v8.0.0/docs/api/buffer.html#buffer_buf_parent)
- cluster
Expand All @@ -232,6 +247,13 @@ This rule cannot report the following cases:
- [server.connections](https://nodejs.org/dist/v0.10.0/docs/api/net.html#net_server_connections)
- repl
- `replServer.convertToContext` (undocumented)
- [replServer.turnOffEditorMode](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0078_replserver_turnoffeditormode)
- [replServer.memory](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0082_replserver_prototype_memory)

### types of arguments

- fs
- `fs.truncate()` and `fs.truncateSync()` usage with a file descriptor has been deprecated.

### dynamic things

Expand Down
34 changes: 34 additions & 0 deletions lib/util/deprecated-apis.js
Expand Up @@ -16,6 +16,18 @@ module.exports = {
since: 5,
replacedBy: null,
},
async_hooks: { //eslint-disable-line camelcase
currentId: {
$deprecated: true,
since: 8.2,
replacedBy: "'async_hooks.executionAsyncId()'",
},
triggerId: {
$deprecated: true,
since: 8.2,
replacedBy: "'async_hooks.triggerAsyncId()'",
},
},
buffer: {
Buffer: {
$constructor: {
Expand Down Expand Up @@ -122,12 +134,22 @@ module.exports = {
since: 6,
replacedBy: "'require(\"repl\")'",
},
_debug: {
$deprecated: true,
since: 9,
replacedBy: null,
},
},
requireRepl: {
$deprecated: true,
since: 6,
replacedBy: "'require(\"repl\")'",
},
_debug: {
$deprecated: true,
since: 9,
replacedBy: null,
},
},
os: {
getNetworkInterfaces: {
Expand All @@ -141,6 +163,13 @@ module.exports = {
replacedBy: "'os.tmpdir()'",
},
},
path: {
_makeLong: {
$deprecated: true,
since: 9,
replacedBy: "'path.toNamespacedPath()'",
},
},
punycode: {
$deprecated: true,
since: 7,
Expand Down Expand Up @@ -194,6 +223,11 @@ module.exports = {
since: 6,
replacedBy: "'tls.TLSSocket'",
},
parseCertString: {
$deprecated: true,
since: 8.6,
replacedBy: "'querystring.parse()'",
},
},
tty: {
setRawMode: {
Expand Down
30 changes: 30 additions & 0 deletions tests/lib/rules/no-deprecated-api.js
Expand Up @@ -243,6 +243,16 @@ ruleTester.run("no-deprecated-api", rule, {
env: { node: true },
errors: ["'_linklist' module was deprecated since v5."],
},
{
code: "require('async_hooks').currentId;",
env: { node: true },
errors: ["'async_hooks.currentId' was deprecated since v8.2. Use 'async_hooks.executionAsyncId()' instead."],
},
{
code: "require('async_hooks').triggerId;",
env: { node: true },
errors: ["'async_hooks.triggerId' was deprecated since v8.2. Use 'async_hooks.triggerAsyncId()' instead."],
},
{
code: "require('constants');",
env: { node: true },
Expand Down Expand Up @@ -323,6 +333,16 @@ ruleTester.run("no-deprecated-api", rule, {
env: { node: true },
errors: ["'module.Module.requireRepl' was deprecated since v6. Use 'require(\"repl\")' instead."],
},
{
code: "require('module')._debug;",
env: { node: true },
errors: ["'module._debug' was deprecated since v9."],
},
{
code: "require('module').Module._debug;",
env: { node: true },
errors: ["'module.Module._debug' was deprecated since v9."],
},
{
code: "require('os').getNetworkInterfaces;",
env: { node: true },
Expand All @@ -333,6 +353,11 @@ ruleTester.run("no-deprecated-api", rule, {
env: { node: true },
errors: ["'os.tmpDir' was deprecated since v7. Use 'os.tmpdir()' instead."],
},
{
code: "require('path')._makeLong;",
env: { node: true },
errors: ["'path._makeLong' was deprecated since v9. Use 'path.toNamespacedPath()' instead."],
},
{
code: "require('punycode');",
env: { node: true },
Expand Down Expand Up @@ -383,6 +408,11 @@ ruleTester.run("no-deprecated-api", rule, {
env: { node: true },
errors: ["'tls.createSecurePair' was deprecated since v6. Use 'tls.TLSSocket' instead."],
},
{
code: "require('tls').parseCertString;",
env: { node: true },
errors: ["'tls.parseCertString' was deprecated since v8.6. Use 'querystring.parse()' instead."],
},
{
code: "require('tty').setRawMode;",
env: { node: true },
Expand Down

0 comments on commit 400e20a

Please sign in to comment.