From 17f094867d3c1d47697fcbc9ca29265242b9af42 Mon Sep 17 00:00:00 2001 From: Marco Vockner Date: Wed, 22 Nov 2023 21:06:18 +0100 Subject: [PATCH] fix: update lint-staged to use package.json --- lint-staged.config.js | 43 ------------------------------------------- package.json | 6 +++++- 2 files changed, 5 insertions(+), 44 deletions(-) delete mode 100644 lint-staged.config.js diff --git a/lint-staged.config.js b/lint-staged.config.js deleted file mode 100644 index 529f235..0000000 --- a/lint-staged.config.js +++ /dev/null @@ -1,43 +0,0 @@ -/* eslint-disable no-undef */ -/* eslint-disable @typescript-eslint/no-var-requires */ -/* eslint-disable unicorn/prefer-array-flat-map */ - -// Source: https://coding.maier.tech/posts/optimizing-lint-staged-config-js-for-prettier/ - -const micromatch = require("micromatch") -const prettier = require("prettier") - -const addQuotes = (a) => `"${a}"` - -module.exports = async (allStagedFiles) => { - // Figure out all extensions supported by Prettier. - const prettierSupportedExtensions = await prettier - .getSupportInfo() - .languages.map(({ extensions }) => extensions) - .flat() - - // Match files for ESLint - const eslintFiles = micromatch(allStagedFiles, ["**/*.{js,ts}"], { - dot: true, - }) - - // Match files for Prettier - const prettierFiles = micromatch( - allStagedFiles, - prettierSupportedExtensions.map((extension) => `**/*${extension}`), - { dot: true }, - ) - - // Array of linters to be run in this sequence. - const linters = [] - - // Add linters only when there are staged files for them. - // 'prettier --write' causes lint-staged to never terminate when prettierFiles is empty. - - if (eslintFiles.length > 0) linters.push(`eslint --fix ${eslintFiles.join(" ")}`) - - if (prettierFiles.length > 0) - linters.push(`prettier --write ${prettierFiles.map((element) => addQuotes(element)).join(" ")}`) - - return linters -} diff --git a/package.json b/package.json index 1e64a20..3243c4f 100644 --- a/package.json +++ b/package.json @@ -75,5 +75,9 @@ }, "browserslist": [ "defaults" - ] + ], + "lint-staged": { + "*.js": "eslint --cache --fix", + "*.--write": "prettier --write" + } }