@anolilab/lint-staged-config 3.0.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +10 -10
- package/dist/bin.mjs +3 -3
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +14 -14
- package/dist/index.d.mts +14 -14
- package/dist/index.d.ts +14 -14
- package/dist/index.mjs +2 -2
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## @anolilab/lint-staged-config [3.0.2](https://github.com/anolilab/javascript-style-guide/compare/@anolilab/lint-staged-config@3.0.1...@anolilab/lint-staged-config@3.0.2) (2025-05-26)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* **lint-staged-config:** update ESLint configuration and dependencies ([d94ff6d](https://github.com/anolilab/javascript-style-guide/commit/d94ff6d0a0453ae35e4cfc80c2f15f8e96f80683))
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Dependencies
|
|
9
|
+
|
|
10
|
+
* **@anolilab/eslint-config:** upgraded to 16.1.2
|
|
11
|
+
|
|
12
|
+
## @anolilab/lint-staged-config [3.0.1](https://github.com/anolilab/javascript-style-guide/compare/@anolilab/lint-staged-config@3.0.0...@anolilab/lint-staged-config@3.0.1) (2025-05-26)
|
|
13
|
+
|
|
14
|
+
### Miscellaneous Chores
|
|
15
|
+
|
|
16
|
+
* add new linting scripts and update dependencies ([655a866](https://github.com/anolilab/javascript-style-guide/commit/655a86641903f157e4d8a4dc69d0f44448fa7cc9))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Dependencies
|
|
20
|
+
|
|
21
|
+
* **@anolilab/eslint-config:** upgraded to 16.1.1
|
|
22
|
+
|
|
1
23
|
## @anolilab/lint-staged-config [3.0.0](https://github.com/anolilab/javascript-style-guide/compare/@anolilab/lint-staged-config@2.1.7...@anolilab/lint-staged-config@3.0.0) (2025-05-26)
|
|
2
24
|
|
|
3
25
|
### ⚠ BREAKING CHANGES
|
package/README.md
CHANGED
|
@@ -77,14 +77,14 @@ If you already have a `.lintstagedrc.js` or `.nano-staged.js`, then you can exte
|
|
|
77
77
|
The content of the `.lintstagedrc.js` or `.nano-staged.js` should look like this:
|
|
78
78
|
|
|
79
79
|
```js
|
|
80
|
-
const { defineConfig } = require("@anolilab/lint-staged-config");
|
|
81
|
-
|
|
82
|
-
module.exports = defineConfig();
|
|
83
|
-
|
|
84
80
|
// or
|
|
85
81
|
|
|
86
82
|
import { defineConfig } from "@anolilab/lint-staged-config";
|
|
87
83
|
|
|
84
|
+
const { defineConfig } = require("@anolilab/lint-staged-config");
|
|
85
|
+
|
|
86
|
+
module.exports = defineConfig();
|
|
87
|
+
|
|
88
88
|
export default defineConfig();
|
|
89
89
|
```
|
|
90
90
|
### Config
|
|
@@ -92,18 +92,18 @@ export default defineConfig();
|
|
|
92
92
|
You can configure `@anolilab/lint-staged-config` options inside the `defineConfig` function.
|
|
93
93
|
|
|
94
94
|
```js
|
|
95
|
+
// or
|
|
96
|
+
|
|
97
|
+
import { defineConfig } from "@anolilab/lint-staged-config";
|
|
98
|
+
|
|
95
99
|
const { defineConfig } = require("@anolilab/lint-staged-config");
|
|
96
100
|
|
|
97
101
|
module.exports = defineConfig({
|
|
98
|
-
|
|
102
|
+
// Add your configuration here
|
|
99
103
|
});
|
|
100
104
|
|
|
101
|
-
// or
|
|
102
|
-
|
|
103
|
-
import { defineConfig } from "@anolilab/lint-staged-config";
|
|
104
|
-
|
|
105
105
|
export default defineConfig({
|
|
106
|
-
|
|
106
|
+
// Add your configuration here
|
|
107
107
|
});
|
|
108
108
|
```
|
|
109
109
|
|
package/dist/bin.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var g=Object.defineProperty;var h=(n,o)=>g(n,"name",{value:o,configurable:!0});import{join as s}from"node:path";import{exit as f}from"node:process";import{readFile as
|
|
2
|
+
var g=Object.defineProperty;var h=(n,o)=>g(n,"name",{value:o,configurable:!0});import{existsSync as u}from"node:fs";import{join as s}from"node:path";import{exit as f}from"node:process";import{readFile as p,writeFileSync as r,ensureDirSync as $,isAccessibleSync as _}from"@visulima/fs";import{parsePackageJson as y,hasPackageJsonAnyDependency as d}from"@visulima/package";var w=Object.defineProperty,l=h((n,o)=>w(n,"name",{value:o,configurable:!0}),"c");const c=l(n=>_(n)?(console.warn(`⚠️ ${n} already exists;`),!0):!1,"checkIfFileExists"),I=l(async(n,o)=>{const e=".lintstagedrc";for(const i of[e,`${e}.js`,`${e}.cjs`,`${e}.mjs`,`${e}.json`,`${e}.yaml`,`${e}.yml`,"lint-staged.config.js","lint-staged.config.mjs","lint-staged.config.cjs"])if(c(s(n,i))){console.warn(`⚠️ ${i} already exists;`);return}const t=s(n,".lintstagedrc.js");r(t,`${o?'import { defineConfig } from "@anolilab/lint-staged-config"':'const { defineConfig } = require("@anolilab/lint-staged-config")'};
|
|
3
3
|
|
|
4
4
|
${o?"export default":"module.exports ="} defineConfig();
|
|
5
5
|
`)},"writeLintStagedRc"),x=l(async(n,o)=>{const e=".nano-staged";for(const i of[e,`${e}.js`,`${e}.cjs`,`${e}.mjs`,`${e}.json`,`${e.replace(".","")}.js`,`${e.replace(".","")}.cjs`,`${e.replace(".","")}.mjs`,`${e.replace(".","")}.json`,".nanostagedrc"])if(c(s(n,i))){console.warn(`⚠️ ${i} already exists;`);return}const t=s(n,".nano-staged.js");r(t,`${o?'import { defineConfig } from "@anolilab/lint-staged-config"':'const { defineConfig } = require("@anolilab/lint-staged-config")'};
|
|
6
6
|
|
|
7
7
|
${o?"export default":"module.exports ="} defineConfig();
|
|
8
|
-
`)},"writeNanoStagedRc"),S=l(async(n,o,e)=>{if(!d(o,["husky"])){console.warn("⚠️ husky is not installed;");return}const t=s(n,".husky")
|
|
8
|
+
`)},"writeNanoStagedRc"),S=l(async(n,o,e)=>{if(!d(o,["husky"])){console.warn("⚠️ husky is not installed;");return}const t=s(n,".husky");$(t);const i=s(t,"common.sh");c(i)||r(i,`#!/bin/sh
|
|
9
9
|
|
|
10
10
|
command_exists () {
|
|
11
11
|
command -v "$1" >/dev/null 2>&1
|
|
@@ -85,4 +85,4 @@ fi
|
|
|
85
85
|
echo Finished Git hook: prepare-commit-msg
|
|
86
86
|
echo --------------------------------------------
|
|
87
87
|
`)},"writeHuskyFiles");(async()=>{const n=process.cwd();console.log("Configuring @anolilab/lint-staged-config",n,`
|
|
88
|
-
`);const o=s(n,"package.json");
|
|
88
|
+
`);const o=s(n,"package.json");u(o)||(console.error("No package.json found in the current directory. You need to run this command in a directory with a package.json file."),f(1));const e=y(await p(o)),t=e.type==="module",i=d(e,["lint-staged"]),a=d(e,["nano-staged"]);try{i?await I(n,t):a&&await x(n,t),await S(n,e,a),console.log("Everything went well, have fun!"),f(0)}catch(m){console.error("Something went wrong:",m),f(1)}})();
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var D=Object.defineProperty;var f=(s,e)=>D(s,"name",{value:e,configurable:!0});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";var D=Object.defineProperty;var f=(s,e)=>D(s,"name",{value:e,configurable:!0});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const J=require("node:fs"),m=require("@visulima/fs"),o=require("@visulima/package"),j=require("node:path"),T=require("eslint"),k=require("shell-quote"),w=require("node:process");var q=Object.defineProperty,h=f((s,e)=>q(s,"name",{value:e,configurable:!0}),"o$1");const O=h(s=>{const e=m.findUpSync("package.json",{cwd:s});return e&&j.dirname(e)},"packageDirectorySync"),C=h(s=>{const e=O(s??process.cwd());if(e?.startsWith("/"))return e;throw new Error(`Cannot determine the nearest root of the package for the file: ${s}!`)},"getNearestPackageRootPath"),N=h(s=>{const e=j.join(...s);if(e.startsWith("/"))return e;throw new TypeError("Joined path did not return an absolute path.")},"joinPaths"),v=h((s,e)=>{const i=C(e),t=N([i,s]);if(m.isAccessibleSync(t))return t;throw new Error(`Cannot locate nearest "${s}" file!`)},"getNearestConfigPath");var R=Object.defineProperty,F=f((s,e)=>R(s,"name",{value:e,configurable:!0}),"i$1");const G=F(s=>{const e={};return s.forEach(i=>{const t=j.dirname(i);e[t]||(e[t]=[]),e[t].push(i)}),e},"groupFilePathsByDirectoryName"),P=w.platform==="win32"||/^(msys|cygwin)$/u.test(w.env.OSTYPE??"");var L=Object.defineProperty,M=f((s,e)=>L(s,"name",{value:e,configurable:!0}),"o");const H=M(async(s,e=new T.ESLint)=>{const i=(await Promise.allSettled(s.map(async t=>await e.isPathIgnored(t)))).map(t=>{if(t.status==="fulfilled")return t.value;throw console.error(`
|
|
2
2
|
Unable to determine if file is ignored.
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
${t.reason}`),new Error("Stopping lint-staged because of an error.")});return s.filter((t,n)=>!i[n]).map(t=>`"${P?t:k.quote([t])}"`)},"removeIgnoredFiles");var I=Object.defineProperty,_=f((s,e)=>I(s,"name",{value:e,configurable:!0}),"m");const y=".eslintrc",U=_((s,e)=>{const i=[];s["max-warnings"]!==void 0&&Number.isNaN(s["max-warnings"])?i.push(`--max-warnings=${s["max-warnings"]}`):s["max-warnings"]!==!1&&i.push("--max-warnings=0");const t=[];o.hasPackageJsonAnyDependency(e,["eslint-plugin-react-hooks"])&&t.push("react-hooks/exhaustive-deps:off"),o.hasPackageJsonAnyDependency(e,["eslint-plugin-eslint-comments"])&&t.push("eslint-comments/no-unused-disable:off");const n=[...s.rules??[],...t].filter(p=>p.trim().length>0);n.length>0&&i.push(n.map(p=>`--rule "${p}"`).join(" "));const l=[...s["fix-type"]??["layout"]].filter(p=>p.trim().length>0);return l.length>0&&i.push(`--fix-type ${l.join(",")}`,"--fix"),s.cache&&i.push("--cache"),i},"createEslintArguments"),W=_(async(s,e,i,t)=>{const n=await H(t),l=U(i,e);if(i.config)return l.push(`--config ${i.config}`),[`${s} exec eslint ${l.join(" ")} ${n.join(" ")}`];const p=G(n),d=[];return Object.values(p).forEach(a=>{let r;[y,`${y}.js`,`${y}.cjs`,`${y}.json`,`${y}.yaml`,`${y}.yml`].forEach(g=>{if(!r)try{r=v(g,a[0])}catch{}}),r&&d.push(`${s} exec eslint ${l.join(" ")} --config ${r} ${a.join(" ")}`)}),d},"createEslintCommands");var B=Object.defineProperty,Q=f((s,e)=>B(s,"name",{value:e,configurable:!0}),"r");const c=Q(s=>s.map(e=>`"${P?e:k.quote([e])}"`).join(" ").replaceAll("/@","/@"),"concatFiles");var Y=Object.defineProperty,$=f((s,e)=>Y(s,"name",{value:e,configurable:!0}),"
|
|
5
|
+
${t.reason}`),new Error("Stopping lint-staged because of an error.")});return s.filter((t,n)=>!i[n]).map(t=>`"${P?t:k.quote([t])}"`)},"removeIgnoredFiles");var I=Object.defineProperty,_=f((s,e)=>I(s,"name",{value:e,configurable:!0}),"m");const y=".eslintrc",U=_((s,e)=>{const i=[];s["max-warnings"]!==void 0&&Number.isNaN(s["max-warnings"])?i.push(`--max-warnings=${s["max-warnings"]}`):s["max-warnings"]!==!1&&i.push("--max-warnings=0");const t=[];o.hasPackageJsonAnyDependency(e,["eslint-plugin-react-hooks"])&&t.push("react-hooks/exhaustive-deps:off"),o.hasPackageJsonAnyDependency(e,["eslint-plugin-eslint-comments"])&&t.push("eslint-comments/no-unused-disable:off");const n=[...s.rules??[],...t].filter(p=>p.trim().length>0);n.length>0&&i.push(n.map(p=>`--rule "${p}"`).join(" "));const l=[...s["fix-type"]??["layout"]].filter(p=>p.trim().length>0);return l.length>0&&i.push(`--fix-type ${l.join(",")}`,"--fix"),s.cache&&i.push("--cache"),i},"createEslintArguments"),W=_(async(s,e,i,t)=>{const n=await H(t),l=U(i,e);if(i.config)return l.push(`--config ${i.config}`),[`${s} exec eslint ${l.join(" ")} ${n.join(" ")}`];const p=G(n),d=[];return Object.values(p).forEach(a=>{let r;[y,`${y}.js`,`${y}.cjs`,`${y}.json`,`${y}.yaml`,`${y}.yml`].forEach(g=>{if(!r)try{r=v(g,a[0])}catch{}}),r&&d.push(`${s} exec eslint ${l.join(" ")} --config ${r} ${a.join(" ")}`)}),d},"createEslintCommands");var B=Object.defineProperty,Q=f((s,e)=>B(s,"name",{value:e,configurable:!0}),"r");const c=Q(s=>s.map(e=>`"${P?e:k.quote([e])}"`).join(" ").replaceAll("/@","/@"),"concatFiles");var Y=Object.defineProperty,$=f((s,e)=>Y(s,"name",{value:e,configurable:!0}),"f");const b=["cjs","js","mjs","cts","ts","mts","yml","yaml","jsx","tsx","mdx","toml","json","json5","jsonc"],E=["cts","ts","mts","tsx","ctsx"],A=["css","scss","sass","less","styl","stylus","pcss","postcss","sss"],z=$((s={})=>{const e={debug:!1,eslint:{extensions:b},stylesheets:{extensions:A},typescript:{exclude:[],extensions:E},...s},i=e.cwd||process.cwd();if(!J.existsSync(`${i}/package.json`))throw new Error(`No package.json found in the current working directory: ${i}; Please adjust the "cwd" option.`);const t=o.parsePackageJson(m.readFileSync(`${i}/package.json`)),{packageManager:n}=o.findPackageManagerSync(i);e.debug&&console.debug("Package manager found:",n);const l=o.hasPackageJsonAnyDependency(t,["markdownlint-cli"]),p=o.hasPackageJsonAnyDependency(t,["markdownlint-cli2"]),d=o.hasPackageJsonAnyDependency(t,["prettier"]);let a={};if(e.eslint!==!1&&o.hasPackageJsonAnyDependency(t,["eslint"])){if(!Array.isArray(e.eslint.extensions)||e.eslint.extensions.length===0)throw new Error("The `extensions` option is required for the ESLint configuration.");!l&&!p&&e.eslint.extensions.push("md"),a[`**/*.{${e.eslint.extensions.join(",")}}`]=async r=>[...d?[`${n} exec prettier --write ${c(r)}`]:[],...await W(n,t,e.eslint,r)]}if(e.json!==!1&&o.hasPackageJsonAnyDependency(t,["sort-package-json"])&&(a["**/package.json"]=r=>[`${n} exec sort-package-json ${c(r)}`]),e.markdown!==!1&&l&&(a={...a,"**/*.md":$(r=>[...d?[`${n} exec prettier --write ${c(r)}`]:[],...l?[`${n} exec markdownlint --fix --ignore '**/node_modules/**' --ignore '**/CHANGELOG.md' ${c(r)}`]:[],...p?[`${n} exec markdownlint-cli2 --fix '!**/node_modules/**' '!**/CHANGELOG.md' ${c(r)}`]:[]],"**/*.md"),"**/*.mdx":$(r=>[...d?[`${n} exec prettier --write ${c(r)}`]:[]],"**/*.mdx")}),e.secretlint!==!1&&o.hasPackageJsonAnyDependency(t,["secretlint"])&&(a["**/*"]=r=>[`${n} exec secretlint ${c(r)}`]),e.stylesheets!==!1&&o.hasPackageJsonAnyDependency(t,["stylelint"])){if(!Array.isArray(e.stylesheets.extensions)||e.stylesheets.extensions.length===0)throw new Error("The `extensions` option is required for the Stylesheets configuration.");a[`**/*.{${e.stylesheets.extensions.join(",")}}`]=r=>[...d?[`${n} exec prettier --ignore-unknown --write ${c(r)}`]:[],`${n} exec stylelint --fix`]}if(e.typescript!==!1&&o.hasPackageJsonAnyDependency(t,["typescript"])){if(!Array.isArray(e.typescript.extensions)||e.typescript.extensions.length===0)throw new Error("The `extensions` option is required for the TypeScript configuration.");a[`**/*.{${e.typescript.extensions.join(",")}}`]=r=>{const g=new Set;return r.forEach(x=>{if(typeof e.typescript?.exclude=="object"&&Array.isArray(e.typescript.exclude)){let u=!1;if(e.typescript.exclude.forEach(S=>{!u&&x.includes(S)&&(u=!0)}),u){e.debug&&console.info(`Skipping ${x} as it's excluded in the settings.`);return}}try{const u=v("tsconfig.json",x);g.add(`${n} exec tsc --noEmit --project ${u}`)}catch(u){e.debug&&console.error(u)}}),[...g]}}return o.hasPackageJsonAnyDependency(t,["vitest"])&&(a["**/?(*.){test,spec}.?(c|m)[jt]s?(x)"]=["vitest related --run"],a["**/__tests__/**/*.?(c|m)[jt]s?(x)"]=[`${n} exec vitest related --run`]),o.hasPackageJsonAnyDependency(t,["jest"])&&(a["**/*.spec.{js,ts,tsx}"]=[`${n} exec jest --findRelatedTests`],a["**/*.test.{js,ts,tsx}"]=[`${n} exec jest --findRelatedTests`],a["**/?(*.){test,spec}.?(c|m)[jt]s?(x)"]=[`${n} exec jest --findRelatedTests`],a["**/__mocks__/*.{js,ts,tsx}"]=[`${n} exec jest --findRelatedTests`],a["**/__tests__/**/*.?(c|m)[jt]s?(x)"]=[`${n} exec jest --findRelatedTests`],a["**/__tests__/*.{js,ts,tsx}"]=[`${n} exec jest --findRelatedTests`],a["**/test/*.{js,ts,tsx}"]=[`${n} exec jest --findRelatedTests`]),o.hasPackageJsonAnyDependency(t,["ava"])&&(a["**/(test|tests|__tests__)/**/*.js"]=r=>[`${n} exec ava ${c(r)}`],a["**/*.(spec|test).js"]=r=>[`${n} exec ava ${c(r)}`],a["**/test.js"]=r=>[`${n} exec ava ${c(r)}`],a["**/test-*.js"]=r=>[`${n} exec ava ${c(r)}`]),a},"defineConfig");exports.defineConfig=z;exports.eslintExtensions=b;exports.stylesheetsExtensions=A;exports.typescriptExtensions=E;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Configuration } from 'lint-staged';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
@@ -7,35 +7,35 @@ declare global {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
extensions?: string[];
|
|
10
|
+
interface EslintConfig {
|
|
12
11
|
cache?: boolean;
|
|
13
12
|
config?: string;
|
|
13
|
+
extensions?: string[];
|
|
14
14
|
"fix-type"?: string[];
|
|
15
15
|
"max-warnings"?: number | string | false;
|
|
16
16
|
rules?: string[];
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
exclude?: string[];
|
|
19
|
+
interface StylesheetsConfig {
|
|
21
20
|
extensions?: string[];
|
|
22
|
-
}
|
|
23
|
-
|
|
21
|
+
}
|
|
22
|
+
interface TypescriptConfig {
|
|
23
|
+
exclude?: string[];
|
|
24
24
|
extensions?: string[];
|
|
25
|
-
}
|
|
25
|
+
}
|
|
26
26
|
declare const eslintExtensions: string[];
|
|
27
27
|
declare const typescriptExtensions: string[];
|
|
28
28
|
declare const stylesheetsExtensions: string[];
|
|
29
29
|
declare const defineConfig: (options?: {
|
|
30
|
-
debug?: boolean;
|
|
31
30
|
cwd?: string;
|
|
32
|
-
|
|
31
|
+
debug?: boolean;
|
|
32
|
+
eslint?: EslintConfig | false;
|
|
33
33
|
json?: false;
|
|
34
34
|
markdown?: false;
|
|
35
35
|
secretlint?: false;
|
|
36
|
-
stylesheets?:
|
|
36
|
+
stylesheets?: StylesheetsConfig | false;
|
|
37
37
|
tests?: false;
|
|
38
|
-
typescript?:
|
|
39
|
-
}) =>
|
|
38
|
+
typescript?: TypescriptConfig | false;
|
|
39
|
+
}) => Configuration;
|
|
40
40
|
|
|
41
41
|
export { defineConfig, eslintExtensions, stylesheetsExtensions, typescriptExtensions };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Configuration } from 'lint-staged';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
@@ -7,35 +7,35 @@ declare global {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
extensions?: string[];
|
|
10
|
+
interface EslintConfig {
|
|
12
11
|
cache?: boolean;
|
|
13
12
|
config?: string;
|
|
13
|
+
extensions?: string[];
|
|
14
14
|
"fix-type"?: string[];
|
|
15
15
|
"max-warnings"?: number | string | false;
|
|
16
16
|
rules?: string[];
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
exclude?: string[];
|
|
19
|
+
interface StylesheetsConfig {
|
|
21
20
|
extensions?: string[];
|
|
22
|
-
}
|
|
23
|
-
|
|
21
|
+
}
|
|
22
|
+
interface TypescriptConfig {
|
|
23
|
+
exclude?: string[];
|
|
24
24
|
extensions?: string[];
|
|
25
|
-
}
|
|
25
|
+
}
|
|
26
26
|
declare const eslintExtensions: string[];
|
|
27
27
|
declare const typescriptExtensions: string[];
|
|
28
28
|
declare const stylesheetsExtensions: string[];
|
|
29
29
|
declare const defineConfig: (options?: {
|
|
30
|
-
debug?: boolean;
|
|
31
30
|
cwd?: string;
|
|
32
|
-
|
|
31
|
+
debug?: boolean;
|
|
32
|
+
eslint?: EslintConfig | false;
|
|
33
33
|
json?: false;
|
|
34
34
|
markdown?: false;
|
|
35
35
|
secretlint?: false;
|
|
36
|
-
stylesheets?:
|
|
36
|
+
stylesheets?: StylesheetsConfig | false;
|
|
37
37
|
tests?: false;
|
|
38
|
-
typescript?:
|
|
39
|
-
}) =>
|
|
38
|
+
typescript?: TypescriptConfig | false;
|
|
39
|
+
}) => Configuration;
|
|
40
40
|
|
|
41
41
|
export { defineConfig, eslintExtensions, stylesheetsExtensions, typescriptExtensions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Configuration } from 'lint-staged';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
@@ -7,35 +7,35 @@ declare global {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
extensions?: string[];
|
|
10
|
+
interface EslintConfig {
|
|
12
11
|
cache?: boolean;
|
|
13
12
|
config?: string;
|
|
13
|
+
extensions?: string[];
|
|
14
14
|
"fix-type"?: string[];
|
|
15
15
|
"max-warnings"?: number | string | false;
|
|
16
16
|
rules?: string[];
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
exclude?: string[];
|
|
19
|
+
interface StylesheetsConfig {
|
|
21
20
|
extensions?: string[];
|
|
22
|
-
}
|
|
23
|
-
|
|
21
|
+
}
|
|
22
|
+
interface TypescriptConfig {
|
|
23
|
+
exclude?: string[];
|
|
24
24
|
extensions?: string[];
|
|
25
|
-
}
|
|
25
|
+
}
|
|
26
26
|
declare const eslintExtensions: string[];
|
|
27
27
|
declare const typescriptExtensions: string[];
|
|
28
28
|
declare const stylesheetsExtensions: string[];
|
|
29
29
|
declare const defineConfig: (options?: {
|
|
30
|
-
debug?: boolean;
|
|
31
30
|
cwd?: string;
|
|
32
|
-
|
|
31
|
+
debug?: boolean;
|
|
32
|
+
eslint?: EslintConfig | false;
|
|
33
33
|
json?: false;
|
|
34
34
|
markdown?: false;
|
|
35
35
|
secretlint?: false;
|
|
36
|
-
stylesheets?:
|
|
36
|
+
stylesheets?: StylesheetsConfig | false;
|
|
37
37
|
tests?: false;
|
|
38
|
-
typescript?:
|
|
39
|
-
}) =>
|
|
38
|
+
typescript?: TypescriptConfig | false;
|
|
39
|
+
}) => Configuration;
|
|
40
40
|
|
|
41
41
|
export { defineConfig, eslintExtensions, stylesheetsExtensions, typescriptExtensions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var E=Object.defineProperty;var d=(t,e)=>E(t,"name",{value:e,configurable:!0});import{
|
|
1
|
+
var E=Object.defineProperty;var d=(t,e)=>E(t,"name",{value:e,configurable:!0});import{existsSync as _}from"node:fs";import{findUpSync as P,isAccessibleSync as S,readFileSync as A}from"@visulima/fs";import{hasPackageJsonAnyDependency as a,parsePackageJson as T,findPackageManagerSync as O}from"@visulima/package";import{dirname as y,join as N}from"node:path";import{ESLint as C}from"eslint";import{quote as j}from"shell-quote";import{platform as R,env as q}from"node:process";var F=Object.defineProperty,$=d((t,e)=>F(t,"name",{value:e,configurable:!0}),"o$1");const G=$(t=>{const e=P("package.json",{cwd:t});return e&&y(e)},"packageDirectorySync"),L=$(t=>{const e=G(t??process.cwd());if(e?.startsWith("/"))return e;throw new Error(`Cannot determine the nearest root of the package for the file: ${t}!`)},"getNearestPackageRootPath"),D=$(t=>{const e=N(...t);if(e.startsWith("/"))return e;throw new TypeError("Joined path did not return an absolute path.")},"joinPaths"),w=$((t,e)=>{const o=L(e),s=D([o,t]);if(S(s))return s;throw new Error(`Cannot locate nearest "${t}" file!`)},"getNearestConfigPath");var J=Object.defineProperty,H=d((t,e)=>J(t,"name",{value:e,configurable:!0}),"i$1");const I=H(t=>{const e={};return t.forEach(o=>{const s=y(o);e[s]||(e[s]=[]),e[s].push(o)}),e},"groupFilePathsByDirectoryName"),v=R==="win32"||/^(msys|cygwin)$/u.test(q.OSTYPE??"");var M=Object.defineProperty,U=d((t,e)=>M(t,"name",{value:e,configurable:!0}),"o");const W=U(async(t,e=new C)=>{const o=(await Promise.allSettled(t.map(async s=>await e.isPathIgnored(s)))).map(s=>{if(s.status==="fulfilled")return s.value;throw console.error(`
|
|
2
2
|
Unable to determine if file is ignored.
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
${s.reason}`),new Error("Stopping lint-staged because of an error.")});return t.filter((s,n)=>!o[n]).map(s=>`"${v?s:j([s])}"`)},"removeIgnoredFiles");var B=Object.defineProperty,k=d((t,e)=>B(t,"name",{value:e,configurable:!0}),"m");const
|
|
5
|
+
${s.reason}`),new Error("Stopping lint-staged because of an error.")});return t.filter((s,n)=>!o[n]).map(s=>`"${v?s:j([s])}"`)},"removeIgnoredFiles");var B=Object.defineProperty,k=d((t,e)=>B(t,"name",{value:e,configurable:!0}),"m");const m=".eslintrc",Y=k((t,e)=>{const o=[];t["max-warnings"]!==void 0&&Number.isNaN(t["max-warnings"])?o.push(`--max-warnings=${t["max-warnings"]}`):t["max-warnings"]!==!1&&o.push("--max-warnings=0");const s=[];a(e,["eslint-plugin-react-hooks"])&&s.push("react-hooks/exhaustive-deps:off"),a(e,["eslint-plugin-eslint-comments"])&&s.push("eslint-comments/no-unused-disable:off");const n=[...t.rules??[],...s].filter(f=>f.trim().length>0);n.length>0&&o.push(n.map(f=>`--rule "${f}"`).join(" "));const l=[...t["fix-type"]??["layout"]].filter(f=>f.trim().length>0);return l.length>0&&o.push(`--fix-type ${l.join(",")}`,"--fix"),t.cache&&o.push("--cache"),o},"createEslintArguments"),z=k(async(t,e,o,s)=>{const n=await W(s),l=Y(o,e);if(o.config)return l.push(`--config ${o.config}`),[`${t} exec eslint ${l.join(" ")} ${n.join(" ")}`];const f=I(n),p=[];return Object.values(f).forEach(i=>{let r;[m,`${m}.js`,`${m}.cjs`,`${m}.json`,`${m}.yaml`,`${m}.yml`].forEach(x=>{if(!r)try{r=w(x,i[0])}catch{}}),r&&p.push(`${t} exec eslint ${l.join(" ")} --config ${r} ${i.join(" ")}`)}),p},"createEslintCommands");var K=Object.defineProperty,Q=d((t,e)=>K(t,"name",{value:e,configurable:!0}),"r");const c=Q(t=>t.map(e=>`"${v?e:j([e])}"`).join(" ").replaceAll("/@","/@"),"concatFiles");var V=Object.defineProperty,h=d((t,e)=>V(t,"name",{value:e,configurable:!0}),"f");const X=["cjs","js","mjs","cts","ts","mts","yml","yaml","jsx","tsx","mdx","toml","json","json5","jsonc"],Z=["cts","ts","mts","tsx","ctsx"],ee=["css","scss","sass","less","styl","stylus","pcss","postcss","sss"],le=h((t={})=>{const e={debug:!1,eslint:{extensions:X},stylesheets:{extensions:ee},typescript:{exclude:[],extensions:Z},...t},o=e.cwd||process.cwd();if(!_(`${o}/package.json`))throw new Error(`No package.json found in the current working directory: ${o}; Please adjust the "cwd" option.`);const s=T(A(`${o}/package.json`)),{packageManager:n}=O(o);e.debug&&console.debug("Package manager found:",n);const l=a(s,["markdownlint-cli"]),f=a(s,["markdownlint-cli2"]),p=a(s,["prettier"]);let i={};if(e.eslint!==!1&&a(s,["eslint"])){if(!Array.isArray(e.eslint.extensions)||e.eslint.extensions.length===0)throw new Error("The `extensions` option is required for the ESLint configuration.");!l&&!f&&e.eslint.extensions.push("md"),i[`**/*.{${e.eslint.extensions.join(",")}}`]=async r=>[...p?[`${n} exec prettier --write ${c(r)}`]:[],...await z(n,s,e.eslint,r)]}if(e.json!==!1&&a(s,["sort-package-json"])&&(i["**/package.json"]=r=>[`${n} exec sort-package-json ${c(r)}`]),e.markdown!==!1&&l&&(i={...i,"**/*.md":h(r=>[...p?[`${n} exec prettier --write ${c(r)}`]:[],...l?[`${n} exec markdownlint --fix --ignore '**/node_modules/**' --ignore '**/CHANGELOG.md' ${c(r)}`]:[],...f?[`${n} exec markdownlint-cli2 --fix '!**/node_modules/**' '!**/CHANGELOG.md' ${c(r)}`]:[]],"**/*.md"),"**/*.mdx":h(r=>[...p?[`${n} exec prettier --write ${c(r)}`]:[]],"**/*.mdx")}),e.secretlint!==!1&&a(s,["secretlint"])&&(i["**/*"]=r=>[`${n} exec secretlint ${c(r)}`]),e.stylesheets!==!1&&a(s,["stylelint"])){if(!Array.isArray(e.stylesheets.extensions)||e.stylesheets.extensions.length===0)throw new Error("The `extensions` option is required for the Stylesheets configuration.");i[`**/*.{${e.stylesheets.extensions.join(",")}}`]=r=>[...p?[`${n} exec prettier --ignore-unknown --write ${c(r)}`]:[],`${n} exec stylelint --fix`]}if(e.typescript!==!1&&a(s,["typescript"])){if(!Array.isArray(e.typescript.extensions)||e.typescript.extensions.length===0)throw new Error("The `extensions` option is required for the TypeScript configuration.");i[`**/*.{${e.typescript.extensions.join(",")}}`]=r=>{const x=new Set;return r.forEach(g=>{if(typeof e.typescript?.exclude=="object"&&Array.isArray(e.typescript.exclude)){let u=!1;if(e.typescript.exclude.forEach(b=>{!u&&g.includes(b)&&(u=!0)}),u){e.debug&&console.info(`Skipping ${g} as it's excluded in the settings.`);return}}try{const u=w("tsconfig.json",g);x.add(`${n} exec tsc --noEmit --project ${u}`)}catch(u){e.debug&&console.error(u)}}),[...x]}}return a(s,["vitest"])&&(i["**/?(*.){test,spec}.?(c|m)[jt]s?(x)"]=["vitest related --run"],i["**/__tests__/**/*.?(c|m)[jt]s?(x)"]=[`${n} exec vitest related --run`]),a(s,["jest"])&&(i["**/*.spec.{js,ts,tsx}"]=[`${n} exec jest --findRelatedTests`],i["**/*.test.{js,ts,tsx}"]=[`${n} exec jest --findRelatedTests`],i["**/?(*.){test,spec}.?(c|m)[jt]s?(x)"]=[`${n} exec jest --findRelatedTests`],i["**/__mocks__/*.{js,ts,tsx}"]=[`${n} exec jest --findRelatedTests`],i["**/__tests__/**/*.?(c|m)[jt]s?(x)"]=[`${n} exec jest --findRelatedTests`],i["**/__tests__/*.{js,ts,tsx}"]=[`${n} exec jest --findRelatedTests`],i["**/test/*.{js,ts,tsx}"]=[`${n} exec jest --findRelatedTests`]),a(s,["ava"])&&(i["**/(test|tests|__tests__)/**/*.js"]=r=>[`${n} exec ava ${c(r)}`],i["**/*.(spec|test).js"]=r=>[`${n} exec ava ${c(r)}`],i["**/test.js"]=r=>[`${n} exec ava ${c(r)}`],i["**/test-*.js"]=r=>[`${n} exec ava ${c(r)}`]),i},"defineConfig");export{le as defineConfig,X as eslintExtensions,ee as stylesheetsExtensions,Z as typescriptExtensions};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anolilab/lint-staged-config",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "Shareable Lint-Staged Config for any project.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anolilab",
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"type": "module",
|
|
44
44
|
"exports": {
|
|
45
45
|
".": {
|
|
46
|
-
"require": {
|
|
47
|
-
"types": "./dist/index.d.cts",
|
|
48
|
-
"default": "./dist/index.cjs"
|
|
49
|
-
},
|
|
50
46
|
"import": {
|
|
51
47
|
"types": "./dist/index.d.mts",
|
|
52
48
|
"default": "./dist/index.mjs"
|
|
49
|
+
},
|
|
50
|
+
"require": {
|
|
51
|
+
"types": "./dist/index.d.cts",
|
|
52
|
+
"default": "./dist/index.cjs"
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"./package.json": "./package.json"
|
|
@@ -68,10 +68,10 @@
|
|
|
68
68
|
"lint-stage-config:install": "./dist/bin.mjs"
|
|
69
69
|
},
|
|
70
70
|
"files": [
|
|
71
|
-
"dist",
|
|
72
|
-
"README.md",
|
|
73
71
|
"CHANGELOG.md",
|
|
74
|
-
"LICENSE.md"
|
|
72
|
+
"LICENSE.md",
|
|
73
|
+
"README.md",
|
|
74
|
+
"dist"
|
|
75
75
|
],
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@visulima/fs": "3.1.2",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"shell-quote": "^1.8.2"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"eslint": "^
|
|
82
|
+
"eslint": "^9.5",
|
|
83
83
|
"husky": "^8.x || ^9.x",
|
|
84
84
|
"jest": "^27.x || ^28.x",
|
|
85
85
|
"lint-staged": "^13.x || ^14.x|| ^15.x || ^16.x",
|