Skip to content
Permalink
Browse files
Update: reporting loc for never option in eol-last (refs #12334) (#…
…14840)

* Chore: assertions on reporting loc in `eol-last` (refs #12334)

* Update: improve end report location for `never` option in eol-last
  • Loading branch information
snitin315 committed Aug 21, 2021
1 parent f110926 commit 3d7d5fb32425e8c04d3eaa0107a2ab03a2e285df
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 13 deletions.
@@ -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,
@@ -55,76 +55,160 @@ ruleTester.run("eol-last", rule, {
{
code: "var a = 123;",
output: "var a = 123;\n",
errors: [{ messageId: "missing", type: "Program" }]
errors: [{
messageId: "missing",
type: "Program",
line: 1,
column: 13,
endLine: void 0,
endColumn: void 0
}]
},
{
code: "var a = 123;\n ",
output: "var a = 123;\n \n",
errors: [{ messageId: "missing", type: "Program" }]
errors: [{
messageId: "missing",
type: "Program",
line: 2,
column: 4,
endLine: void 0,
endColumn: void 0
}]
},
{
code: "var a = 123;\n",
output: "var a = 123;",
options: ["never"],
errors: [{ messageId: "unexpected", type: "Program" }]
errors: [{
messageId: "unexpected",
type: "Program",
line: 1,
column: 13,
endLine: 2,
endColumn: 1
}]
},
{
code: "var a = 123;\r\n",
output: "var a = 123;",
options: ["never"],
errors: [{ messageId: "unexpected", type: "Program" }]
errors: [{
messageId: "unexpected",
type: "Program",
line: 1,
column: 13,
endLine: 2,
endColumn: 1
}]
},
{
code: "var a = 123;\r\n\r\n",
output: "var a = 123;",
options: ["never"],
errors: [{ messageId: "unexpected", type: "Program" }]
errors: [{
messageId: "unexpected",
type: "Program",
line: 2,
column: 1,
endLine: 3,
endColumn: 1
}]
},
{
code: "var a = 123;\nvar b = 456;\n",
output: "var a = 123;\nvar b = 456;",
options: ["never"],
errors: [{ messageId: "unexpected", type: "Program" }]
errors: [{
messageId: "unexpected",
type: "Program",
line: 2,
column: 13,
endLine: 3,
endColumn: 1
}]
},
{
code: "var a = 123;\r\nvar b = 456;\r\n",
output: "var a = 123;\r\nvar b = 456;",
options: ["never"],
errors: [{ messageId: "unexpected", type: "Program" }]
errors: [{
messageId: "unexpected",
type: "Program",
line: 2,
column: 13,
endLine: 3,
endColumn: 1
}]
},
{
code: "var a = 123;\n\n",
output: "var a = 123;",
options: ["never"],
errors: [{ messageId: "unexpected", type: "Program" }]
errors: [{
messageId: "unexpected",
type: "Program",
line: 2,
column: 1,
endLine: 3,
endColumn: 1
}]
},

// Deprecated: `"unix"` parameter
{
code: "var a = 123;",
output: "var a = 123;\n",
options: ["unix"],
errors: [{ messageId: "missing", type: "Program" }]
errors: [{
messageId: "missing",
type: "Program",
line: 1,
column: 13,
endLine: void 0,
endColumn: void 0
}]
},
{
code: "var a = 123;\n ",
output: "var a = 123;\n \n",
options: ["unix"],
errors: [{ messageId: "missing", type: "Program" }]
errors: [{
messageId: "missing",
type: "Program",
line: 2,
column: 4,
endLine: void 0,
endColumn: void 0
}]
},

// Deprecated: `"windows"` parameter
{
code: "var a = 123;",
output: "var a = 123;\r\n",
options: ["windows"],
errors: [{ messageId: "missing", type: "Program" }]
errors: [{
messageId: "missing",
type: "Program",
line: 1,
column: 13,
endLine: void 0,
endColumn: void 0
}]
},
{
code: "var a = 123;\r\n ",
output: "var a = 123;\r\n \r\n",
options: ["windows"],
errors: [{ messageId: "missing", type: "Program" }]
errors: [{
messageId: "missing",
type: "Program",
line: 2,
column: 4,
endLine: void 0,
endColumn: void 0
}]
}
]
});

0 comments on commit 3d7d5fb

Please sign in to comment.