Skip to content

Commit

Permalink
Update: improve end report location for never option in eol-last
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Aug 2, 2021
1 parent 34aee75 commit 3ddb815
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
7 changes: 6 additions & 1 deletion lib/rules/eol-last.js
Expand Up @@ -86,10 +86,15 @@ module.exports = {
});
} else if (mode === "never" && endsWithNewline) {

const secondLastLine = sourceCode.lines[sourceCode.lines.length - 2];

// File is newline-terminated, but shouldn't be
context.report({
node,
loc: location,
loc: {
start: { line: sourceCode.lines.length - 1, column: secondLastLine.length },
end: { line: sourceCode.lines.length, column: 0 }
},
messageId: "unexpected",
fix(fixer) {
const finalEOLs = /(?:\r?\n)+$/u,
Expand Down
44 changes: 22 additions & 22 deletions tests/lib/rules/eol-last.js
Expand Up @@ -83,10 +83,10 @@ ruleTester.run("eol-last", rule, {
errors: [{
messageId: "unexpected",
type: "Program",
line: 2,
column: 1,
endLine: void 0,
endColumn: void 0
line: 1,
column: 13,
endLine: 2,
endColumn: 1
}]
},
{
Expand All @@ -96,10 +96,10 @@ ruleTester.run("eol-last", rule, {
errors: [{
messageId: "unexpected",
type: "Program",
line: 2,
column: 1,
endLine: void 0,
endColumn: void 0
line: 1,
column: 13,
endLine: 2,
endColumn: 1
}]
},
{
Expand All @@ -109,10 +109,10 @@ ruleTester.run("eol-last", rule, {
errors: [{
messageId: "unexpected",
type: "Program",
line: 3,
line: 2,
column: 1,
endLine: void 0,
endColumn: void 0
endLine: 3,
endColumn: 1
}]
},
{
Expand All @@ -122,10 +122,10 @@ ruleTester.run("eol-last", rule, {
errors: [{
messageId: "unexpected",
type: "Program",
line: 3,
column: 1,
endLine: void 0,
endColumn: void 0
line: 2,
column: 13,
endLine: 3,
endColumn: 1
}]
},
{
Expand All @@ -135,10 +135,10 @@ ruleTester.run("eol-last", rule, {
errors: [{
messageId: "unexpected",
type: "Program",
line: 3,
column: 1,
endLine: void 0,
endColumn: void 0
line: 2,
column: 13,
endLine: 3,
endColumn: 1
}]
},
{
Expand All @@ -148,10 +148,10 @@ ruleTester.run("eol-last", rule, {
errors: [{
messageId: "unexpected",
type: "Program",
line: 3,
line: 2,
column: 1,
endLine: void 0,
endColumn: void 0
endLine: 3,
endColumn: 1
}]
},

Expand Down

0 comments on commit 3ddb815

Please sign in to comment.