From f5ae4dafb8456ee2f3f0fdc8dd679d83e9f920c9 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 10 Apr 2024 12:44:21 -0700 Subject: [PATCH] fix: set args to after-used for no-unused-vars rule --- lib/index.js | 2 +- test/index.js | 43 ++++++++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/lib/index.js b/lib/index.js index e832f8a..c419c60 100644 --- a/lib/index.js +++ b/lib/index.js @@ -161,7 +161,7 @@ module.exports = { 'no-unused-expressions': ['error', { allowShortCircuit: true, allowTernary: true, allowTaggedTemplates: true, }], - 'no-unused-vars': ['error', { vars: 'all', args: 'none', ignoreRestSiblings: true }], + 'no-unused-vars': ['error', { vars: 'all', args: 'after-used', ignoreRestSiblings: true }], 'no-use-before-define': ['error', { functions: false, classes: false, variables: false }], 'no-useless-call': 'error', 'no-useless-computed-key': 'error', diff --git a/test/index.js b/test/index.js index 30d8662..ba01831 100644 --- a/test/index.js +++ b/test/index.js @@ -1,23 +1,40 @@ const { ESLint: ESLint8 } = require('eslint') const t = require('tap') -const code = `const foo = 1 +const loadConfig = (desc, Ctor) => new Ctor({ + useEslintrc: false, + overrideConfigFile: 'lib/index.js', // this is relative to the root of the repo +}) + +const lintText = async (engine, code) => { + const [result] = await engine.lintText(code) + return result +} + +t.test('eslint8', async t => { + const engine = loadConfig('eslint 8', ESLint8) + + t.test('config loads correctly', async t => { + const code = `const foo = 1 const bar = function () {} bar(foo) ` - -t.test('config loads correctly', t => { - const loadConfig = (desc, Ctor) => t.test(async t => { - const engine = new Ctor({ - useEslintrc: false, - overrideConfigFile: 'lib/index.js', // this is relative to the root of the repo - }) - - const [result] = await engine.lintText(code) + const result = await lintText(engine, code) t.equal(result.errorCount, 0, 'no errors') }) - t.plan(1) - loadConfig('eslint 8', ESLint8) - t.end() + t.test('unused args', async t => { + const code = `function unused (a, b, c) { + return b +} +function allUsed (a, b) { + return b +} +unused() +allUsed() +` + const result = await lintText(engine, code) + t.equal(result.errorCount, 1, 'no errors') + t.equal(result.messages[0].message, "'c' is defined but never used.") + }) })