Skip to content

Commit

Permalink
optimize code: #218 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
junstyle committed Sep 1, 2024
1 parent 70b9d9f commit cef4da2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "php-cs-fixer",
"displayName": "php cs fixer",
"description": "PHP CS Fixer extension for VS Code, php formatter, php code beautify tool, format html",
"version": "0.3.18",
"version": "0.3.19",
"publisher": "junstyle",
"author": "junstyle",
"license": "ISC",
Expand Down Expand Up @@ -168,6 +168,7 @@
},
"devDependencies": {
"@types/node": "^16.11.43",
"@types/vscode": "1.56.0"
"@types/vscode": "1.56.0",
"esbuild": "^0.21.4"
}
}
9 changes: 1 addition & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,7 @@ class PHPCSFixer extends PHPCSFixerConfig {
}
}
if (!useConfig && this.rules) {
let rules = this.rules as string
if (process.platform === 'win32') {
rules = '"' + rules.replace(/"/g, "\\\"") + '"'
} else {
rules = rules.replace(/\s+/g, '')
statusInfo("rules can't contain whitespaces on linux os!")
}
args.push('--rules=' + rules)
args.push('--rules="' + (this.rules as string).replace(/"/g, "\\\"") + '"')
}
if (this.allowRisky) {
args.push('--allow-risky=yes')
Expand Down
8 changes: 3 additions & 5 deletions src/runAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import { spawn, SpawnOptionsWithoutStdio } from 'child_process';
import { output } from './output';

export function runAsync(command: string, args: string[], options: SpawnOptionsWithoutStdio, onData: (data: Buffer) => void = null) {
const cpOptions = Object.assign({}, options, { shell: process.platform == 'win32', })
const cpOptions = Object.assign({}, options, { shell: true })
let cp;
try {
if (process.platform == 'win32') {
if (command.includes(" ") && command[0] != '"') {
command = '"' + command + '"'
}
if (command.includes(" ") && command[0] != '"') {
command = '"' + command + '"'
}

output('runAsync: spawn ' + command);
Expand Down

0 comments on commit cef4da2

Please sign in to comment.