From 694ea008d1cee4eae7f201bcb7f1cbd178d6932c Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 14 Dec 2018 22:22:40 -0500 Subject: [PATCH] tools: enable no-useless-constructor lint rule This commit enables ESLint's no-useless-constructor rule. Note that the documentation examples that only include constructor calls were left in tact. PR-URL: https://github.com/nodejs/node/pull/25055 Reviewed-By: Luigi Pinca Reviewed-By: Roman Reiss Reviewed-By: Daijiro Wachi Reviewed-By: Anto Aravinth Reviewed-By: James M Snell --- .eslintrc.js | 1 + doc/api/stream.md | 10 +++++----- lib/perf_hooks.js | 2 -- lib/v8.js | 4 ---- test/parallel/test-stream-writable-null.js | 4 ---- 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 8bc20978275b79..ab0baf1c85dfca 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -223,6 +223,7 @@ module.exports = { }], 'no-useless-call': 'error', 'no-useless-concat': 'error', + 'no-useless-constructor': 'error', 'no-useless-escape': 'error', 'no-useless-return': 'error', 'no-void': 'error', diff --git a/doc/api/stream.md b/doc/api/stream.md index 96fccd0bc0cde7..775add8f8e3b76 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1441,6 +1441,7 @@ of the four basic stream classes (`stream.Writable`, `stream.Readable`, `stream.Duplex`, or `stream.Transform`), making sure they call the appropriate parent class constructor: + ```js const { Writable } = require('stream'); @@ -1531,6 +1532,7 @@ changes: * `final` {Function} Implementation for the [`stream._final()`][stream-_final] method. + ```js const { Writable } = require('stream'); @@ -1702,11 +1704,6 @@ required elements of a custom [`Writable`][] stream instance: const { Writable } = require('stream'); class MyWritable extends Writable { - constructor(options) { - super(options); - // ... - } - _write(chunk, encoding, callback) { if (chunk.toString().indexOf('a') >= 0) { callback(new Error('chunk is invalid')); @@ -1780,6 +1777,7 @@ constructor and implement the `readable._read()` method. * `destroy` {Function} Implementation for the [`stream._destroy()`][readable-_destroy] method. + ```js const { Readable } = require('stream'); @@ -2038,6 +2036,7 @@ changes: * `writableHighWaterMark` {number} Sets `highWaterMark` for the writable side of the stream. Has no effect if `highWaterMark` is provided. + ```js const { Duplex } = require('stream'); @@ -2192,6 +2191,7 @@ output on the `Readable` side is not consumed. * `flush` {Function} Implementation for the [`stream._flush()`][stream-_flush] method. + ```js const { Transform } = require('stream'); diff --git a/lib/perf_hooks.js b/lib/perf_hooks.js index f7b18816e6ceb0..7d4f1ef43073fe 100644 --- a/lib/perf_hooks.js +++ b/lib/perf_hooks.js @@ -142,8 +142,6 @@ function getMilestoneTimestamp(milestoneIdx) { } class PerformanceNodeTiming { - constructor() {} - get name() { return 'node'; } diff --git a/lib/v8.js b/lib/v8.js index 0d9ffc6033ced2..5b9632fcb096bd 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -173,10 +173,6 @@ class DefaultSerializer extends Serializer { } class DefaultDeserializer extends Deserializer { - constructor(buffer) { - super(buffer); - } - _readHostObject() { const typeIndex = this.readUint32(); const ctor = arrayBufferViewTypes[typeIndex]; diff --git a/test/parallel/test-stream-writable-null.js b/test/parallel/test-stream-writable-null.js index 63e122a3b496e1..dc0f569ee6c58c 100644 --- a/test/parallel/test-stream-writable-null.js +++ b/test/parallel/test-stream-writable-null.js @@ -5,10 +5,6 @@ const assert = require('assert'); const stream = require('stream'); class MyWritable extends stream.Writable { - constructor(opt) { - super(opt); - } - _write(chunk, encoding, callback) { assert.notStrictEqual(chunk, null); callback();