Skip to content

Commit b002144

Browse files
committed
feat: added the missing code
Signed-off-by: prisis <[email protected]>
1 parent ce14364 commit b002144

18 files changed

+330
-26
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,4 @@ common/autoinstallers/*/.npmrc
135135
/packages/eslint-config/.eslintrc.js
136136
/packages/commitlint-config/commitlint.config.js
137137
/packages/commitlint-config/.czrc
138+
/packages/lint-staged-config/.lintstagedrc.js

.lintstagedrc

-8
This file was deleted.

.lintstagedrc.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const config = require("./packages/lint-staged-config");
2+
3+
module.exports = {
4+
...config,
5+
};

packages/lint-staged-config/README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<div align="center">
2+
3+
<h1>Shareable Lint-Staged Config</h1>
4+
5+
Package that contains shareable configuration for [lint-staged](https://github.com/okonet/lint-staged) — a popular tool for running linters on staged Git files.
6+
7+
8+
[![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url]
9+
10+
</div>
11+
12+
---
13+
14+
<div align="center">
15+
<p>
16+
<sup>
17+
Daniel Bannert's open source work is supported by the community on <a href="https://github.com/sponsors/prisis">GitHub Sponsors</a>
18+
</sup>
19+
</p>
20+
</div>
21+
22+
---
23+
24+
25+
## Supported Node.js Versions
26+
27+
Libraries in this ecosystem make the best effort to track
28+
[Node.js’ release schedule](https://nodejs.org/en/about/releases/). Here’s [a
29+
post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a).
30+
31+
Contributing
32+
------------
33+
34+
If you would like to help take a look at the [list of issues](https://github.com/anolilab/javascript-style-guide/issues) and check our [Contributing](.github/CONTRIBUTING.md) guild.
35+
36+
> **Note:** please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
37+
38+
Credits
39+
-------------
40+
41+
- [Daniel Bannert](https://github.com/prisis)
42+
- [All Contributors](https://github.com/anolilab/javascript-style-guide/graphs/contributors)
43+
44+
License
45+
-------------
46+
47+
The anolilab javascript-style-guide is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT)
48+
49+
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
50+
[typescript-url]: "typescript"
51+
[license-image]: https://img.shields.io/npm/l/@anolilab/lint-staged-config?color=blueviolet&style=for-the-badge
52+
[license-url]: LICENSE.md "license"
53+
[npm-image]: https://img.shields.io/npm/v/@anolilab/lint-staged-config/latest.svg?style=for-the-badge&logo=npm
54+
[npm-url]: https://www.npmjs.com/package/@anolilab/lint-staged-config/v/latest "npm"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "@anoliab/lint-staged-config-group",
3+
"version": "0.0.0",
4+
"description": "Shareable Lint-Staged Config for any project.",
5+
"license": "MIT",
6+
"exports": {
7+
"./group/eslint": {
8+
"types": "./../dist/groups/eslint.d.ts",
9+
"require": "./../dist/groups/eslint.js",
10+
"import": "./../dist/groups/eslint.mjs"
11+
},
12+
"./group/package-json": {
13+
"types": "./../dist/groups/package-json.d.ts",
14+
"require": "./../dist/groups/package-json.js",
15+
"import": "./../dist/groups/package-json.mjs"
16+
},
17+
"./group/prettier": {
18+
"types": "./../dist/groups/prettier.d.ts",
19+
"require": "./../dist/groups/prettier.js",
20+
"import": "./../dist/groups/prettier.mjs"
21+
},
22+
"./group/secretlint": {
23+
"types": "./../dist/groups/secretlint.d.ts",
24+
"require": "./../dist/groups/secretlint.js",
25+
"import": "./../dist/groups/secretlint.mjs"
26+
},
27+
"./group/stylesheets": {
28+
"types": "./../dist/groups/stylesheets.d.ts",
29+
"require": "./../dist/groups/stylesheets.js",
30+
"import": "./../dist/groups/stylesheets.mjs"
31+
},
32+
"./group/tests": {
33+
"types": "./../dist/groups/tests.d.ts",
34+
"require": "./../dist/groups/tests.js",
35+
"import": "./../dist/groups/tests.mjs"
36+
},
37+
"./group/typescript": {
38+
"types": "./../dist/groups/typescript.d.ts",
39+
"require": "./../dist/groups/typescript.js",
40+
"import": "./../dist/groups/typescript.mjs"
41+
},
42+
"./package.json": "./package.json"
43+
}
44+
}

packages/lint-staged-config/package.json

+53-4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,41 @@
3737
"require": "./dist/index.js",
3838
"import": "./dist/index.mjs"
3939
},
40+
"./group/eslint": {
41+
"types": "./dist/groups/eslint.d.ts",
42+
"require": "./dist/groups/eslint.js",
43+
"import": "./dist/groups/eslint.mjs"
44+
},
45+
"./group/package-json": {
46+
"types": "./dist/groups/package-json.d.ts",
47+
"require": "./dist/groups/package-json.js",
48+
"import": "./dist/groups/package-json.mjs"
49+
},
50+
"./group/prettier": {
51+
"types": "./dist/groups/prettier.d.ts",
52+
"require": "./dist/groups/prettier.js",
53+
"import": "./dist/groups/prettier.mjs"
54+
},
55+
"./group/secretlint": {
56+
"types": "./dist/groups/secretlint.d.ts",
57+
"require": "./dist/groups/secretlint.js",
58+
"import": "./dist/groups/secretlint.mjs"
59+
},
60+
"./group/stylesheets": {
61+
"types": "./dist/groups/stylesheets.d.ts",
62+
"require": "./dist/groups/stylesheets.js",
63+
"import": "./dist/groups/stylesheets.mjs"
64+
},
65+
"./group/tests": {
66+
"types": "./dist/groups/tests.d.ts",
67+
"require": "./dist/groups/tests.js",
68+
"import": "./dist/groups/tests.mjs"
69+
},
70+
"./group/typescript": {
71+
"types": "./dist/groups/typescript.d.ts",
72+
"require": "./dist/groups/typescript.js",
73+
"import": "./dist/groups/typescript.mjs"
74+
},
4075
"./package.json": "./package.json"
4176
},
4277
"main": "dist/index.js",
@@ -61,10 +96,24 @@
6196
"devDependencies": {
6297
"@anolilab/semantic-release-preset": "4.0.1",
6398
"semantic-release": "^21.0.5",
64-
"lint-staged": "^13.2.2"
99+
"lint-staged": "^13.2.2",
100+
"@types/lint-staged": "^13.2.0",
101+
"tsup": "^6.7.0",
102+
"typescript": "5.1.3",
103+
"husky": "^8.0.3"
104+
},
105+
"optionalDependencies": {
106+
"secretlint": "^6.2.3",
107+
"eslint": "^7.32.0",
108+
"stylelint": "^15.9.0",
109+
"prettier": "^2.8.8",
110+
"pretty-quick": "^3.1.3",
111+
"vite": "^4.3.9",
112+
"jest": "^29.5.0"
65113
},
66114
"peerDependencies": {
67-
"lint-staged": "^13.x"
115+
"lint-staged": "^13.x",
116+
"husky": "^8.x"
68117
},
69118
"engines": {
70119
"node": ">=16"
@@ -76,12 +125,12 @@
76125
"sources": [
77126
"src/index.ts",
78127
"src/postinstall.ts",
79-
"src/groups/dockerfile.ts",
80128
"src/groups/eslint.ts",
81129
"src/groups/package-json.ts",
82130
"src/groups/prettier.ts",
131+
"src/groups/secretlint.ts",
83132
"src/groups/stylesheets.ts",
84-
"src/groups/test.ts",
133+
"src/groups/tests.ts",
85134
"src/groups/typescript.ts"
86135
]
87136
}
+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { hasDependency, hasDevDependency, pkg } from "@anolilab/package-json-utils";
2+
import type { Config } from "lint-staged";
3+
4+
import eslintConfig from "./groups/eslint";
5+
import packageJsonConfig from "./groups/package-json";
6+
import prettierConfig from "./groups/prettier";
7+
import secretlintConfig from "./groups/secretlint";
8+
import stylesheetsConfig from "./groups/stylesheets";
9+
import testsConfig from "./groups/tests";
10+
import typescriptConfig from "./groups/typescript";
11+
12+
type Groups = {
13+
configName: string;
14+
config: Config;
15+
dependencies: string[];
16+
}[];
17+
18+
const groups: Groups = [
19+
{
20+
configName: "eslint",
21+
config: eslintConfig,
22+
dependencies: ["eslint"],
23+
},
24+
{
25+
configName: "package-json",
26+
config: packageJsonConfig,
27+
dependencies: [],
28+
},
29+
{
30+
configName: "prettier",
31+
config: prettierConfig,
32+
dependencies: ["prettier", "pretty-quick"],
33+
},
34+
{
35+
configName: "secretlint",
36+
config: secretlintConfig,
37+
dependencies: ["secretlint"],
38+
},
39+
{
40+
configName: "stylesheets",
41+
config: stylesheetsConfig,
42+
dependencies: [],
43+
},
44+
{
45+
configName: "tests",
46+
config: testsConfig,
47+
dependencies: ["vite", "jest"],
48+
},
49+
{
50+
configName: "typescript",
51+
config: typescriptConfig,
52+
dependencies: ["typescript"],
53+
},
54+
];
55+
56+
let anolilabEslintConfig: { [key: string]: { [key: string]: false | undefined } } = {};
57+
58+
if (pkg) {
59+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
60+
anolilabEslintConfig = pkg?.["anolilab"]?.["lint-staged-config"];
61+
}
62+
63+
let loadedPlugins: Config = {};
64+
const loadedPluginsNames: string[] = [];
65+
66+
const possiblePlugins: { [rule: string]: { [packageName: string]: boolean } } = {};
67+
68+
groups.forEach((plugin) => {
69+
const { dependencies, config, configName } = plugin;
70+
71+
if (anolilabEslintConfig?.["plugin"]?.[configName] !== false) {
72+
const foundDependencies = [];
73+
74+
dependencies.forEach((dependency) => {
75+
if (hasDependency(dependency) || hasDevDependency(dependency)) {
76+
foundDependencies.push(dependency);
77+
}
78+
});
79+
80+
if (foundDependencies.length === dependencies.length) {
81+
loadedPlugins = { ...loadedPlugins, ...config };
82+
loadedPluginsNames.push(configName);
83+
} else {
84+
possiblePlugins[configName] = {};
85+
86+
dependencies.forEach((dependency) => {
87+
(possiblePlugins[configName] as { [key: string]: boolean })[dependency] = hasDependency(dependency) || hasDevDependency(dependency);
88+
});
89+
}
90+
}
91+
});
92+
93+
const loaded: Config = { ...loadedPlugins };
94+
95+
export { loaded as loadedPlugins, loadedPluginsNames, possiblePlugins };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import consoleLog from "./logger";
2+
3+
export {};
4+
5+
declare global {
6+
var hasAnolilabStageLintConfigLoaded: boolean;
7+
}

packages/lint-staged-config/src/groups/dockerfile.ts

-5
This file was deleted.

packages/lint-staged-config/src/groups/eslint.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import type { Config } from "lint-staged";
2+
13
const extensions = ["json", "json5", "jsonc", "cjs", "js", "mjs", "cts", "ts", "mts", "yml", "yaml", "jsx", "tsx", "md", "mdx"] as const;
24

3-
const group = {
5+
const group: Config = {
46
[`*.{${extensions.join(",")}}`]: ["cross-env NO_LOGS=true eslint"],
57
};
68

packages/lint-staged-config/src/groups/package-json.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const group = {
1+
import type { Config } from "lint-staged";
2+
3+
const group: Config = {
24
"**/package.json": () => [
35

