Skip to content

Commit

Permalink
refactor: simplified lint-staged config
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed Jun 11, 2024
1 parent db9170c commit 8f33371
Showing 1 changed file with 4 additions and 40 deletions.
44 changes: 4 additions & 40 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,44 +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 --fix ${eslintFileNames
.filter((filename) => filename !== null)
.map((filename) => {
return `"${filename}"`
})
.join(' ')}`,
`git add ${escapedFileNames}`,
]
},
'*.{js,jsx,mjs,ts,tsx,mts}': [
'prettier --with-node-modules --ignore-path .prettierignore --write',
'eslint --fix',
],
'*.{json,md,mdx,css,html,yml,yaml,scss}': [
'prettier --with-node-modules --ignore-path .prettierignore --write',
],
Expand Down

0 comments on commit 8f33371

Please sign in to comment.