Skip to content

Commit

Permalink
feat: ember-template-lint severity converter (support different sever…
Browse files Browse the repository at this point in the history
…ity kinds)

* supported different kinds of severity from ember-template-lint
  • Loading branch information
lifeart authored Apr 15, 2021
1 parent a602e48 commit be3e923
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/template-linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface TemplateLinterError {
fatal?: boolean;
moduleId: string;
rule?: string;
filePath: string;
severity: number;
message: string;
isFixable?: boolean;
Expand Down
30 changes: 29 additions & 1 deletion src/utils/diagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,37 @@ export function toHbsSource(templateNode: ITemplateNode): string {
return output;
}

function convertEmberTemplateLintSeverity(value: number): DiagnosticSeverity {
// lint values
const TODO_SEVERITY = -1;
const IGNORE_SEVERITY = 0;
const WARNING_SEVERITY = 1;
const ERROR_SEVERITY = 2;

if (value === TODO_SEVERITY) {
return DiagnosticSeverity.Hint;
} else if (value === ERROR_SEVERITY) {
return DiagnosticSeverity.Error;
} else if (value === WARNING_SEVERITY) {
return DiagnosticSeverity.Warning;
} else if (value === IGNORE_SEVERITY) {
return DiagnosticSeverity.Information;
}

return DiagnosticSeverity.Error;
}

function severityForError(error: TemplateLinterError): DiagnosticSeverity {
if (error.rule) {
return convertEmberTemplateLintSeverity(error.severity);
} else {
return DiagnosticSeverity.Error;
}
}

export function toDiagnostic(source: string, error: TemplateLinterError): Diagnostic {
const result = {
severity: DiagnosticSeverity.Error,
severity: severityForError(error),
range: toRange(source, error),
message: toMessage(error),
code: error.rule || 'syntax',
Expand Down

0 comments on commit be3e923

Please # to comment.