46
],
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { hasDependency, hasDevDependency } from "@anolilab/package-json-utils";
2+
import type { Config } from "lint-staged";
23

34
let hasPrettyQuick = false;
45

56
if (hasDependency("pretty-quick") || hasDevDependency("pretty-quick")) {
67
hasPrettyQuick = true;
78
}
89

9-
const group = {
10-
"*": hasPrettyQuick ? ["pretty-quick --check --staged"] : ["prettier --list-different"],
10+
const group: Config = {
11+
"!(CHANGELOG|LICENSE)*": hasPrettyQuick ? ["pretty-quick --check --staged"] : ["prettier --list-different"],
1112
};
1213

1314
export default group;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { Config } from "lint-staged";
2+
3+
const group: Config = {
4+
"*": ["secretlint"],
5+
};
6+
7+
export default group;

packages/lint-staged-config/src/groups/stylesheets.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const group = {
1+
import type { Config } from "lint-staged";
2+
3+
const group: Config = {
24
[`*.{${["css", "sass", "scss", "less"].join(",")}}`]: ["stylelint"],
35
};
46

packages/lint-staged-config/src/groups/tests.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const group = {
1+
import type { Config } from "lint-staged";
2+
3+
const group: Config = {
24
"**/__tests__/**/*.?(c|m)[jt]s?(x)": ["vitest related --run"],
35
"**/?(*.){test,spec}.?(c|m)[jt]s?(x)": ["vitest related --run"],
46
};
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const group = {
1+
import type { Config } from "lint-staged";
22

3-
};
3+
const group: Config = {};
44

55
export default group;

0 commit comments

Comments
 (0)