-
Notifications
You must be signed in to change notification settings - Fork 27.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "refactor: remove unnecessary
lint-staged
operations (#65861)"
This reverts partial commit 0558f61.
- Loading branch information
1 parent
750ae91
commit 6d6aa50
Showing
1 changed file
with
51 additions
and
8 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,10 +1,53 @@ | ||
const { quote } = require('shell-quote') | ||
const { ESLint } = require('eslint') | ||
|
||
const eslint = new ESLint() | ||
|
||
/** | ||
* Escape filenames to ensure that spaces and such aren't interpreted as | ||
* separators. | ||
* | ||
* @param {string[]} filenames | ||
* @returns {string[]} | ||
*/ | ||
function escape(filenames) { | ||
if (process.platform === 'win32') { | ||
return filenames | ||
} | ||
|
||
return filenames.map((filename) => quote([filename]).replace(/\\@/g, '@')) | ||
} | ||
|
||
module.exports = { | ||
'*.{js,jsx,mjs,ts,tsx,mts}': [ | ||
'prettier --with-node-modules --ignore-path .prettierignore --write', | ||
'eslint --no-ignore --max-warnings=0 --fix', | ||
], | ||
'*.{json,md,mdx,css,html,yml,yaml,scss}': [ | ||
'prettier --with-node-modules --ignore-path .prettierignore --write', | ||
], | ||
'*.rs': ['cargo fmt --'], | ||
'**/*.{js,jsx,mjs,ts,tsx,mts}': async (filenames) => { | ||
const escapedFileNames = escape(filenames).join(' ') | ||
const eslintFileNames = await Promise.all( | ||
filenames.map(async (filename) => { | ||
const ignored = await eslint.isPathIgnored(filename) | ||
return ignored ? null : filename | ||
}) | ||
) | ||
|
||
return [ | ||
`prettier --with-node-modules --ignore-path .prettierignore --write ${escapedFileNames}`, | ||
`eslint --no-ignore --max-warnings=0 --fix ${eslintFileNames | ||
.filter((filename) => filename !== null) | ||
.map((filename) => { | ||
return `"${filename}"` | ||
}) | ||
.join(' ')}`, | ||
`git add ${escapedFileNames}`, | ||
] | ||
}, | ||
'**/*.{json,md,mdx,css,html,yml,yaml,scss}': (filenames) => { | ||
const escapedFileNames = escape(filenames).join(' ') | ||
return [ | ||
`prettier --with-node-modules --ignore-path .prettierignore --write ${escapedFileNames}`, | ||
`git add ${escapedFileNames}`, | ||
] | ||
}, | ||
'**/*.rs': (filenames) => { | ||
const escapedFileNames = escape(filenames).join(' ') | ||
return [`cargo fmt -- ${escapedFileNames}`, `git add ${escapedFileNames}`] | ||
}, | ||
} |