Skip to content

Commit 968678a

Browse files
committed
Fix toWSLPath to support spaces
1 parent 8cdfab5 commit 968678a

5 files changed

Lines changed: 24 additions & 9 deletions

File tree

.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+
- java@17.0.10
23
- node@22.2.0
4+
- python@3.11.11
35
tools:
6+
- eslint@8.57.0
7+
- lizard@1.17.31
48
- pmd@6.55.0
59
- semgrep@1.78.0
6-
- eslint@8.57.0
7-
- trivy@0.59.1
10+
- trivy@0.66.0

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ codacy-vscode-extension-CHANGELOG.txt
4545

4646
#Ignore vscode AI rules
4747
.github/instructions/codacy.instructions.md
48+
49+
50+
#Ignore vscode AI rules
51+
.github\instructions\codacy.instructions.md

src/cli/WinWSLCodacyCli.ts

Lines changed: 11 additions & 4 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,20 +11,26 @@ 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(' ', '\\ ').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

1723
private static fromWSLPath(path: string): string {
1824
// Convert WSL path to Windows path while keeping quotes
1925
// Example: '/mnt/c/Users/user/project' -> 'C:\Users\user\project'
20-
const windowsPath = path.replace(/^'\/mnt\/([a-zA-Z])/, "'$1:").replace('\\ ',' ',).replace(/\//g, '\\')
26+
const windowsPath = path.replace(/^'\/mnt\/([a-zA-Z])/, "'$1:").replace(/\//g, '\\')
2127
return windowsPath
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}'`
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)