-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { DiagnosticSeverity } from 'vscode-languageserver-protocol'; | ||
import { expect } from './chai-config.spec'; | ||
|
||
import { DiagnosticSeverityAdjuster } from './DiagnosticSeverityAdjuster'; | ||
import type { BsDiagnostic } from './interfaces'; | ||
|
||
describe('DiagnosticSeverityAdjuster', () => { | ||
const adjuster = new DiagnosticSeverityAdjuster(); | ||
|
||
it('supports empty map', () => { | ||
const actual = adjuster.createSeverityMap({}); | ||
expect(Array.from(actual.keys()).length === 0); | ||
}); | ||
|
||
it('maps strings to enums', () => { | ||
const actual = adjuster.createSeverityMap({ | ||
'a': 'error', | ||
'b': 'warn', | ||
'c': 'info', | ||
1001: 'hint', | ||
// @ts-expect-error using invalid key | ||
'e': 'foo', | ||
// @ts-expect-error using invalid key | ||
'f': 42 | ||
}); | ||
expect(actual.get('a')).to.equal(DiagnosticSeverity.Error); | ||
expect(actual.get('b')).to.equal(DiagnosticSeverity.Warning); | ||
expect(actual.get('c')).to.equal(DiagnosticSeverity.Information); | ||
expect(actual.get('1001')).to.equal(DiagnosticSeverity.Hint); | ||
expect(actual.get('e')).to.equal(undefined); | ||
expect(actual.get('f')).to.equal(undefined); | ||
}); | ||
|
||
it('adjusts severity', () => { | ||
const diagnostics = [ | ||
{ | ||
code: 'BSLINT1001', | ||
severity: DiagnosticSeverity.Error | ||
} as BsDiagnostic, { | ||
code: 1001, | ||
severity: DiagnosticSeverity.Error | ||
} as BsDiagnostic | ||
]; | ||
adjuster.adjust({ | ||
severityOverride: { | ||
'BSLINT1001': 'warn', | ||
1001: 'info' | ||
} | ||
}, diagnostics); | ||
expect(diagnostics[0].severity).to.equal(DiagnosticSeverity.Warning); | ||
expect(diagnostics[1].severity).to.equal(DiagnosticSeverity.Information); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { DiagnosticSeverity } from 'vscode-languageserver-protocol'; | ||
import type { BsConfig } from './BsConfig'; | ||
import type { BsDiagnostic } from './interfaces'; | ||
|
||
export class DiagnosticSeverityAdjuster { | ||
public adjust(options: BsConfig, diagnostics: BsDiagnostic[]): void { | ||
const map = this.createSeverityMap(options.severityOverride); | ||
|
||
diagnostics.forEach(diagnostic => { | ||
const code = String(diagnostic.code); | ||
if (map.has(code)) { | ||
diagnostic.severity = map.get(code); | ||
} | ||
}); | ||
} | ||
|
||
public createSeverityMap(severityOverride: BsConfig['severityOverride']): Map<string, DiagnosticSeverity> { | ||
const map = new Map<string, DiagnosticSeverity>(); | ||
Object.keys(severityOverride).forEach(key => { | ||
const value = severityOverride[key]; | ||
switch (value) { | ||
case 'error': | ||
map.set(key, DiagnosticSeverity.Error); | ||
break; | ||
case 'warn': | ||
map.set(key, DiagnosticSeverity.Warning); | ||
break; | ||
case 'info': | ||
map.set(key, DiagnosticSeverity.Information); | ||
break; | ||
case 'hint': | ||
map.set(key, DiagnosticSeverity.Hint); | ||
break; | ||
} | ||
}); | ||
return map; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters