Skip to content

Latest commit

 

History

History
126 lines (102 loc) · 5.72 KB

File metadata and controls

126 lines (102 loc) · 5.72 KB

Disallow deprecated API (no-deprecated-api)

Node has many deprecated API. The community is going to remove those API from Node in future, so we should not use those.

Rule Details

The following patterns are considered problems:

/*eslint no-deprecated-api: 2*/

var fs = require("fs");
fs.exists("./foo.js", function() {}); /*ERROR: 'fs.exists' was deprecated since v4. Use 'fs.stat()' or 'fs.access()' instead.*/

// Also, it can report the following patterns.
var exists = require("fs").exists; /*ERROR: 'fs.exists' was deprecated since v4. Use 'fs.stat()' or 'fs.access()' instead.*/
const {exists} = require("fs"); /*ERROR: 'fs.exists' was deprecated since v4. Use 'fs.stat()' or 'fs.access()' instead.*/


// And other deprecated API below.

This rule reports the following deprecated API.

Known Limitations

Cannot report non-static properties:

Cannot report dynamic things:

require(foo).aDeprecatedProperty;
require("http")[A_DEPRECATED_PROPERTY]();

Cannot understand assignments to properties:

var obj = {
    Buffer: require("buffer").Buffer
};
new obj.Buffer(); /* missing. */
var obj = {};
obj.Buffer = require("buffer").Buffer
new obj.Buffer(); /* missing. */

Cannot understand assignments to arguments:

(function(Buffer) {
    new Buffer(); /* missing. */
})(require("buffer").Buffer);

Cannot understand reassignments:

var Buffer = require("buffer").Buffer;
Buffer = require("another-buffer");
new Buffer(); /*ERROR: 'buffer.Buffer' constructor was deprecated.*/

When Not To Use It

If you don't want to be warned on deprecated API, then it's safe to disable this rule.