Skip to content

ShellCheck: Ensure parser does not throw an error #749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Bash Language Server

## 4.8.1

- Ensure ShellCheck directive parse does not throw on malformed input https://github.com/bash-lsp/bash-language-server/pull/749

## 4.8.0

- Use ShellCheck directives when analyzing source commands https://github.com/bash-lsp/bash-language-server/pull/747
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A language server for Bash",
"author": "Mads Hartmann",
"license": "MIT",
"version": "4.8.0",
"version": "4.8.1",
"main": "./out/server.js",
"typings": "./out/server.d.ts",
"bin": {
Expand Down
11 changes: 11 additions & 0 deletions server/src/shellcheck/__tests__/directive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,15 @@ describe('parseShellCheckDirective', () => {
it('parses a line with no directive', () => {
expect(parseShellCheckDirective('# foo bar')).toEqual([])
})

it('does not throw on invalid directives', () => {
expect(parseShellCheckDirective('# shellcheck')).toEqual([])
expect(parseShellCheckDirective('# shellcheck disable = ')).toEqual([])
expect(parseShellCheckDirective('# shellcheck disable=SC2-SC1')).toEqual([
{ type: 'disable', rules: [] },
])
expect(parseShellCheckDirective('# shellcheck disable=SC0-SC-1')).toEqual([
{ type: 'disable', rules: ['SC0-SC-1'] },
])
})
})
2 changes: 1 addition & 1 deletion server/src/shellcheck/directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function parseShellCheckDirective(line: string): Directive[] {
? (typeKey as DirectiveType)
: null

if (!type) {
if (!type || !directiveValue) {
continue
}

Expand Down