Skip to content

Commit 284ab9d

Browse files
committed
Ensure parser does not throw an error
1 parent 34f77db commit 284ab9d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

server/src/shellcheck/__tests__/directive.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,15 @@ describe('parseShellCheckDirective', () => {
132132
it('parses a line with no directive', () => {
133133
expect(parseShellCheckDirective('# foo bar')).toEqual([])
134134
})
135+
136+
it('does not throw on invalid directives', () => {
137+
expect(parseShellCheckDirective('# shellcheck')).toEqual([])
138+
expect(parseShellCheckDirective('# shellcheck disable = ')).toEqual([])
139+
expect(parseShellCheckDirective('# shellcheck disable=SC2-SC1')).toEqual([
140+
{ type: 'disable', rules: [] },
141+
])
142+
expect(parseShellCheckDirective('# shellcheck disable=SC0-SC-1')).toEqual([
143+
{ type: 'disable', rules: ['SC0-SC-1'] },
144+
])
145+
})
135146
})

server/src/shellcheck/directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function parseShellCheckDirective(line: string): Directive[] {
4545
? (typeKey as DirectiveType)
4646
: null
4747

48-
if (!type) {
48+
if (!type || !directiveValue) {
4949
continue
5050
}
5151

0 commit comments

Comments
 (0)