Skip to content

Commit 0177b50

Browse files
authored
fix(rule): correct error reporting on muliple line
fix #77
2 parents 3f65ef8 + ae7e616 commit 0177b50

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/ginger.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ function reporter(context, options = {}) {
6969
)
7070
.forEach((correction) => {
7171
const index = correction.start;
72-
const originalPosition = source.originalPositionFromIndex(index);
72+
const originalIndex = source.originalIndexFromIndex(index);
7373
const originalRange = [
74-
originalPosition.column,
75-
originalPosition.column + correction.length,
74+
originalIndex,
75+
originalIndex + correction.length,
7676
];
7777

7878
// if range is ignored, skip reporting
@@ -89,8 +89,7 @@ function reporter(context, options = {}) {
8989
report(
9090
node,
9191
new RuleError(message, {
92-
line: originalPosition.line - 1,
93-
column: originalPosition.column,
92+
index: originalIndex,
9493
fix,
9594
}),
9695
);

test/ginger.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,16 @@ tester.run('ginger', rule, {
5959
},
6060
],
6161
},
62+
{
63+
text: 'This sentence contains\n newline and errror.',
64+
output: 'This sentence contains\n newline and error.',
65+
errors: [
66+
{
67+
message: 'errror -> error',
68+
line: 2,
69+
column: 14,
70+
},
71+
],
72+
},
6273
],
6374
});

0 commit comments

Comments
 (0)