From 70b9d9f4bb2408dfcd6465d9562f2dd3b4b6db78 Mon Sep 17 00:00:00 2001 From: junstyle Date: Thu, 15 Aug 2024 21:46:20 +0800 Subject: [PATCH] fix --rules on linux os --- index.js | 9 ++++++++- package.json | 2 +- src/index.ts | 10 +++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index f724e0d..b81a6fa 100644 --- a/index.js +++ b/index.js @@ -18455,7 +18455,14 @@ var PHPCSFixer = class extends PHPCSFixerConfig { } } if (!useConfig && this.rules) { - args.push('--rules="' + this.rules.replace(/"/g, '\\"') + '"'); + let rules = this.rules; + 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); } if (this.allowRisky) { args.push("--allow-risky=yes"); diff --git a/package.json b/package.json index 01557eb..8bbb56e 100644 --- a/package.json +++ b/package.json @@ -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.17", + "version": "0.3.18", "publisher": "junstyle", "author": "junstyle", "license": "ISC", diff --git a/src/index.ts b/src/index.ts index 3d2f0d2..ebb93a4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -152,9 +152,13 @@ class PHPCSFixer extends PHPCSFixerConfig { } } if (!useConfig && this.rules) { - const rules = process.platform === 'win32' - ? ('"' + (this.rules as string).replace(/"/g, "\\\"") + '"') - : 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) } if (this.allowRisky) {