bash-language-server
Advanced tools
Comparing version 5.1.1 to 5.1.2
# Bash Language Server | ||
## 5.1.2 | ||
- Use shellcheck's shell directive for selecting the dialect https://github.com/bash-lsp/bash-language-server/pull/1081 | ||
## 5.1.1 | ||
@@ -4,0 +8,0 @@ |
@@ -5,2 +5,3 @@ declare const BASH_DIALECTS: readonly ["sh", "bash", "dash", "ksh", "zsh", "csh", "ash"]; | ||
export declare function getShellDialect(shebang: string): BashDialect | null; | ||
export declare function getShellDialectFromShellDirective(fileContent: string): BashDialect | null; | ||
export declare function analyzeShebang(fileContent: string): { | ||
@@ -7,0 +8,0 @@ shellDialect: BashDialect | null; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.analyzeShebang = exports.getShellDialect = exports.getShebang = void 0; | ||
exports.analyzeShebang = exports.getShellDialectFromShellDirective = exports.getShellDialect = exports.getShebang = void 0; | ||
const SHEBANG_REGEXP = /^#!(.*)/; | ||
@@ -8,2 +8,3 @@ const SHELL_REGEXP = /bin[/](?:env )?(\w+)/; | ||
const BASH_DIALECTS = ['sh', 'bash', 'dash', 'ksh', 'zsh', 'csh', 'ash']; | ||
const SHELL_DIRECTIVE_REGEXP = new RegExp(`^\\s*#\\s*shellcheck.*shell=(${BASH_DIALECTS.join('|')}).*$|^\\s*#.*$|^\\s*$`); | ||
function getShebang(fileContent) { | ||
@@ -28,7 +29,25 @@ const match = SHEBANG_REGEXP.exec(fileContent); | ||
exports.getShellDialect = getShellDialect; | ||
function getShellDialectFromShellDirective(fileContent) { | ||
const contentLines = fileContent.split('\n'); | ||
for (const line of contentLines) { | ||
const match = SHELL_DIRECTIVE_REGEXP.exec(line); | ||
if (match === null) { | ||
break; | ||
} | ||
if (match[1]) { | ||
const bashDialect = match[1].trim(); | ||
if (BASH_DIALECTS.includes(bashDialect)) { | ||
return bashDialect; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
exports.getShellDialectFromShellDirective = getShellDialectFromShellDirective; | ||
function analyzeShebang(fileContent) { | ||
var _a; | ||
const shebang = getShebang(fileContent); | ||
return { | ||
shebang, | ||
shellDialect: shebang ? getShellDialect(shebang) : null, | ||
shellDialect: (_a = getShellDialectFromShellDirective(fileContent)) !== null && _a !== void 0 ? _a : (shebang ? getShellDialect(shebang) : null), | ||
}; | ||
@@ -35,0 +54,0 @@ } |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "5.1.1", | ||
"version": "5.1.2", | ||
"main": "./out/server.js", | ||
@@ -35,3 +35,3 @@ "typings": "./out/server.d.ts", | ||
"@types/fuzzy-search": "2.1.5", | ||
"@types/node-fetch": "2.6.9", | ||
"@types/node-fetch": "2.6.10", | ||
"@types/turndown": "5.0.4", | ||
@@ -38,0 +38,0 @@ "@types/urijs": "1.19.25" |
@@ -82,3 +82,3 @@ # Bash Language Server | ||
\ 'name': 'bash-language-server', | ||
\ 'cmd': {server_info->[&shell, &shellcmdflag, 'bash-language-server start']}, | ||
\ 'cmd': {server_info->['bash-language-server', 'start']}, | ||
\ 'allowlist': ['sh', 'bash'], | ||
@@ -85,0 +85,0 @@ \ }) |
@@ -19,3 +19,3 @@ import { pathToFileURL } from 'node:url' | ||
// if you add a .sh file to testing/fixtures, update this value | ||
const FIXTURE_FILES_MATCHING_GLOB = 17 | ||
const FIXTURE_FILES_MATCHING_GLOB = 18 | ||
@@ -22,0 +22,0 @@ const defaultConfig = getDefaultConfiguration() |
@@ -0,1 +1,2 @@ | ||
import { FIXTURE_DOCUMENT } from '../../../../testing/fixtures' | ||
import { analyzeShebang } from '../shebang' | ||
@@ -38,2 +39,26 @@ | ||
}) | ||
it('returns shell dialect from shell directive', () => { | ||
expect(analyzeShebang('# shellcheck shell=dash')).toEqual({ | ||
shellDialect: 'dash', | ||
shebang: null, | ||
}) | ||
}) | ||
it('returns shell dialect when multiple directives are passed', () => { | ||
expect( | ||
analyzeShebang( | ||
'# shellcheck enable=require-variable-braces shell=dash disable=SC1000', | ||
), | ||
).toEqual({ | ||
shellDialect: 'dash', | ||
shebang: null, | ||
}) | ||
}) | ||
it('shell directive overrides file extension and shebang', () => { | ||
expect( | ||
analyzeShebang(FIXTURE_DOCUMENT.SHELLCHECK_SHELL_DIRECTIVE.getText()), | ||
).toHaveProperty('shellDialect', 'sh') | ||
}) | ||
}) |
@@ -8,2 +8,6 @@ const SHEBANG_REGEXP = /^#!(.*)/ | ||
const SHELL_DIRECTIVE_REGEXP = new RegExp( | ||
`^\\s*#\\s*shellcheck.*shell=(${BASH_DIALECTS.join('|')}).*$|^\\s*#.*$|^\\s*$`, | ||
) | ||
export function getShebang(fileContent: string): string | null { | ||
@@ -30,2 +34,21 @@ const match = SHEBANG_REGEXP.exec(fileContent) | ||
export function getShellDialectFromShellDirective( | ||
fileContent: string, | ||
): BashDialect | null { | ||
const contentLines = fileContent.split('\n') | ||
for (const line of contentLines) { | ||
const match = SHELL_DIRECTIVE_REGEXP.exec(line) | ||
if (match === null) { | ||
break | ||
} | ||
if (match[1]) { | ||
const bashDialect = match[1].trim() as any | ||
if (BASH_DIALECTS.includes(bashDialect)) { | ||
return bashDialect | ||
} | ||
} | ||
} | ||
return null | ||
} | ||
export function analyzeShebang(fileContent: string): { | ||
@@ -38,4 +61,6 @@ shellDialect: BashDialect | null | ||
shebang, | ||
shellDialect: shebang ? getShellDialect(shebang) : null, | ||
shellDialect: | ||
getShellDialectFromShellDirective(fileContent) ?? | ||
(shebang ? getShellDialect(shebang) : null), | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1124980
12625