Skip to content
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
5 changes: 5 additions & 0 deletions server/src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('ConfigSchema', () => {
"includeAllWorkspaceSymbols": false,
"logLevel": "info",
"shellcheckArguments": [],
"shellcheckExternalSources": true,
"shellcheckPath": "shellcheck",
"shfmt": {
"binaryNextLine": false,
Expand Down Expand Up @@ -62,6 +63,7 @@ describe('ConfigSchema', () => {
"-e",
"SC2002",
],
"shellcheckExternalSources": true,
"shellcheckPath": "",
"shfmt": {
"binaryNextLine": true,
Expand Down Expand Up @@ -99,6 +101,7 @@ describe('getConfigFromEnvironmentVariables', () => {
"includeAllWorkspaceSymbols": false,
"logLevel": "info",
"shellcheckArguments": [],
"shellcheckExternalSources": true,
"shellcheckPath": "shellcheck",
"shfmt": {
"binaryNextLine": false,
Expand Down Expand Up @@ -130,6 +133,7 @@ describe('getConfigFromEnvironmentVariables', () => {
"includeAllWorkspaceSymbols": false,
"logLevel": "info",
"shellcheckArguments": [],
"shellcheckExternalSources": true,
"shellcheckPath": "",
"shfmt": {
"binaryNextLine": false,
Expand Down Expand Up @@ -170,6 +174,7 @@ describe('getConfigFromEnvironmentVariables', () => {
"-e",
"SC2001",
],
"shellcheckExternalSources": true,
"shellcheckPath": "/path/to/shellcheck",
"shfmt": {
"binaryNextLine": false,
Expand Down
8 changes: 7 additions & 1 deletion server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export const ConfigSchema = z.object({
// If true, then all symbols from the workspace are included.
includeAllWorkspaceSymbols: z.boolean().default(false),

// Additional ShellCheck arguments. Note that we already add the following arguments: --shell, --format, --external-sources."
// Controls whether ShellCheck is invoked with --external-sources. When enabled (default),
// ShellCheck follows source directives to lint referenced files. On projects with many
// cross-sourcing scripts this can cause unbounded memory growth. Set to false to disable.
shellcheckExternalSources: z.boolean().default(true),

// Additional ShellCheck arguments. Note that we already add the following arguments: --shell, --format, and --external-sources (if shellcheckExternalSources is true).
shellcheckArguments: z
.preprocess((arg) => {
let argsList: string[] = []
Expand Down Expand Up @@ -87,6 +92,7 @@ export function getConfigFromEnvironmentVariables(): {
includeAllWorkspaceSymbols: toBoolean(process.env.INCLUDE_ALL_WORKSPACE_SYMBOLS),
logLevel: process.env[LOG_LEVEL_ENV_VAR],
shellcheckArguments: process.env.SHELLCHECK_ARGUMENTS,
shellcheckExternalSources: toBoolean(process.env.SHELLCHECK_EXTERNAL_SOURCES),
shellcheckPath: process.env.SHELLCHECK_PATH,
shfmt: {
path: process.env.SHFMT_PATH,
Expand Down
5 changes: 4 additions & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ export default class BashServer {
logger.info('ShellCheck linting is disabled as "shellcheckPath" was not set')
this.linter = undefined
} else {
this.linter = new Linter({ executablePath: shellcheckPath })
this.linter = new Linter({
executablePath: shellcheckPath,
externalSources: this.config.shellcheckExternalSources,
})
}

const shfmtPath = this.config.shfmt?.path
Expand Down
7 changes: 5 additions & 2 deletions server/src/shellcheck/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function safeFileURLToPath(uri: string): string | null {
type LinterOptions = {
executablePath: string
cwd?: string
externalSources?: boolean
}

export type LintingResult = {
Expand All @@ -43,15 +44,17 @@ export type LintingResult = {
export class Linter {
private cwd: string
public executablePath: string
private externalSources: boolean
private uriToDebouncedExecuteLint: {
[uri: string]: InstanceType<typeof Linter>['executeLint']
}
private _canLint: boolean

constructor({ cwd, executablePath }: LinterOptions) {
constructor({ cwd, executablePath, externalSources = true }: LinterOptions) {
this._canLint = true
this.cwd = cwd || process.cwd()
this.executablePath = executablePath
this.externalSources = externalSources
this.uriToDebouncedExecuteLint = Object.create(null)
}

Expand Down Expand Up @@ -139,7 +142,7 @@ export class Linter {

const args = [
'--format=json1',
'--external-sources',
...(this.externalSources ? ['--external-sources'] : []),
...sourcePathsArgs,
...additionalArgs,
]
Expand Down
7 changes: 6 additions & 1 deletion vscode-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,15 @@
"default": "shellcheck",
"description": "Controls the executable used for ShellCheck linting information. An empty string will disable linting."
},
"bashIde.shellcheckExternalSources": {
"type": "boolean",
"default": true,
"description": "Controls whether ShellCheck is invoked with --external-sources. When enabled (default), ShellCheck follows source directives to lint referenced files. On projects with many cross-sourcing scripts this can cause unbounded memory growth. Set to false to disable."
},
"bashIde.shellcheckArguments": {
"type": "string",
"default": "",
"description": "Additional ShellCheck arguments. Note that we already add the following arguments: --shell, --format, --external-sources."
"description": "Additional ShellCheck arguments. Note that we already add the following arguments: --shell, --format, and --external-sources (if shellcheckExternalSources is true)."
},
"bashIde.shfmt.path": {
"type": "string",
Expand Down
Loading