Skip to content

Commit 09d906e

Browse files
authored
Merge pull request #164 from codacy/escape-spaces-windows
Escape spaces on windows/wsl
2 parents 0b89705 + 34f8291 commit 09d906e

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

.codacy/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Codacy CLI
1+
# Codacy CLI
22
tools-configs/
33
.gitignore
44
cli-config.yaml
5-
*.sh
5+
logs/

.codacy/codacy.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
runtimes:
2+
23
4+
35
tools:
6+
7+
48
59
6-
7-
10+

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,11 @@ codacy-vscode-extension-CHANGELOG.txt
4141

4242
#Ignore windsurf AI rules
4343
.windsurfrules
44+
45+
46+
#Ignore vscode AI rules
47+
.github/instructions/codacy.instructions.md
48+
49+
50+
#Ignore vscode AI rules
51+
.github\instructions\codacy.instructions.md

src/cli/WinWSLCodacyCli.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { MacCodacyCli } from './MacCodacyCli'
22

3+
34
export class WinWSLCodacyCli extends MacCodacyCli {
45
constructor(rootPath: string, provider?: string, organization?: string, repository?: string) {
56
const winRootPath =
@@ -10,7 +11,12 @@ export class WinWSLCodacyCli extends MacCodacyCli {
1011
private static toWSLPath(path: string): string {
1112
// Convert Windows path to WSL path
1213
// Example: 'C:\Users\user\project' -> '/mnt/c/Users/user/project'
13-
const wslPath = path.replace(/\\/g, '/').replace(/^'([a-zA-Z]):/, "'/mnt/$1")
14+
// First, unescape any escaped spaces (backslash-space -> space)
15+
let cleanPath = path.replace(/^'|'$/g, '')
16+
// Unescape any escaped spaces (backslash-space -> space)
17+
cleanPath = cleanPath.replace(/\\ /g, ' ')
18+
// Then convert backslashes to slashes and add /mnt/ prefix
19+
const wslPath = cleanPath.replace(/\\/g, '/').replace(/^'?([a-zA-Z]):/, '/mnt/$1').replace(/ /g, '\\ ')
1420
return wslPath
1521
}
1622

@@ -22,8 +28,9 @@ export class WinWSLCodacyCli extends MacCodacyCli {
2228
}
2329

2430
protected preparePathForExec(path: string): string {
25-
// Convert the path to WSL format
26-
return WinWSLCodacyCli.toWSLPath(path)
31+
// Convert the path to WSL format and wrap in quotes to handle spaces
32+
const wslPath = WinWSLCodacyCli.toWSLPath(path)
33+
return wslPath.includes(' ') ? `"${wslPath}"` : wslPath;
2734
}
2835

2936
protected async execAsync(

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"sourceMap": true,
1111
"rootDir": "src",
1212
"strict": true,
13-
"allowSyntheticDefaultImports": true
13+
"allowSyntheticDefaultImports": true,
14+
"skipLibCheck": true
1415
},
1516
"include": [
1617
"src/**/*"

0 commit comments

Comments
 (0)