Skip to content

Commit

Permalink
Fixed: Illegal value for line #1
Browse files Browse the repository at this point in the history
  • Loading branch information
vknabel committed Dec 12, 2019
1 parent 5e61c88 commit 03c3e4b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.1

- Fixed: Illegal value for `line` #1

## 1.0.0

- Initial release
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "git",
"url": "https://github.com/vknabel/vscode-swiftlint"
},
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",
"author": {
"name": "Valentin Knabel",
Expand Down
33 changes: 18 additions & 15 deletions src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,33 @@ function reportToPreciseDiagnosticForDocument(
document: TextDocument
): (report: Report) => Diagnostic {
return report => {
const line = document.lineAt(report.line);
try {
const line = document.lineAt(report.line - 1);
let range: Range;
if (report.character === null) {
range = line.range;
} else {
const wordBegin = line.range.start.translate({
characterDelta: report.character
});
range =
document.getWordRangeAtPosition(wordBegin) ||
new Range(wordBegin, wordBegin.translate({ characterDelta: 1 }));
}

let range: Range;
if (report.character === null) {
range = line.range;
} else {
const wordBegin = line.range.start.translate({
characterDelta: report.character
});
range =
document.getWordRangeAtPosition(wordBegin) ||
new Range(wordBegin, wordBegin.translate({ characterDelta: 1 }));
const severity = reportSeverityToDiagnosticSeverity(report.severity);
return new Diagnostic(range, report.reason, severity);
} catch (error) {
throw error;
}

const severity = reportSeverityToDiagnosticSeverity(report.severity);
return new Diagnostic(range, report.reason, severity);
};
}

function reportToSimpleDiagnostic(): (
report: Report
) => { file: string; diagnostic: Diagnostic } {
return report => {
const startPosition = new Position(report.line, report.character || 0);
const startPosition = new Position(report.line - 1, report.character || 0);
const endPosition = startPosition.translate({ characterDelta: 1 });
const range = new Range(startPosition, endPosition);
const severity = reportSeverityToDiagnosticSeverity(report.severity);
Expand Down

0 comments on commit 03c3e4b

Please sign in to comment.