From 6606630af2c8272409d9e86423313b8fa67b8378 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 11 Jun 2024 08:51:53 -0700 Subject: [PATCH] refactor: simplified lint-staged config (#66720) This restores the changes that were reverted in #66554. This corrects the issue that triggered the revert by removing the `--no-ignore` flag which allows ESLint to handle the ignored files correctly. --- lint-staged.config.js | 44 ++++--------------------------------------- 1 file changed, 4 insertions(+), 40 deletions(-) diff --git a/lint-staged.config.js b/lint-staged.config.js index 9cdc3d318c..167eaaaa0f 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -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', ],