-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add blocklist/allowlist for diagnostics
Summary: Refactor the diagnostics allowlist a bit, and support both allowlist and blocklist. This lets us implement wildcard via an empty blocklist, which is simpler and more general. Reviewed By: madgen Differential Revision: D65459587 fbshipit-source-id: a9ef8be95c9ac191df6a1aefa8fc2d8b99621afd
- Loading branch information
1 parent
4c355b4
commit 9952c5b
Showing
3 changed files
with
148 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import type {DiagnosticAllowlist} from '../types'; | ||
|
||
import {isBlockingDiagnostic} from '../Diagnostics'; | ||
|
||
const range = {startLine: 1, startCol: 1, endLine: 1, endCol: 1}; | ||
|
||
describe('Diagnostics', () => { | ||
describe('isBlockingDiagnostic', () => { | ||
it('handles allowlist', () => { | ||
const policy: DiagnosticAllowlist = new Map([ | ||
['error', new Map([['foo', {allow: new Set(['code1'])}]])], | ||
]); | ||
expect( | ||
isBlockingDiagnostic( | ||
{ | ||
message: 'sample', | ||
range, | ||
severity: 'error', | ||
source: 'foo', | ||
code: 'code1', | ||
}, | ||
policy, | ||
), | ||
).toBe(true); | ||
expect( | ||
isBlockingDiagnostic( | ||
{ | ||
message: 'sample', | ||
range, | ||
severity: 'error', | ||
source: 'foo', | ||
code: 'code3', | ||
}, | ||
policy, | ||
), | ||
).toBe(false); | ||
}); | ||
|
||
it('handles blocklist', () => { | ||
const policy: DiagnosticAllowlist = new Map([ | ||
['error', new Map([['foo', {block: new Set(['code1'])}]])], | ||
]); | ||
expect( | ||
isBlockingDiagnostic( | ||
{ | ||
message: 'sample', | ||
range, | ||
severity: 'error', | ||
source: 'foo', | ||
code: 'code3', | ||
}, | ||
policy, | ||
), | ||
).toBe(true); | ||
expect( | ||
isBlockingDiagnostic( | ||
{ | ||
message: 'sample', | ||
range, | ||
severity: 'error', | ||
source: 'foo', | ||
code: 'code1', | ||
}, | ||
policy, | ||
), | ||
).toBe(false); | ||
}); | ||
|
||
it('handles wildcard', () => { | ||
const policy: DiagnosticAllowlist = new Map([ | ||
['error', new Map([['foo', {block: new Set([])}]])], | ||
]); | ||
expect( | ||
isBlockingDiagnostic( | ||
{ | ||
message: 'sample', | ||
range, | ||
severity: 'error', | ||
source: 'foo', | ||
code: 'code1', | ||
}, | ||
policy, | ||
), | ||
).toBe(true); | ||
}); | ||
|
||
it('ignores non-errors', () => { | ||
const policy: DiagnosticAllowlist = new Map([ | ||
['error', new Map([['foo', {block: new Set([])}]])], | ||
]); | ||
expect( | ||
isBlockingDiagnostic( | ||
{ | ||
message: 'sample', | ||
range, | ||
severity: 'hint', | ||
source: 'foo', | ||
code: 'code1', | ||
}, | ||
policy, | ||
), | ||
).toBe(false); | ||
}); | ||
|
||
it('accepts warnings', () => { | ||
const policy: DiagnosticAllowlist = new Map([ | ||
['warning', new Map([['foo', {block: new Set([])}]])], | ||
]); | ||
expect( | ||
isBlockingDiagnostic( | ||
{ | ||
message: 'sample', | ||
range, | ||
severity: 'warning', | ||
source: 'foo', | ||
code: 'code1', | ||
}, | ||
policy, | ||
), | ||
).toBe(true); | ||
}); | ||
}); | ||
}); |
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