Skip to content

Commit

Permalink
Fix to props used for errors
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Apr 16, 2024
1 parent 9365080 commit b4da184
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cli/rpglint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ async function main() {

try {
const content = readFileSync(filePath, { encoding: `utf-8` });
const eol = content.includes(`\r\n`) ? `\r\n` : `\n`;
const eolIndexes: number[] = [];

for (let i = 0; i < content.length; i++) {
if (content.substring(i, i + eol.length) === eol) {
eolIndexes.push(i);
}
}

if (content.length > 6 && content.substring(0, 6).toLowerCase() === `**free`) {
const docs = await parser.getDocs(
Expand Down Expand Up @@ -145,7 +153,9 @@ async function main() {

if (lintResult.errors.length) {
lintResult.errors.forEach(error => {
console.log(`${filePath}:${error.range.start.line + 1}:${error.range.start.character}:${Linter.getErrorText(error.type)}`);
const line = eolIndexes.findIndex(index => index > error.offset.position);
const offset = error.offset.position - (eolIndexes[line-1] || 0);
console.log(`${filePath}:${line+1}:${offset}:${Linter.getErrorText(error.type)}`);
});
}
break;
Expand All @@ -162,7 +172,9 @@ async function main() {

if (lintResult.errors.length) {
lintResult.errors.forEach(error => {
console.log(`\tLine ${error.range.start.line + 1}, column ${error.range.start.character}: ${Linter.getErrorText(error.type)}`);
const line = eolIndexes.findIndex(index => index > error.offset.position);
const offset = error.offset.position - (eolIndexes[line-1] || 0);
console.log(`\tLine ${line+1}, column ${offset}: ${Linter.getErrorText(error.type)}`);
});
}
break;
Expand Down

0 comments on commit b4da184

Please sign in to comment.