-
-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
278 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Snapshot report for `test/consistent-function-scoping.js` | ||
|
||
The actual snapshot is saved in `consistent-function-scoping.js.snap`. | ||
|
||
Generated by [AVA](https://avajs.dev). | ||
|
||
## consistent-function-scoping - #1 | ||
|
||
> Snapshot 1 | ||
`␊ | ||
1 | function foo() {␊ | ||
> 2 | function bar() {}␊ | ||
| ^^^^^^^^^^^^ Move function 'bar' to the outer scope.␊ | ||
3 | }␊ | ||
` | ||
|
||
## consistent-function-scoping - #2 | ||
|
||
> Snapshot 1 | ||
`␊ | ||
1 | function foo() {␊ | ||
> 2 | async function bar() {}␊ | ||
| ^^^^^^^^^^^^^^^^^^ Move async function 'bar' to the outer scope.␊ | ||
3 | }␊ | ||
` | ||
|
||
## consistent-function-scoping - #3 | ||
|
||
> Snapshot 1 | ||
`␊ | ||
1 | function foo() {␊ | ||
> 2 | function * bar() {}␊ | ||
| ^^^^^^^^^^^^^^ Move generator function 'bar' to the outer scope.␊ | ||
3 | }␊ | ||
` | ||
|
||
## consistent-function-scoping - #4 | ||
|
||
> Snapshot 1 | ||
`␊ | ||
1 | function foo() {␊ | ||
> 2 | async function * bar() {}␊ | ||
| ^^^^^^^^^^^^^^^^^^^^ Move async generator function 'bar' to the outer scope.␊ | ||
3 | }␊ | ||
` | ||
|
||
## consistent-function-scoping - #5 | ||
|
||
> Snapshot 1 | ||
`␊ | ||
1 | function foo() {␊ | ||
> 2 | const bar = () => {}␊ | ||
| ^^ Move arrow function 'bar' to the outer scope.␊ | ||
3 | }␊ | ||
` | ||
|
||
## consistent-function-scoping - #6 | ||
|
||
> Snapshot 1 | ||
`␊ | ||
> 1 | const doFoo = () => bar => bar;␊ | ||
| ^^ Move arrow function to the outer scope.␊ | ||
` | ||
|
||
## consistent-function-scoping - #7 | ||
|
||
> Snapshot 1 | ||
`␊ | ||
1 | function foo() {␊ | ||
> 2 | const bar = async () => {}␊ | ||
| ^^ Move async arrow function 'bar' to the outer scope.␊ | ||
3 | }␊ | ||
` |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Snapshot report for `test/no-useless-undefined.js` | ||
|
||
The actual snapshot is saved in `no-useless-undefined.js.snap`. | ||
|
||
Generated by [AVA](https://avajs.dev). | ||
|
||
## no-useless-undefined - #1 | ||
|
||
> Snapshot 1 | ||
`␊ | ||
1 | foo(␊ | ||
2 | undefined,␊ | ||
3 | bar,␊ | ||
> 4 | undefined,␊ | ||
| ^^^^^^^^^^␊ | ||
> 5 | undefined,␊ | ||
| ^^^^^^^^^^^␊ | ||
> 6 | undefined,␊ | ||
| ^^^^^^^^^^^␊ | ||
> 7 | undefined,␊ | ||
| ^^^^^^^^^^^ Do not use useless `undefined`.␊ | ||
8 | )␊ | ||
` | ||
|
||
## no-useless-undefined - #2 | ||
|
||
> Snapshot 1 | ||
`␊ | ||
> 1 | function foo([bar = undefined] = []) {}␊ | ||
| ^^^^^^^^^ Do not use useless `undefined`.␊ | ||
` | ||
|
||
## no-useless-undefined - #3 | ||
|
||
> Snapshot 1 | ||
`␊ | ||
> 1 | foo(bar, undefined, undefined);␊ | ||
| ^^^^^^^^^^^^^^^^^^^^ Do not use useless `undefined`.␊ | ||
` | ||
|
||
## no-useless-undefined - #4 | ||
|
||
> Snapshot 1 | ||
`␊ | ||
> 1 | let a = undefined, b = 2;␊ | ||
| ^^^^^^^^^ Do not use useless `undefined`.␊ | ||
` |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
'use strict'; | ||
const {Linter} = require('eslint'); | ||
const {codeFrameColumns} = require('@babel/code-frame'); | ||
const codeFrameColumnsOptions = {linesAbove: Infinity, linesBelow: Infinity}; | ||
|
||
function visualizeRange(text, location, message) { | ||
return codeFrameColumns( | ||
text, | ||
location, | ||
{ | ||
...codeFrameColumnsOptions, | ||
message | ||
} | ||
); | ||
} | ||
|
||
function visualizeEslintResult(text, result) { | ||
const {line, column, endLine, endColumn, message} = result; | ||
const location = { | ||
start: { | ||
line, | ||
column | ||
} | ||
}; | ||
|
||
if (typeof endLine === 'number' && typeof endColumn === 'number') { | ||
location.end = { | ||
line: endLine, | ||
column: endColumn | ||
}; | ||
} | ||
|
||
return `\n${visualizeRange(text, location, message)}\n`; | ||
} | ||
|
||
class VisualizeRuleTester { | ||
constructor(test, config) { | ||
this.test = test; | ||
this.config = config; | ||
} | ||
|
||
run(ruleId, rule, tests) { | ||
const {test, config} = this; | ||
const linter = new Linter(); | ||
const verifyConfig = { | ||
...config, | ||
rules: { | ||
[ruleId]: 'error' | ||
} | ||
}; | ||
|
||
linter.defineRule(ruleId, rule); | ||
|
||
for (const [index, code] of tests.entries()) { | ||
test(`${ruleId} - #${index + 1}`, t => { | ||
const results = linter.verify(code, verifyConfig); | ||
|
||
if (results.length !== 1) { | ||
throw new Error('Visualize test should has exactly one error.'); | ||
} | ||
|
||
const [error] = results; | ||
|
||
if (error.fatal) { | ||
throw new Error(error.message); | ||
} | ||
|
||
t.snapshot(visualizeEslintResult(code, error)); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
function visualizeRuleTester(test, config) { | ||
return new VisualizeRuleTester(test, config); | ||
} | ||
|
||
module.exports = visualizeRuleTester; |