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

fix: set args to after-used for no-unused-vars rule #103

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
43 changes: 30 additions & 13 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -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.")
})
})
Loading