Skip to content
Permalink
Browse files

New: Severity with "default" value for hints

  • Loading branch information
molant committed Nov 3, 2019
1 parent c981d9d commit d62df35cb7794746bf8b9f9b08937dc40b6a2438
@@ -39,7 +39,7 @@ export const getSeverity = (config: HintConfig | HintConfig[]): Severity | null
configuredSeverity = getSeverity(config[0]);
}

if (configuredSeverity !== null && configuredSeverity >= 0 && configuredSeverity <= 4) {
if (configuredSeverity !== null && configuredSeverity >= 0 && configuredSeverity <= 5) {
return configuredSeverity;
}

@@ -11,7 +11,8 @@
"hint",
"information",
"warning",
"error"
"error",
"default"
]
},
"errorlevelnumber": {
@@ -21,7 +22,8 @@
1,
2,
3,
4
4,
5
]
},
"hintconfig": {
@@ -135,6 +135,15 @@ export class HintContext<E extends Events = Events> {
sourceCode = getHTMLCodeSnippet(element);
}

/**
* By default all hints get configured with `default` so they can
* decide the severity of each report unless it's overriden by the
* user.
*/
const finalSeverity = this.severity !== Severity.default ?
this.severity :
severity;

/*
* If location is undefined or equal to null, `position` will be set as `{ column: -1, line: -1 }` later in `hint.report`.
* So pass the `location` on as it is.
@@ -147,7 +156,7 @@ export class HintContext<E extends Events = Events> {
location: position || { column: -1, line: -1 },
message,
resource,
severity: this.severity || severity,
severity: finalSeverity,
sourceCode: codeSnippet || sourceCode || ''
});
}
@@ -7,7 +7,7 @@ import { Severity } from '../types/problems';
* to objects or if an object is passed, it returns it.
*/

const DEFAULT_HINT_LEVEL = 'error';
const DEFAULT_HINT_LEVEL = Severity.default;

const shortHandHintPrefixes: {[prefix: string]: keyof typeof Severity | undefined} = {
'-': 'off',
@@ -47,7 +47,7 @@ const normalizeHint = (hint: string): NormalizedHint => {
/**
* Normalized all hints passed as configuration
* Ex.:
* * ["hint1"] => { "hint1": "error" }
* * ["hint1"] => { "hint1": "default" }
* * { "hint1": "warning" } => { "hint1": "warning" }
* * ["hint1:warning"] => { "hint1": "warning" }
*/
@@ -9,7 +9,8 @@ export enum Severity {
hint = 1,
information = 2,
warning = 3,
error = 4
error = 4,
default = 5
}

/** A problem found by a hint */

0 comments on commit d62df35

Please sign in to comment.
You can’t perform that action at this time.