Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove unnecessary lint-staged operations #65861

Merged
merged 7 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
52 changes: 6 additions & 46 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,48 +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 ${escape(eslintFileNames.filter((filename) => filename !== null)).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',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • removed --with-node-modules flag since no effect if gitignored
  • removed --ignore-path since prettier reads .prettierignore & .gitignore by default

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --with-node-modules flag is to force linting test files in nested under node_modules iirc we should re-add this

],
'**/*.{json,md,mdx,css,html,yml,yaml,scss}': ['prettier --write'],
'**/*.rs': ['cargo fmt'],
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,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 @@ -171,7 +171,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
Loading