diff --git a/package.json b/package.json index 19cb08633..3bd157cd7 100644 --- a/package.json +++ b/package.json @@ -468,8 +468,8 @@ "predev:incremental": "node-gyp configure build -C test --debug", "dev:incremental": "node test", "doc": "doxygen doc/Doxyfile", - "lint": "node tools/eslint-format && node tools/clang-format", - "lint:fix": "node tools/clang-format --fix && node tools/eslint-format --fix" + "lint": "eslint && node tools/clang-format", + "lint:fix": "eslint --fix && node tools/clang-format --fix" }, "pre-commit": "lint", "version": "8.2.2", diff --git a/test/array_buffer.js b/test/array_buffer.js index d6853e50d..08547ed7e 100644 --- a/test/array_buffer.js +++ b/test/array_buffer.js @@ -58,7 +58,7 @@ function test (binding) { 'ArrayBuffer updates data pointer and length when detached', () => { // Detach the ArrayBuffer in JavaScript. - // eslint-disable-next-line no-undef + const mem = new WebAssembly.Memory({ initial: 1 }); binding.arraybuffer.checkDetachUpdatesData(mem.buffer, () => mem.grow(1)); diff --git a/test/async_context.js b/test/async_context.js index 6a4bef662..6cf0418f6 100644 --- a/test/async_context.js +++ b/test/async_context.js @@ -73,7 +73,7 @@ async function makeCallbackWithResource (binding) { { eventName: 'init', type: 'async_context_test', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: { foo: 'foo' } }, { eventName: 'before' }, @@ -95,7 +95,7 @@ async function makeCallbackWithoutResource (binding) { { eventName: 'init', type: 'async_context_no_res_test', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: { } }, { eventName: 'before' }, diff --git a/test/async_progress_queue_worker.js b/test/async_progress_queue_worker.js index 3f031a415..b72a55c71 100644 --- a/test/async_progress_queue_worker.js +++ b/test/async_progress_queue_worker.js @@ -42,7 +42,7 @@ async function asyncProgressWorkerCallbackOverloads (bindingFunction) { { eventName: 'init', type: 'cbResources', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: {} }, { eventName: 'before' }, @@ -90,7 +90,7 @@ async function asyncProgressWorkerRecvOverloads (bindingFunction) { { eventName: 'init', type: asyncResName, - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: asyncResObject }, { eventName: 'before' }, @@ -131,7 +131,7 @@ async function asyncProgressWorkerNoCbOverloads (bindingFunction) { { eventName: 'init', type: asyncResName, - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: asyncResObject }, { eventName: 'before' }, diff --git a/test/async_progress_worker.js b/test/async_progress_worker.js index 78ba7b63d..d96ab64b8 100644 --- a/test/async_progress_worker.js +++ b/test/async_progress_worker.js @@ -44,7 +44,7 @@ async function asyncProgressWorkerCallbackOverloads (bindingFunction) { { eventName: 'init', type: 'cbResources', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: {} }, { eventName: 'before' }, @@ -92,7 +92,7 @@ async function asyncProgressWorkerRecvOverloads (bindingFunction) { { eventName: 'init', type: asyncResName, - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: asyncResObject }, { eventName: 'before' }, @@ -133,7 +133,7 @@ async function asyncProgressWorkerNoCbOverloads (bindingFunction) { { eventName: 'init', type: asyncResName, - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: asyncResObject }, { eventName: 'before' }, diff --git a/test/async_worker.js b/test/async_worker.js index 304a3247f..16e2a8e96 100644 --- a/test/async_worker.js +++ b/test/async_worker.js @@ -139,7 +139,7 @@ async function test (binding) { { eventName: 'init', type: 'TestResource', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: { foo: 'fooBar' } }, { eventName: 'before' }, @@ -167,7 +167,7 @@ async function test (binding) { { eventName: 'init', type: 'TestResource', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: { } }, { eventName: 'before' }, @@ -194,7 +194,7 @@ async function test (binding) { { eventName: 'init', type: 'TestResource', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: { foo: 'foo' } }, { eventName: 'before' }, @@ -224,7 +224,7 @@ async function test (binding) { { eventName: 'init', type: 'TestResource', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: { foo: 'foo' } }, { eventName: 'before' }, @@ -252,7 +252,7 @@ async function test (binding) { { eventName: 'init', type: 'TestResource', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: { foo: 'foo' } }, { eventName: 'before' }, diff --git a/test/function.js b/test/function.js index 7cd8c04e2..c5514db36 100644 --- a/test/function.js +++ b/test/function.js @@ -18,7 +18,7 @@ function test (binding) { assert.deepStrictEqual(binding.valueCallback(), { foo: 'bar' }); - /* eslint-disable-next-line no-new, new-cap */ + /* eslint-disable-next-line new-cap */ assert.strictEqual(new binding.newTargetCallback(), binding.newTargetCallback); assert.strictEqual(binding.newTargetCallback(), undefined); diff --git a/test/function_reference.js b/test/function_reference.js index 84263fce9..e69fc8e5b 100644 --- a/test/function_reference.js +++ b/test/function_reference.js @@ -95,7 +95,7 @@ async function canCallAsyncFunctionWithDifferentOverloads (binding) { { eventName: 'init', type: 'func_ref_resources', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: {} }, { eventName: 'before' }, @@ -113,7 +113,7 @@ async function canCallAsyncFunctionWithDifferentOverloads (binding) { { eventName: 'init', type: 'func_ref_resources', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: {} }, { eventName: 'before' }, diff --git a/test/type_taggable.js b/test/type_taggable.js index 263befa9d..7bc843cf6 100644 --- a/test/type_taggable.js +++ b/test/type_taggable.js @@ -53,8 +53,7 @@ function testTypeTaggable ({ typeTaggedInstance, checkTypeTag }) { assert.strictEqual(checkTypeTag(4, obj3), false); } -// eslint-disable-next-line camelcase -function test ({ type_taggable }) { - testTypeTaggable(type_taggable.external); - testTypeTaggable(type_taggable.object); +function test (binding) { + testTypeTaggable(binding.type_taggable.external); + testTypeTaggable(binding.type_taggable.object); } diff --git a/tools/eslint-format.js b/tools/eslint-format.js deleted file mode 100644 index 6923ab7b6..000000000 --- a/tools/eslint-format.js +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env node - -const spawn = require('child_process').spawnSync; - -const filesToCheck = '*.js'; -const FORMAT_START = process.env.FORMAT_START || 'main'; -const IS_WIN = process.platform === 'win32'; -const ESLINT_PATH = IS_WIN ? 'node_modules\\.bin\\eslint.cmd' : 'node_modules/.bin/eslint'; - -function main (args) { - let fix = false; - while (args.length > 0) { - switch (args[0]) { - case '-f': - case '--fix': - fix = true; - break; - default: - } - args.shift(); - } - - // Check js files that change on unstaged file - const fileUnStaged = spawn( - 'git', - ['diff', '--name-only', '--diff-filter=d', FORMAT_START, filesToCheck], - { - encoding: 'utf-8' - } - ); - - // Check js files that change on staged file - const fileStaged = spawn( - 'git', - ['diff', '--name-only', '--cached', '--diff-filter=d', FORMAT_START, filesToCheck], - { - encoding: 'utf-8' - } - ); - - const options = [ - ...fileStaged.stdout.split('\n').filter((f) => f !== ''), - ...fileUnStaged.stdout.split('\n').filter((f) => f !== '') - ]; - - if (fix) { - options.push('--fix'); - } - - const result = spawn(ESLINT_PATH, [...options], { - encoding: 'utf-8' - }); - - if (result.error && result.error.errno === 'ENOENT') { - console.error('Eslint not found! Eslint is supposed to be found at ', ESLINT_PATH); - return 2; - } - - if (result.status === 1) { - console.error('Eslint error:', result.stdout); - const fixCmd = 'npm run lint:fix'; - console.error(`ERROR: please run "${fixCmd}" to format changes in your commit - Note that when running the command locally, please keep your local - main branch and working branch up to date with nodejs/node-addon-api - to exclude un-related complains. - Or you can run "env FORMAT_START=upstream/main ${fixCmd}". - Also fix JS files by yourself if necessary.`); - return 1; - } - - if (result.stderr) { - console.error('Error running eslint:', result.stderr); - return 2; - } -} - -if (require.main === module) { - process.exitCode = main(process.argv.slice(2)); -}