-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove unnecessary
lint-staged
operations (#65861)
### Why? The current `lint-staged` hook uses [function signature](https://github.com/lint-staged/lint-staged?tab=readme-ov-file#function-signature) to target the **staged files** and has extra steps for handling those files that seem to have been passed on from a [5-year-old legacy code](#9245). The entire process is unnecessary today since `lint-staged` only runs on the staged files. ### How? This PR removed unnecessary logic, removed some no-effect flags, and [removed `git add`](https://github.com/lint-staged/lint-staged?tab=readme-ov-file#v10). > If your task previously contained a git add step, please remove this. --------- Co-authored-by: Sam Ko <sam@vercel.com>
- Loading branch information
1 parent
b4f3283
commit 0558f61
Showing
4 changed files
with
234 additions
and
279 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,4 +1 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
pnpm lint-staged |
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,53 +1,8 @@ | ||
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}': 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}`] | ||
}, | ||
'*.{js,jsx,mjs,ts,tsx,mts}': [ | ||
'prettier --write', | ||
'eslint --no-ignore --max-warnings=0 --fix', | ||
], | ||
'*.{json,md,mdx,css,html,yml,yaml,scss}': ['prettier --write'], | ||
'*.rs': ['cargo fmt'], | ||
} |
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
Oops, something went wrong.