Unverified Commit cef8bfa5 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

Revert "refactor: remove unnecessary `lint-staged` operations (#65861)" (#66554)

cc @samcx 

### Why?

The previous change on `lint-staged` dropped, ignoring files from
eslint, resulting in errors on files that should be ignored (e.g. `dist`
inside `.github/actions/`).

x-ref: #66383

### How?

This PR reverts PARTIAL commit 0558f61c.

### RFC

> ESLint v8.51.0 introduced [--no-warn-ignored CLI
flag](https://eslint.org/docs/latest/use/command-line-interface#--no-warn-ignored).
It suppresses the warning File ignored because of a matching ignore
pattern. Use "--no-ignore" to override warning, so manually ignoring
files via eslint.isPathIgnored is no longer necessary.

How about we convert current config as flat config, which would be
necessary if we upgrade to v9, and use the `--no-warn-ignored` flag on
`lint-staged` to reduce the operation introduced in #65861?

x-ref:
https://github.com/lint-staged/lint-staged?tab=readme-ov-file#eslint--8510--flat-eslint-config

---------
Co-authored-by: 's avatarSam Ko <sam@vercel.com>
parent 3cf225c8
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 = { module.exports = {
'*.{js,jsx,mjs,ts,tsx,mts}': [ '*.{js,jsx,mjs,ts,tsx,mts}': async (filenames) => {
'prettier --with-node-modules --ignore-path .prettierignore --write', const escapedFileNames = escape(filenames).join(' ')
'eslint --no-ignore --max-warnings=0 --fix', 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}': [ '*.{json,md,mdx,css,html,yml,yaml,scss}': [
'prettier --with-node-modules --ignore-path .prettierignore --write', 'prettier --with-node-modules --ignore-path .prettierignore --write',
], ],
......
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