diff --git a/CHANGELOG.md b/CHANGELOG.md index 06323a9..4b7ec9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # Changelog -## Unreleased +## 1.8.0 - removed: `swiftlint.forceExcludePaths` as it didn't work. Use `excluded` in your `.swiftlint` config instead. #39 +- Added: `swiftlint.path` can now be an array of strings and defaults to `[/usr/bin/env, swiftlint]` [vknabel/vscode-apple-swift-format#17](https://github.com/vknabel/vscode-apple-swift-format/issues/17) ## 1.7.3 diff --git a/package.json b/package.json index dd33065..a8d69be 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "git", "url": "https://github.com/vknabel/vscode-swiftlint" }, - "version": "1.7.3", + "version": "1.8.0", "license": "MIT", "author": { "name": "Valentin Knabel", @@ -60,10 +60,29 @@ "description": "Only use SwiftLint when a config exists." }, "swiftlint.path": { - "type": "string", - "default": "/usr/local/bin/swiftlint", "description": "The location of your globally installed SwiftLint.", - "scope": "machine" + "scope": "machine", + "default": [ + "/usr/bin/env", + "swiftlint" + ], + "oneOf": [ + { + "type": "string", + "default": "/usr/local/bin/swiftlint" + }, + { + "type": "array", + "minItems": 1, + "default": [ + "/usr/bin/env", + "swiftlint" + ], + "items": { + "type": "string" + } + } + ] }, "swiftlint.additionalParameters": { "type": "array", diff --git a/src/Current.ts b/src/Current.ts index c8b99a1..06dbee5 100644 --- a/src/Current.ts +++ b/src/Current.ts @@ -27,7 +27,7 @@ export interface Current { onlyEnableWithConfig(): boolean; affectsConfiguration(changeEvent: vscode.ConfigurationChangeEvent): boolean; - swiftLintPath(uri: vscode.Uri): string | null; + swiftLintPath(uri: vscode.Uri): string[] | null; toolchainPath(): string | undefined; additionalParameters(): string[]; resetSwiftLintPath(): void; @@ -113,7 +113,7 @@ export function prodEnvironment(): Current { const fullPath = workspace ? join(workspace!.uri.path, path) : path; if (existsSync(fullPath)) { - return absolutePath(fullPath); + return [absolutePath(fullPath)]; } } @@ -160,12 +160,19 @@ export function prodEnvironment(): Current { }; } -const fallbackGlobalSwiftFormatPath = () => - absolutePath( - vscode.workspace - .getConfiguration() - .get("swiftlint.path", "/usr/local/bin/swiftlint") - ); +const fallbackGlobalSwiftFormatPath = (): string[] => { + const defaultPath = ["/usr/bin/env", "swiftlint"]; + const path = vscode.workspace + .getConfiguration() + .get("swiftlint.path", defaultPath); + if (typeof path === "string") { + return [absolutePath(path)]; + } else if (Array.isArray(path) && path.length > 0) { + return [absolutePath(path[0]), ...path.slice(1)]; + } else { + return defaultPath; + } +}; const Current = prodEnvironment(); export default Current as Current; diff --git a/src/UserInteraction.ts b/src/UserInteraction.ts index 4357029..204c1cc 100644 --- a/src/UserInteraction.ts +++ b/src/UserInteraction.ts @@ -38,7 +38,9 @@ export async function handleFormatError(error: any, uri: vscode.Uri) { } } else if (error.code === "ENOENT") { const selection = await Current.editor.showErrorMessage( - `Could not find SwiftLint: ${Current.config.swiftLintPath(uri)}`, + `Could not find SwiftLint: ${ + Current.config.swiftLintPath(uri)?.join(" ") ?? "null" + }`, FormatErrorInteraction.reset, FormatErrorInteraction.configure ); diff --git a/src/lint.ts b/src/lint.ts index fea1049..7a73bc3 100644 --- a/src/lint.ts +++ b/src/lint.ts @@ -324,12 +324,12 @@ function execSwiftlint(request: { Object.keys(filesEnv) .map((env) => `${env}='${filesEnv[env]}'`) .join(" "), - `'${swiftLintPath}' `, + `'${swiftLintPath.join(" ")}' `, swiftLintArgs?.map((arg) => `'${arg}'`).join(" ") ); const exec = execShell( - swiftLintPath, - swiftLintArgs, + swiftLintPath[0], + [...swiftLintPath.slice(1), ...swiftLintArgs], { encoding: "utf8", maxBuffer: 20 * 1024 * 1024,