Skip to content
This repository has been archived by the owner on Nov 14, 2022. It is now read-only.

Commit

Permalink
Improve lint-staged config
Browse files Browse the repository at this point in the history
Fixes #685
  • Loading branch information
maiertech committed Jan 15, 2021
1 parent 317bca1 commit 4b40828
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 24 deletions.
28 changes: 25 additions & 3 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
module.exports = {
'*.js': ['eslint --fix', 'prettier --write', 'prettier --check'],
'*.{md,mdx,css,yaml,yml}': ['prettier --write', 'prettier --check'],
const micromatch = require('micromatch');
const prettier = require('prettier');

// https://coding.maier.tech/chunks/optimizing-lint-staged-config-js-for-prettier/

const prettierSupportedExtensions = prettier
.getSupportInfo()
.languages.map(({ extensions }) => extensions)
.flat();

const addQuotes = (a) => `"${a}"`;

module.exports = (allStagedFiles) => {
const eslintFiles = micromatch(allStagedFiles, ['**/*.js'], { dot: true });
const prettierFiles = micromatch(
allStagedFiles,
prettierSupportedExtensions.map((extension) => `**/*${extension}`),
{ dot: true }
);
const linters = [];
if (eslintFiles.length > 0)
linters.push(`eslint --fix ${eslintFiles.join(' ')}`);
if (prettierFiles.length > 0)
linters.push(`prettier --write ${prettierFiles.map(addQuotes).join(' ')}`);
return linters;
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
"@babel/preset-react": "^7.12.7",
"@changesets/cli": "^2.13.0",
"@maiertech/eslint-config": "^0.16.0",
"@maiertech/prettier-config": "^0.2.1",
"@maiertech/prettier-config": "^0.3.0",
"@skypack/package-check": "^0.2.2",
"eslint": "^7.17.0",
"husky": "^4.3.0",
"husky": "^4.3.7",
"lint-staged": "^10.5.2",
"microbundle": "^0.13.0",
"micromatch": "^4.0.2",
"prettier": "^2.2.1"
}
}
45 changes: 26 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1766,10 +1766,10 @@
dependencies:
"@shopify/eslint-plugin" "^39.0.3"

"@maiertech/prettier-config@^0.2.1":
version "0.2.1"
resolved "https://registry.yarnpkg.com/@maiertech/prettier-config/-/prettier-config-0.2.1.tgz#8b85eb509a6e498218010e8fc540287dcbbe1e8c"
integrity sha512-V+DXbpav/ggMOv8xYISCvNES6Dsa3IMRErIs8F6rEEQ1C7r6KmeWyO6YOUOA3GwEAkT9Yk7T4nbprI+obN/LnA==
"@maiertech/prettier-config@^0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@maiertech/prettier-config/-/prettier-config-0.3.0.tgz#206009d9004c967d562a3b62faa3ab68185862c5"
integrity sha512-S6vCBBepNC5gJQLEfF6GzHyXssoTxaCtpCqdUHvIc585DIrdEMWNyEeVX7JN3rl7cQn6IMjscllIV5BBSmh1OQ==

"@manypkg/find-root@^1.1.0":
version "1.1.0"
Expand Down Expand Up @@ -7415,12 +7415,12 @@ find-up@^5.0.0:
locate-path "^6.0.0"
path-exists "^4.0.0"

find-versions@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/find-versions/-/find-versions-3.2.0.tgz#10297f98030a786829681690545ef659ed1d254e"
integrity sha512-P8WRou2S+oe222TOCHitLy8zj+SIsVJh52VP4lvXkaFVnOFFdoWv1H1Jjvel1aI6NCFOAaeAVm8qrI0odiLcww==
find-versions@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/find-versions/-/find-versions-4.0.0.tgz#3c57e573bf97769b8cb8df16934b627915da4965"
integrity sha512-wgpWy002tA+wgmO27buH/9KzyEOQnKsG/R0yrcjPT9BOFm0zRBVQbZ95nRGXWMywS8YR5knRbpohio0bcJABxQ==
dependencies:
semver-regex "^2.0.0"
semver-regex "^3.1.2"

[email protected]:
version "1.2.16"
Expand Down Expand Up @@ -9042,18 +9042,18 @@ human-signals@^1.1.1:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"
integrity sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==

husky@^4.3.0:
version "4.3.6"
resolved "https://registry.yarnpkg.com/husky/-/husky-4.3.6.tgz#ebd9dd8b9324aa851f1587318db4cccb7665a13c"
integrity sha512-o6UjVI8xtlWRL5395iWq9LKDyp/9TE7XMOTvIpEVzW638UcGxTmV5cfel6fsk/jbZSTlvfGVJf2svFtybcIZag==
husky@^4.3.7:
version "4.3.7"
resolved "https://registry.yarnpkg.com/husky/-/husky-4.3.7.tgz#ca47bbe6213c1aa8b16bbd504530d9600de91e88"
integrity sha512-0fQlcCDq/xypoyYSJvEuzbDPHFf8ZF9IXKJxlrnvxABTSzK1VPT2RKYQKrcgJ+YD39swgoB6sbzywUqFxUiqjw==
dependencies:
chalk "^4.0.0"
ci-info "^2.0.0"
compare-versions "^3.6.0"
cosmiconfig "^7.0.0"
find-versions "^3.2.0"
find-versions "^4.0.0"
opencollective-postinstall "^2.0.2"
pkg-dir "^4.2.0"
pkg-dir "^5.0.0"
please-upgrade-node "^3.2.0"
slash "^3.0.0"
which-pm-runs "^1.0.0"
Expand Down Expand Up @@ -12741,6 +12741,13 @@ pkg-dir@^4.1.0, pkg-dir@^4.2.0:
dependencies:
find-up "^4.0.0"

pkg-dir@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-5.0.0.tgz#a02d6aebe6ba133a928f74aec20bafdfe6b8e760"
integrity sha512-NPE8TDbzl/3YQYY7CSS228s3g2ollTFnc+Qi3tqmqJp9Vg2ovUpixcJEo2HJScN2Ez+kEaal6y70c0ehqJBJeA==
dependencies:
find-up "^5.0.0"

pkg-up@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/pkg-up/-/pkg-up-3.1.0.tgz#100ec235cc150e4fd42519412596a28512a0def5"
Expand Down Expand Up @@ -14736,10 +14743,10 @@ semver-diff@^3.1.1:
dependencies:
semver "^6.3.0"

semver-regex@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/semver-regex/-/semver-regex-2.0.0.tgz#a93c2c5844539a770233379107b38c7b4ac9d338"
integrity sha512-mUdIBBvdn0PLOeP3TEkMH7HHeUP3GjsXCwKarjv/kGmUFOYg1VqEemKhoQpWMu6X2I8kHeuVdGibLGkVK+/5Qw==
semver-regex@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/semver-regex/-/semver-regex-3.1.2.tgz#34b4c0d361eef262e07199dbef316d0f2ab11807"
integrity sha512-bXWyL6EAKOJa81XG1OZ/Yyuq+oT0b2YLlxx7c+mrdYPaPbnj6WgVULXhinMIeZGufuUBu/eVRqXEhiv4imfwxA==

"semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.5.0, semver@^5.5.1, semver@^5.6.0:
version "5.7.1"
Expand Down

1 comment on commit 4b40828

@vercel
Copy link

@vercel vercel bot commented on 4b40828 Jan 15, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.