Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: enable no-empty ESLint rule #41831

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Expand Up @@ -295,7 +295,6 @@ module.exports = {
'valid-typeof': ['error', { requireStringLiterals: true }],

// ESLint recommended rules that we disable
'no-empty': 'off',
'no-inner-declarations': 'off',

// JSDoc recommended rules that we disable
Expand Down
2 changes: 1 addition & 1 deletion benchmark/es/foreach-bench.js
Expand Up @@ -22,7 +22,7 @@ function useFor(n, items, count) {
function useForOf(n, items) {
bench.start();
for (let i = 0; i < n; i++) {
// eslint-disable-next-line no-unused-vars
// eslint-disable-next-line no-unused-vars, no-empty
for (const item of items) {}
}
bench.end(n);
Expand Down
1 change: 1 addition & 0 deletions benchmark/fs/bench-statSync-failure.js
Expand Up @@ -21,6 +21,7 @@ function main({ n, statSyncType }) {
try {
fs.statSync(arg);
} catch {
// Continue regardless of error.
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions benchmark/fs/read-stream-throughput.js
Expand Up @@ -50,7 +50,11 @@ function main(conf) {
buf.fill('x');
}

try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
const ws = fs.createWriteStream(filename);
ws.on('close', runTest.bind(null, filesize, highWaterMark, encoding, n));
ws.on('drain', write);
Expand Down Expand Up @@ -81,7 +85,11 @@ function runTest(filesize, highWaterMark, encoding, n) {
});

rs.on('end', () => {
try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
// MB/sec
bench.end(bytes / (1024 * 1024));
});
Expand Down
12 changes: 10 additions & 2 deletions benchmark/fs/readfile-partitioned.js
Expand Up @@ -23,7 +23,11 @@ const bench = common.createBenchmark(main, {
});

function main({ len, dur, concurrent }) {
try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
let data = Buffer.alloc(len, 'x');
fs.writeFileSync(filename, data);
data = null;
Expand All @@ -38,7 +42,11 @@ function main({ len, dur, concurrent }) {
const totalOps = reads + zips;
benchEnded = true;
bench.end(totalOps);
try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
}, dur * 1000);

function read() {
Expand Down
12 changes: 10 additions & 2 deletions benchmark/fs/readfile-promises.js
Expand Up @@ -20,7 +20,11 @@ const bench = common.createBenchmark(main, {
});

function main({ len, duration, concurrent }) {
try { fs.unlinkSync(filename); } catch { }
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
let data = Buffer.alloc(len, 'x');
fs.writeFileSync(filename, data);
data = null;
Expand All @@ -31,7 +35,11 @@ function main({ len, duration, concurrent }) {
setTimeout(() => {
benchEnded = true;
bench.end(writes);
try { fs.unlinkSync(filename); } catch { }
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
process.exit(0);
}, duration * 1000);

Expand Down
12 changes: 10 additions & 2 deletions benchmark/fs/readfile.js
Expand Up @@ -20,7 +20,11 @@ const bench = common.createBenchmark(main, {
});

function main({ len, duration, concurrent }) {
try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
let data = Buffer.alloc(len, 'x');
fs.writeFileSync(filename, data);
data = null;
Expand All @@ -31,7 +35,11 @@ function main({ len, duration, concurrent }) {
setTimeout(() => {
benchEnded = true;
bench.end(reads);
try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
process.exit(0);
}, duration * 1000);

Expand Down
12 changes: 10 additions & 2 deletions benchmark/fs/write-stream-throughput.js
Expand Up @@ -36,7 +36,11 @@ function main({ dur, encodingType, size }) {
throw new Error(`invalid encodingType: ${encodingType}`);
}

try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}

let started = false;
let ended = false;
Expand All @@ -48,7 +52,11 @@ function main({ dur, encodingType, size }) {
f.on('finish', () => {
ended = true;
const written = fs.statSync(filename).size / 1024;
try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
bench.end(written / 1024);
});

Expand Down
6 changes: 5 additions & 1 deletion benchmark/fs/writefile-promises.js
Expand Up @@ -46,7 +46,11 @@ function main({ encodingType, duration, concurrent, size }) {
benchEnded = true;
bench.end(writes);
for (let i = 0; i < filesWritten; i++) {
try { fs.unlinkSync(`${filename}-${i}`); } catch { }
try {
fs.unlinkSync(`${filename}-${i}`);
} catch {
// Continue regardless of error.
}
}
process.exit(0);
}, duration * 1000);
Expand Down
4 changes: 3 additions & 1 deletion benchmark/misc/punycode.js
Expand Up @@ -4,7 +4,9 @@ const common = require('../common.js');
let icu;
try {
icu = common.binding('icu');
} catch {}
} catch {
// Continue regardless of error.
}
const punycode = require('punycode');

const bench = common.createBenchmark(main, {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/net/net-c2s-cork.js
Expand Up @@ -55,7 +55,7 @@ function main({ dur, len, type }) {

function send() {
socket.cork();
while (socket.write(chunk, encoding)) {}
while (socket.write(chunk, encoding));
socket.uncork();
}
});
Expand Down
8 changes: 4 additions & 4 deletions doc/api/console.md
Expand Up @@ -469,10 +469,10 @@ Stops a timer that was previously started by calling [`console.time()`][] and
prints the result to `stdout`:

```js
console.time('100-elements');
for (let i = 0; i < 100; i++) {}
console.timeEnd('100-elements');
// prints 100-elements: 225.438ms
console.time('bunch-of-stuff');
// Do a bunch of stuff.
console.timeEnd('bunch-of-stuff');
// Prints: bunch-of-stuff: 225.438ms
```

### `console.timeLog([label][, ...data])`
Expand Down
8 changes: 6 additions & 2 deletions doc/api/worker_threads.md
Expand Up @@ -1267,7 +1267,9 @@ import {

if (isMainThread) {
new Worker(new URL(import.meta.url));
for (let n = 0; n < 1e10; n++) {}
for (let n = 0; n < 1e10; n++) {
// Looping to simulate work.
}
} else {
// This output will be blocked by the for loop in the main thread.
console.log('foo');
Expand All @@ -1284,7 +1286,9 @@ const {

if (isMainThread) {
new Worker(__filename);
for (let n = 0; n < 1e10; n++) {}
for (let n = 0; n < 1e10; n++) {
// Looping to simulate work.
}
} else {
// This output will be blocked by the for loop in the main thread.
console.log('foo');
Expand Down
8 changes: 6 additions & 2 deletions lib/events.js
Expand Up @@ -445,7 +445,9 @@ function enhanceStackTrace(err, own) {
const { name } = this.constructor;
if (name !== 'EventEmitter')
ctorInfo = ` on ${name} instance`;
} catch {}
} catch {
// Continue regardless of error.
}
const sep = `\nEmitted 'error' event${ctorInfo} at:\n`;

const errStack = ArrayPrototypeSlice(
Expand Down Expand Up @@ -493,7 +495,9 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
value: FunctionPrototypeBind(enhanceStackTrace, this, er, capture),
configurable: true
});
} catch {}
} catch {
// Continue regardless of error.
}

// Note: The comments on the `throw` lines are intentional, they show
// up in Node's output if this results in an unhandled exception.
Expand Down
4 changes: 3 additions & 1 deletion lib/fs.js
Expand Up @@ -1600,7 +1600,9 @@ function symlink(target, path, type_, callback_) {
// errors consistent between platforms if invalid path is
// provided.
absoluteTarget = pathModule.resolve(path, '..', target);
} catch { }
} catch {
// Continue regardless of error.
}
if (absoluteTarget !== undefined) {
stat(absoluteTarget, (err, stat) => {
const resolvedType = !err && stat.isDirectory() ? 'dir' : 'file';
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/bootstrap/pre_execution.js
Expand Up @@ -103,7 +103,9 @@ function patchProcessObject(expandArgv1) {
const path = require('path');
try {
process.argv[1] = path.resolve(process.argv[1]);
} catch {}
} catch {
// Continue regardless of error.
}
}

// TODO(joyeecheung): most of these should be deprecated and removed,
Expand Down
12 changes: 9 additions & 3 deletions lib/internal/error_serdes.js
Expand Up @@ -48,7 +48,9 @@ function TryGetAllProperties(object, target = object) {
if (getter && key !== '__proto__') {
try {
descriptor.value = FunctionPrototypeCall(getter, target);
} catch {}
} catch {
// Continue regardless of error.
}
}
if ('value' in descriptor && typeof descriptor.value !== 'function') {
delete descriptor.get;
Expand Down Expand Up @@ -107,11 +109,15 @@ function serializeError(error) {
}
}
}
} catch {}
} catch {
// Continue regardless of error.
}
try {
const serialized = serialize(error);
return Buffer.concat([Buffer.from([kSerializedObject]), serialized]);
} catch {}
} catch {
// Continue regardless of error.
}
return Buffer.concat([Buffer.from([kInspectedError]),
Buffer.from(inspect(error), 'utf8')]);
}
Expand Down
8 changes: 6 additions & 2 deletions lib/internal/main/worker_thread.js
Expand Up @@ -226,14 +226,18 @@ function workerOnGlobalUncaughtException(error, fromPromise) {
if (!handlerThrew) {
process.emit('exit', process.exitCode);
}
} catch {}
} catch {
// Continue regardless of error.
}
}

let serialized;
try {
const { serializeError } = require('internal/error_serdes');
serialized = serializeError(error);
} catch {}
} catch {
// Continue regardless of error.
}
debug(`[${threadId}] uncaught exception serialized = ${!!serialized}`);
if (serialized)
port.postMessage({
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/modules/cjs/loader.js
Expand Up @@ -1128,7 +1128,9 @@ Module._extensions['.js'] = function(module, filename) {
let parentSource;
try {
parentSource = fs.readFileSync(parentPath, 'utf8');
} catch {}
} catch {
// Continue regardless of error.
}
if (parentSource) {
const errLine = StringPrototypeSplit(
StringPrototypeSlice(err.stack, StringPrototypeIndexOf(
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/modules/esm/module_job.js
Expand Up @@ -154,7 +154,9 @@ class ModuleJob {
// care about CommonJS for the purposes of this error message.
({ format } =
await this.loader.load(childFileURL));
} catch {}
} catch {
// Continue regardless of error.
}

if (format === 'commonjs') {
const importStatement = splitStack[1];
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/modules/esm/resolve.js
Expand Up @@ -474,7 +474,9 @@ function resolvePackageTargetString(
try {
new URL(target);
isURL = true;
} catch {}
} catch {
// Continue regardless of error.
}
if (!isURL) {
const exportTarget = pattern ?
RegExpPrototypeSymbolReplace(patternRegEx, target, () => subpath) :
Expand Down
8 changes: 6 additions & 2 deletions lib/internal/modules/esm/translators.js
Expand Up @@ -180,7 +180,9 @@ translators.set('commonjs', async function commonjsStrategy(url, source,
let value;
try {
value = exports[exportName];
} catch {}
} catch {
// Continue regardless of error.
}
this.setExport(exportName, value);
}
this.setExport('default', exports);
Expand All @@ -205,7 +207,9 @@ function cjsPreparseModuleExports(filename) {
let source;
try {
source = readFileSync(filename, 'utf8');
} catch {}
} catch {
// Continue regardless of error.
}

let exports, reexports;
try {
Expand Down