Skip to content

Commit d34ec64

Browse files
authored
Merge pull request #749 from bash-lsp/parse-shellcheck-directives-v2
ShellCheck: Ensure parser does not throw an error
2 parents 34f77db + 6ec5429 commit d34ec64

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

server/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Bash Language Server
22

3+
## 4.8.1
4+
5+
- Ensure ShellCheck directive parse does not throw on malformed input https://github.com/bash-lsp/bash-language-server/pull/749
6+
37
## 4.8.0
48

59
- Use ShellCheck directives when analyzing source commands https://github.com/bash-lsp/bash-language-server/pull/747

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "A language server for Bash",
44
"author": "Mads Hartmann",
55
"license": "MIT",
6-
"version": "4.8.0",
6+
"version": "4.8.1",
77
"main": "./out/server.js",
88
"typings": "./out/server.d.ts",
99
"bin": {

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)