-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(stylelint): parse lintCommand like argv
- Loading branch information
Showing
5 changed files
with
87 additions
and
15 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packages/vite-plugin-checker/src/checkers/stylelint/argv.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// copied from https://github.com/jonschlinkert/is-plain-object/blob/master/is-plain-object.js | ||
// to make less breaking change, we'll make it a dependency before v1.0.0 | ||
|
||
export { parseArgsStringToArgv as default, parseArgsStringToArgv } | ||
function parseArgsStringToArgv(value: string, env?: string, file?: string): string[] { | ||
// ([^\s'"]([^\s'"]*(['"])([^\3]*?)\3)+[^\s'"]*) Matches nested quotes until the first space outside of quotes | ||
|
||
// [^\s'"]+ or Match if not a space ' or " | ||
|
||
// (['"])([^\5]*?)\5 or Match "quoted text" without quotes | ||
// `\3` and `\5` are a backreference to the quote style (' or ") captured | ||
const myRegexp = /([^\s'"]([^\s'"]*(['"])([^\3]*?)\3)+[^\s'"]*)|[^\s'"]+|(['"])([^\5]*?)\5/gi | ||
const myString = value | ||
const myArray: string[] = [] | ||
if (env) { | ||
myArray.push(env) | ||
} | ||
if (file) { | ||
myArray.push(file) | ||
} | ||
let match: RegExpExecArray | null | ||
do { | ||
// Each call to exec returns the next regex match as an array | ||
match = myRegexp.exec(myString) | ||
if (match !== null) { | ||
// Index 1 in the array is the captured group if it exists | ||
// Index 0 is the matched text, which we use if no captured group exists | ||
myArray.push(firstString(match[1], match[6], match[0])!) | ||
} | ||
} while (match !== null) | ||
|
||
return myArray | ||
} | ||
|
||
// Accepts any number of arguments, and returns the first one that is a string | ||
// (even an empty string) | ||
// @ts-ignore | ||
function firstString(...args: Array<any>): string | undefined { | ||
// eslint-disable-next-line @typescript-eslint/prefer-for-of | ||
for (let i = 0; i < args.length; i++) { | ||
const arg = args[i] | ||
if (typeof arg === 'string') { | ||
return arg | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters