Skip to content

Commit

Permalink
filename-case: Improve report position (#1227)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Apr 28, 2021
1 parent aa272af commit 3d4ac1b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
6 changes: 4 additions & 2 deletions rules/filename-case.js
Expand Up @@ -158,7 +158,7 @@ const create = context => {
}

return {
Program: node => {
Program() {
const extension = path.extname(filenameWithExtension);
const filename = path.basename(filenameWithExtension, extension);
const base = filename + extension;
Expand All @@ -180,7 +180,9 @@ const create = context => {
});

context.report({
node,
// Report on first character like `unicode-bom` rule
// https://github.com/eslint/eslint/blob/8a77b661bc921c3408bae01b3aa41579edfc6e58/lib/rules/unicode-bom.js#L46
loc: {column: 0, line: 1},
messageId: MESSAGE_ID,
data: {
chosenCases: englishishJoinWords(chosenCases.map(x => cases[x].name)),
Expand Down
10 changes: 10 additions & 0 deletions test/filename-case.mjs
Expand Up @@ -538,3 +538,13 @@ test({
)
]
});

test.snapshot({
valid: [],
invalid: [
{
code: 'foo();\n'.repeat(10),
filename: 'src/foo/foo_bar.js'
}
]
});
35 changes: 35 additions & 0 deletions test/snapshots/filename-case.mjs.md
@@ -0,0 +1,35 @@
# Snapshot report for `test/filename-case.mjs`

The actual snapshot is saved in `filename-case.mjs.snap`.

Generated by [AVA](https://avajs.dev).

## Invalid #1
1 | foo();
2 | foo();
3 | foo();
4 | foo();
5 | foo();
6 | foo();
7 | foo();
8 | foo();
9 | foo();
10 | foo();
11 |

> Error 1/1
`␊
> 1 | foo();␊
| ^ Filename is not in kebab case. Rename it to \`foo-bar.js\`.␊
2 | foo();␊
3 | foo();␊
4 | foo();␊
5 | foo();␊
6 | foo();␊
7 | foo();␊
8 | foo();␊
9 | foo();␊
10 | foo();␊
11 |␊
`
Binary file added test/snapshots/filename-case.mjs.snap
Binary file not shown.

0 comments on commit 3d4ac1b

Please sign in to comment.