-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set args to after-used for no-unused-vars rule (#103)
This PR makes the following code failing linting. IMO this helps with refactoring and making sure arguments are not left in function calls. ```js // Lint error: "'c' is defined but never used." function unused (a, b, c) { return b } unused() ```
- Loading branch information
1 parent
436f26c
commit acd463d
Showing
2 changed files
with
31 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") | ||
}) | ||
}) |