Unverified Commit 0558f61c authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

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](https://github.com/vercel/next.js/pull/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: 's avatarSam Ko <sam@vercel.com>
parent b4f32831
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
pnpm lint-staged
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'],
}
......@@ -55,7 +55,7 @@
"debug": "cross-env NEXT_TELEMETRY_DISABLED=1 node --inspect packages/next/dist/bin/next",
"postinstall": "node scripts/git-configure.mjs && node scripts/install-native.mjs",
"version": "pnpm install --no-frozen-lockfile && IS_PUBLISH=yes ./scripts/check-pre-compiled.sh && git add .",
"prepare": "husky install",
"prepare": "husky",
"sync-react": "node ./scripts/sync-react.js",
"update-google-fonts": "node ./scripts/update-google-fonts.js"
},
......@@ -159,7 +159,7 @@
"gzip-size": "5.1.1",
"html-validator": "5.1.18",
"http-proxy": "1.18.1",
"husky": "8.0.0",
"husky": "9.0.11",
"image-size": "1.1.1",
"is-animated": "2.0.2",
"isomorphic-unfetch": "3.0.0",
......@@ -172,7 +172,7 @@
"ky": "0.19.1",
"ky-universal": "0.6.0",
"lerna": "4.0.0",
"lint-staged": "10.1.7",
"lint-staged": "15.2.2",
"lodash": "4.17.20",
"lost": "8.3.1",
"minimatch": "3.0.4",
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment