Skip to content

Commit

Permalink
refactor: remove unnecessary lint-staged operations (#65861)
Browse files Browse the repository at this point in the history
### 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
devjiwonchoi and samcx authored May 30, 2024
1 parent b4f3283 commit 0558f61
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 279 deletions.
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm lint-staged
57 changes: 6 additions & 51 deletions lint-staged.config.js
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'],
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Loading

0 comments on commit 0558f61

Please sign in to comment.