@anolilab/lint-staged-config 2.0.14 → 2.0.15
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 +7 -0
- package/dist/{chunk-Z7NO74WJ.js → chunk-SAPGJRYB.js} +2 -2
- package/dist/chunk-SAPGJRYB.js.map +1 -0
- package/dist/{chunk-2YQA47MA.mjs → chunk-UFMJP5NU.mjs} +2 -2
- package/dist/chunk-UFMJP5NU.mjs.map +1 -0
- package/dist/groups/eslint/index.js +2 -2
- package/dist/groups/eslint/index.mjs +1 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-2YQA47MA.mjs.map +0 -1
- package/dist/chunk-Z7NO74WJ.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## @anolilab/lint-staged-config [2.0.15](https://github.com/anolilab/javascript-style-guide/compare/@anolilab/lint-staged-config@2.0.14...@anolilab/lint-staged-config@2.0.15) (2023-10-05)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* added missing exec ([ac12738](https://github.com/anolilab/javascript-style-guide/commit/ac12738253ad8b180db3865aaa628a35adb034f5))
|
|
7
|
+
|
|
1
8
|
## @anolilab/lint-staged-config [2.0.14](https://github.com/anolilab/javascript-style-guide/compare/@anolilab/lint-staged-config@2.0.13...@anolilab/lint-staged-config@2.0.14) (2023-10-05)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -12,9 +12,9 @@ var shellQuote = require('shell-quote');
|
|
|
12
12
|
Unable to determine if file is ignored.
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
${e.reason}`),new Error("Stopping lint-staged because of an error.")});return n.filter((e,r)=>!i[r]).map(e=>`"${chunkKP7AH4EU_js.a?e:shellQuote.quote([e])}"`)},w=A;var o=h?.settings?.eslint??{},c=[];(packageJsonUtils.hasDependency("eslint-plugin-react-hooks")||packageJsonUtils.hasDevDependency("eslint-plugin-react-hooks"))&&c.push("react-hooks/exhaustive-deps:off");(packageJsonUtils.hasDependency("eslint-plugin-eslint-comments")||packageJsonUtils.hasDevDependency("eslint-plugin-eslint-comments")||packageJsonUtils.isPackageAvailable("eslint-plugin-eslint-comments"))&&c.push("eslint-comments/no-unused-disable:off");var a=".eslintrc",D=()=>{let n=[];o["max-warnings"]!==void 0&&Number.isNaN(o["max-warnings"])?n.push(`--max-warnings=${o["max-warnings"]}`):o["max-warnings"]!==!1&&n.push("--max-warnings=0");let t=[...o.rules??[],...c].filter(i=>i.trim().length>0);t.length>0&&n.push(t.map(i=>`--rule "${i}"`).join(" "));let s=[...o["fix-type"]??["layout"]].filter(i=>i.trim().length>0);return s.length>0&&n.push(`--fix-type ${s.join(",")}`,"--fix"),o.cache&&n.push("--cache"),n},M=async n=>{let t=await w(n),s=D();if(o.config)return s.push(`--config ${o.config}`),[`${chunkP4FK54EG_js.a()} exec eslint ${s.join(" ")} ${t.join(" ")}`];let i=b(t),g=[];return Object.values(i).forEach(e=>{let r;[a,`${a}.js`,`${a}.cjs`,`${a}.json`,`${a}.yaml`,`${a}.yml`].forEach(j=>{if(!r)try{r=chunkVU6SMFTD_js.a(j,e[0]);}catch{}}),r&&g.push(`${chunkP4FK54EG_js.a()} exec eslint ${s.join(" ")} --config ${r} ${e.join(" ")}`);}),g},m=M;var C=["cjs","js","mjs","cts","ts","mts","yml","yaml","jsx","tsx","mdx","toml"];global.hasAnolilabLintStagedMarkdownCli||(global.hasAnolilabLintStagedMarkdownCli=packageJsonUtils.hasDependency("markdownlint-cli")||packageJsonUtils.hasDevDependency("markdownlint-cli"));global.hasAnolilabLintStagedMarkdownCli2||(global.hasAnolilabLintStagedMarkdownCli2=packageJsonUtils.hasDependency("markdownlint-cli2")||packageJsonUtils.hasDevDependency("markdownlint-cli2"));!global.hasAnolilabLintStagedMarkdownCli&&!global.hasAnolilabLintStagedMarkdownCli2&&C.push("md");var N={[`**/*.{${["json","json5","jsonc"].join(",")}}`]:async n=>[...await m(n)],[`**/*.{${[C].join(",")}}`]:async n=>[`${chunkP4FK54EG_js.a()}
|
|
15
|
+
${e.reason}`),new Error("Stopping lint-staged because of an error.")});return n.filter((e,r)=>!i[r]).map(e=>`"${chunkKP7AH4EU_js.a?e:shellQuote.quote([e])}"`)},w=A;var o=h?.settings?.eslint??{},c=[];(packageJsonUtils.hasDependency("eslint-plugin-react-hooks")||packageJsonUtils.hasDevDependency("eslint-plugin-react-hooks"))&&c.push("react-hooks/exhaustive-deps:off");(packageJsonUtils.hasDependency("eslint-plugin-eslint-comments")||packageJsonUtils.hasDevDependency("eslint-plugin-eslint-comments")||packageJsonUtils.isPackageAvailable("eslint-plugin-eslint-comments"))&&c.push("eslint-comments/no-unused-disable:off");var a=".eslintrc",D=()=>{let n=[];o["max-warnings"]!==void 0&&Number.isNaN(o["max-warnings"])?n.push(`--max-warnings=${o["max-warnings"]}`):o["max-warnings"]!==!1&&n.push("--max-warnings=0");let t=[...o.rules??[],...c].filter(i=>i.trim().length>0);t.length>0&&n.push(t.map(i=>`--rule "${i}"`).join(" "));let s=[...o["fix-type"]??["layout"]].filter(i=>i.trim().length>0);return s.length>0&&n.push(`--fix-type ${s.join(",")}`,"--fix"),o.cache&&n.push("--cache"),n},M=async n=>{let t=await w(n),s=D();if(o.config)return s.push(`--config ${o.config}`),[`${chunkP4FK54EG_js.a()} exec eslint ${s.join(" ")} ${t.join(" ")}`];let i=b(t),g=[];return Object.values(i).forEach(e=>{let r;[a,`${a}.js`,`${a}.cjs`,`${a}.json`,`${a}.yaml`,`${a}.yml`].forEach(j=>{if(!r)try{r=chunkVU6SMFTD_js.a(j,e[0]);}catch{}}),r&&g.push(`${chunkP4FK54EG_js.a()} exec eslint ${s.join(" ")} --config ${r} ${e.join(" ")}`);}),g},m=M;var C=["cjs","js","mjs","cts","ts","mts","yml","yaml","jsx","tsx","mdx","toml"];global.hasAnolilabLintStagedMarkdownCli||(global.hasAnolilabLintStagedMarkdownCli=packageJsonUtils.hasDependency("markdownlint-cli")||packageJsonUtils.hasDevDependency("markdownlint-cli"));global.hasAnolilabLintStagedMarkdownCli2||(global.hasAnolilabLintStagedMarkdownCli2=packageJsonUtils.hasDependency("markdownlint-cli2")||packageJsonUtils.hasDevDependency("markdownlint-cli2"));!global.hasAnolilabLintStagedMarkdownCli&&!global.hasAnolilabLintStagedMarkdownCli2&&C.push("md");var N={[`**/*.{${["json","json5","jsonc"].join(",")}}`]:async n=>[...await m(n)],[`**/*.{${[C].join(",")}}`]:async n=>[`${chunkP4FK54EG_js.a()} exec prettier --write ${chunkKP7AH4EU_js.b(n)}`,...await m(n)]},nn=N;
|
|
16
16
|
|
|
17
17
|
exports.a = h;
|
|
18
18
|
exports.b = nn;
|
|
19
19
|
//# sourceMappingURL=out.js.map
|
|
20
|
-
//# sourceMappingURL=chunk-
|
|
20
|
+
//# sourceMappingURL=chunk-SAPGJRYB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/groups/eslint/index.ts","../src/groups/eslint/create-eslint-commands.ts","../src/utils/lint-staged-config.ts","../src/groups/eslint/group-file-paths-by-directory-name.ts","../src/groups/eslint/remove-ignored-files.ts"],"names":["hasDependency","hasDevDependency","isPackageAvailable","pkg","config","lint_staged_config_default","dirname","groupFilePathsByDirectoryName","filePaths","groups","filePath","directoryName","group_file_paths_by_directory_name_default","ESLint","quote","removeIgnoredFiles","filenames","eslint","ignoredFiles","filename","promise","_","index","is_windows_default","remove_ignored_files_default","eslintSettings","eslintGlobalRulesForFix","configFile","createEslintArguments","eslintArguments","rules","rule","fixType","type","createEslintCommands","filteredFiles","get_package_manager_default","groupedFilesNames","eslintCommands","configName","get_nearest_config_path_default","create_eslint_commands_default","extensions","group","concat_files_default","eslint_default"],"mappings":"+HAAA,OAAS,iBAAAA,EAAe,oBAAAC,MAAwB,+BCAhD,OAAS,iBAAAD,EAAe,oBAAAC,EAAkB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U,OAAQ,GAAGA,CAAU,QAAS,GAAGA,CAAU,QAAS,GAAGA,CAAU,MAAM,EAAE,QAASY,GAAe,CAC3I,GAAI,CAAAnC,EAIJ,GAAI,CAEAA,EAASoC,EAAqBD,EAAY/B,EAAU,CAAC,CAAiB,CAC1E,MAAQ,CAER,CACJ,CAAC,EAEGJ,GACAkC,EAAe,KAAK,GAAGF,EAAkB,CAAC,gBAAgBP,EAAgB,KAAK,GAAG,CAAC,aAAazB,CAAM,IAAII,EAAU,KAAK,GAAG,CAAC,EAAE,CAEvI,CAAC,EAEM8B,CACX,EAEOG,EAAQP,EDzHf,IAAMQ,EAAa,CAAC,MAAO,KAAM,MAAO,MAAO,KAAM,MAAO,MAAO,OAAQ,MAAO,MAAO,MAAO,MAAM,EAEjG,OAAO,mCACR,OAAO,iCAAmC1C,EAAc,kBAAkB,GAAKC,EAAiB,kBAAkB,GAGjH,OAAO,oCACR,OAAO,kCAAoCD,EAAc,mBAAmB,GAAKC,EAAiB,mBAAmB,GAGrH,CAAC,OAAO,kCAAoC,CAAC,OAAO,mCACpDyC,EAAW,KAAK,IAAI,EAGxB,IAAMC,EAAgB,CAClB,CAAC,SAAS,CAAC,OAAQ,QAAS,OAAO,EAAE,KAAK,GAAG,CAAC,GAAG,EAAG,MAAO3B,GAAwB,CAAC,GAAI,MAAMyB,EAAqBzB,CAAS,CAAE,EAC9H,CAAC,SAAS,CAAC0B,CAAU,EAAE,KAAK,GAAG,CAAC,GAAG,EAAG,MAAO1B,GAAwB,CACjE,GAAGoB,EAAkB,CAAC,0BAA0BQ,EAAY5B,CAAS,CAAC,GACtE,GAAI,MAAMyB,EAAqBzB,CAAS,CAC5C,CACJ,EAEO6B,GAAQF","sourcesContent":["import { hasDependency, hasDevDependency } from \"@anolilab/package-json-utils\";\nimport type { Config } from \"lint-staged\";\n\nimport concatFiles from \"../../utils/concat-files\";\nimport getPackageManager from \"../../utils/get-package-manager\";\nimport createEslintCommands from \"./create-eslint-commands\";\n\nconst extensions = [\"cjs\", \"js\", \"mjs\", \"cts\", \"ts\", \"mts\", \"yml\", \"yaml\", \"jsx\", \"tsx\", \"mdx\", \"toml\"];\n\nif (!global.hasAnolilabLintStagedMarkdownCli) {\n global.hasAnolilabLintStagedMarkdownCli = hasDependency(\"markdownlint-cli\") || hasDevDependency(\"markdownlint-cli\");\n}\n\nif (!global.hasAnolilabLintStagedMarkdownCli2) {\n global.hasAnolilabLintStagedMarkdownCli2 = hasDependency(\"markdownlint-cli2\") || hasDevDependency(\"markdownlint-cli2\");\n}\n\nif (!global.hasAnolilabLintStagedMarkdownCli && !global.hasAnolilabLintStagedMarkdownCli2) {\n extensions.push(\"md\");\n}\n\nconst group: Config = {\n [`**/*.{${[\"json\", \"json5\", \"jsonc\"].join(\",\")}}`]: async (filenames: string[]) => [...(await createEslintCommands(filenames))],\n [`**/*.{${[extensions].join(\",\")}}`]: async (filenames: string[]) => [\n `${getPackageManager()} exec prettier --write ${concatFiles(filenames)}`,\n ...(await createEslintCommands(filenames)),\n ],\n};\n\nexport default group;\n","import { hasDependency, hasDevDependency, isPackageAvailable } from \"@anolilab/package-json-utils\";\n\nimport getNearestConfigPath from \"../../utils/get-nearest-config-path\";\nimport getPackageManager from \"../../utils/get-package-manager\";\nimport anolilabLintStagedConfig from \"../../utils/lint-staged-config\";\nimport groupFilePathsByDirectoryName from \"./group-file-paths-by-directory-name\";\nimport removeIgnoredFiles from \"./remove-ignored-files\";\n\ninterface EslintConfig {\n cache?: boolean;\n config?: string;\n \"fix-type\"?: string[];\n \"max-warnings\"?: number | string | false;\n rules?: string[];\n}\n\ninterface ESLintSettings {\n settings?: {\n eslint?: EslintConfig;\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\nconst eslintSettings: EslintConfig = (anolilabLintStagedConfig as ESLintSettings)?.settings?.eslint ?? ({} as EslintConfig);\n\nconst eslintGlobalRulesForFix: string[] = [];\n\nif (hasDependency(\"eslint-plugin-react-hooks\") || hasDevDependency(\"eslint-plugin-react-hooks\")) {\n // react-hooks/eslint and react in general is very strict about exhaustively\n // declaring the dependencies when using the useEffect, useCallback... hooks.\n //\n // In some specific scenarios declaring the deps seems 'less' wanted or 'less' applicable\n // by the developer, leading to some exceptions in the code. That said it should be avoided.\n //\n // While the 'react-hooks/exhaustive-deps' rule is a good rule of thumb, it's not recommended to\n // automatically fix it from lint-staged as it can potentially break a legit intent.\n //\n // Reminder that a good practice is to always declare the dependencies when using the hooks,\n // and if not applicable, add an eslint disable comment to the useEffect, useCallback... such as:\n //\n // // eslint-disable-next-line react-hooks/exhaustive-deps\n //\n // Another approach can be to use hooks such as https://github.com/kentcdodds/use-deep-compare-effect to quickly bypass\n // shallow rendering limitations.\n //\n // @see https://reactjs.org/docs/hooks-rules.html\n // @see https://eslint.org/docs/2.13.1/user-guide/configuring#disabling-rules-with-inline-comments\n eslintGlobalRulesForFix.push(\"react-hooks/exhaustive-deps:off\");\n}\n\nif (\n hasDependency(\"eslint-plugin-eslint-comments\") ||\n hasDevDependency(\"eslint-plugin-eslint-comments\") ||\n isPackageAvailable(\"eslint-plugin-eslint-comments\")\n) {\n eslintGlobalRulesForFix.push(\"eslint-comments/no-unused-disable:off\");\n}\n\nconst configFile = \".eslintrc\";\n\nconst createEslintArguments = (): string[] => {\n const eslintArguments: string[] = [];\n\n if (eslintSettings[\"max-warnings\"] !== undefined && Number.isNaN(eslintSettings[\"max-warnings\"])) {\n eslintArguments.push(`--max-warnings=${eslintSettings[\"max-warnings\"]}`);\n } else if (eslintSettings[\"max-warnings\"] !== false) {\n eslintArguments.push(\"--max-warnings=0\");\n }\n\n const rules = [...(eslintSettings.rules ?? []), ...eslintGlobalRulesForFix].filter((rule) => rule.trim().length > 0);\n\n if (rules.length > 0) {\n eslintArguments.push(rules.map((rule) => `--rule \"${rule}\"`).join(\" \"));\n }\n\n // For lint-staged it's safer to not apply the fix command if it changes the AST\n // @see https://eslint.org/docs/user-guide/command-line-interface#--fix-type\n const fixType = [...(eslintSettings[\"fix-type\"] ?? [\"layout\"])].filter((type) => type.trim().length > 0);\n\n if (fixType.length > 0) {\n eslintArguments.push(`--fix-type ${fixType.join(\",\")}`, \"--fix\");\n }\n\n if (eslintSettings.cache) {\n eslintArguments.push(\"--cache\");\n }\n\n return eslintArguments;\n};\n\nconst createEslintCommands = async (filenames: string[]): Promise<string[]> => {\n const filteredFiles = await removeIgnoredFiles(filenames);\n\n const eslintArguments = createEslintArguments();\n\n if (eslintSettings.config) {\n eslintArguments.push(`--config ${eslintSettings.config}`);\n\n return [`${getPackageManager()} exec eslint ${eslintArguments.join(\" \")} ${filteredFiles.join(\" \")}`];\n }\n\n const groupedFilesNames = groupFilePathsByDirectoryName(filteredFiles);\n const eslintCommands: string[] = [];\n\n Object.values(groupedFilesNames).forEach((filePaths) => {\n let config: string | undefined;\n\n [configFile, `${configFile}.js`, `${configFile}.cjs`, `${configFile}.json`, `${configFile}.yaml`, `${configFile}.yml`].forEach((configName) => {\n if (config) {\n return;\n }\n\n try {\n // eslint-disable-next-line no-template-curly-in-string\n config = getNearestConfigPath(configName, filePaths[0] as \"/${string}\") as string;\n } catch {\n // Ignore\n }\n });\n\n if (config) {\n eslintCommands.push(`${getPackageManager()} exec eslint ${eslintArguments.join(\" \")} --config ${config} ${filePaths.join(\" \")}`);\n }\n });\n\n return eslintCommands;\n};\n\nexport default createEslintCommands;\n","import { pkg } from \"@anolilab/package-json-utils\";\n\nif (!global.anolilabLintStagedPackageJsonConfig && pkg) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access\n global.anolilabLintStagedPackageJsonConfig = pkg[\"anolilab\"]?.[\"lint-staged-config\"];\n}\n\nconst config: Record<string, boolean | undefined> = global.anolilabLintStagedPackageJsonConfig ?? {};\n\nexport default config;\n","import { dirname } from \"node:path\";\n\nconst groupFilePathsByDirectoryName = (filePaths: string[]): Record<string, string[]> => {\n const groups: Record<string, string[]> = {};\n\n filePaths.forEach((filePath) => {\n const directoryName = dirname(filePath);\n\n // eslint-disable-next-line security/detect-object-injection\n if (!groups[directoryName]) {\n // eslint-disable-next-line security/detect-object-injection\n groups[directoryName] = [];\n }\n // eslint-disable-next-line security/detect-object-injection\n (groups[directoryName] as string[]).push(filePath);\n });\n\n return groups;\n};\n\nexport default groupFilePathsByDirectoryName;\n","import { ESLint } from \"eslint\";\nimport { quote } from \"shell-quote\";\n\nimport isWindows from \"../../utils/is-windows\";\n\nconst removeIgnoredFiles = async (filenames: string[]): Promise<string[]> => {\n const eslint = new ESLint();\n // eslint-disable-next-line compat/compat\n const promises = await Promise.allSettled(filenames.map(async (filename) => await eslint.isPathIgnored(filename)));\n const ignoredFiles = promises.map((promise) => {\n if (promise.status === \"fulfilled\") {\n return promise.value;\n }\n\n console.error(`\\nUnable to determine if file is ignored.\\n\\n\\n${promise.reason}`);\n\n throw new Error(\"Stopping lint-staged because of an error.\");\n });\n\n // eslint-disable-next-line security/detect-object-injection\n const filteredFiles = filenames.filter((_, index) => !ignoredFiles[index]);\n\n return filteredFiles.map((filename) => `\"${isWindows ? filename : quote([filename])}\"`);\n};\n\nexport default removeIgnoredFiles;\n"]}
|
|
@@ -10,8 +10,8 @@ import { quote } from 'shell-quote';
|
|
|
10
10
|
Unable to determine if file is ignored.
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
${e.reason}`),new Error("Stopping lint-staged because of an error.")});return n.filter((e,r)=>!i[r]).map(e=>`"${a$3?e:quote([e])}"`)},w=A;var o=h?.settings?.eslint??{},c=[];(hasDependency("eslint-plugin-react-hooks")||hasDevDependency("eslint-plugin-react-hooks"))&&c.push("react-hooks/exhaustive-deps:off");(hasDependency("eslint-plugin-eslint-comments")||hasDevDependency("eslint-plugin-eslint-comments")||isPackageAvailable("eslint-plugin-eslint-comments"))&&c.push("eslint-comments/no-unused-disable:off");var a=".eslintrc",D=()=>{let n=[];o["max-warnings"]!==void 0&&Number.isNaN(o["max-warnings"])?n.push(`--max-warnings=${o["max-warnings"]}`):o["max-warnings"]!==!1&&n.push("--max-warnings=0");let t=[...o.rules??[],...c].filter(i=>i.trim().length>0);t.length>0&&n.push(t.map(i=>`--rule "${i}"`).join(" "));let s=[...o["fix-type"]??["layout"]].filter(i=>i.trim().length>0);return s.length>0&&n.push(`--fix-type ${s.join(",")}`,"--fix"),o.cache&&n.push("--cache"),n},M=async n=>{let t=await w(n),s=D();if(o.config)return s.push(`--config ${o.config}`),[`${a$1()} exec eslint ${s.join(" ")} ${t.join(" ")}`];let i=b(t),g=[];return Object.values(i).forEach(e=>{let r;[a,`${a}.js`,`${a}.cjs`,`${a}.json`,`${a}.yaml`,`${a}.yml`].forEach(j=>{if(!r)try{r=a$2(j,e[0]);}catch{}}),r&&g.push(`${a$1()} exec eslint ${s.join(" ")} --config ${r} ${e.join(" ")}`);}),g},m=M;var C=["cjs","js","mjs","cts","ts","mts","yml","yaml","jsx","tsx","mdx","toml"];global.hasAnolilabLintStagedMarkdownCli||(global.hasAnolilabLintStagedMarkdownCli=hasDependency("markdownlint-cli")||hasDevDependency("markdownlint-cli"));global.hasAnolilabLintStagedMarkdownCli2||(global.hasAnolilabLintStagedMarkdownCli2=hasDependency("markdownlint-cli2")||hasDevDependency("markdownlint-cli2"));!global.hasAnolilabLintStagedMarkdownCli&&!global.hasAnolilabLintStagedMarkdownCli2&&C.push("md");var N={[`**/*.{${["json","json5","jsonc"].join(",")}}`]:async n=>[...await m(n)],[`**/*.{${[C].join(",")}}`]:async n=>[`${a$1()}
|
|
13
|
+
${e.reason}`),new Error("Stopping lint-staged because of an error.")});return n.filter((e,r)=>!i[r]).map(e=>`"${a$3?e:quote([e])}"`)},w=A;var o=h?.settings?.eslint??{},c=[];(hasDependency("eslint-plugin-react-hooks")||hasDevDependency("eslint-plugin-react-hooks"))&&c.push("react-hooks/exhaustive-deps:off");(hasDependency("eslint-plugin-eslint-comments")||hasDevDependency("eslint-plugin-eslint-comments")||isPackageAvailable("eslint-plugin-eslint-comments"))&&c.push("eslint-comments/no-unused-disable:off");var a=".eslintrc",D=()=>{let n=[];o["max-warnings"]!==void 0&&Number.isNaN(o["max-warnings"])?n.push(`--max-warnings=${o["max-warnings"]}`):o["max-warnings"]!==!1&&n.push("--max-warnings=0");let t=[...o.rules??[],...c].filter(i=>i.trim().length>0);t.length>0&&n.push(t.map(i=>`--rule "${i}"`).join(" "));let s=[...o["fix-type"]??["layout"]].filter(i=>i.trim().length>0);return s.length>0&&n.push(`--fix-type ${s.join(",")}`,"--fix"),o.cache&&n.push("--cache"),n},M=async n=>{let t=await w(n),s=D();if(o.config)return s.push(`--config ${o.config}`),[`${a$1()} exec eslint ${s.join(" ")} ${t.join(" ")}`];let i=b(t),g=[];return Object.values(i).forEach(e=>{let r;[a,`${a}.js`,`${a}.cjs`,`${a}.json`,`${a}.yaml`,`${a}.yml`].forEach(j=>{if(!r)try{r=a$2(j,e[0]);}catch{}}),r&&g.push(`${a$1()} exec eslint ${s.join(" ")} --config ${r} ${e.join(" ")}`);}),g},m=M;var C=["cjs","js","mjs","cts","ts","mts","yml","yaml","jsx","tsx","mdx","toml"];global.hasAnolilabLintStagedMarkdownCli||(global.hasAnolilabLintStagedMarkdownCli=hasDependency("markdownlint-cli")||hasDevDependency("markdownlint-cli"));global.hasAnolilabLintStagedMarkdownCli2||(global.hasAnolilabLintStagedMarkdownCli2=hasDependency("markdownlint-cli2")||hasDevDependency("markdownlint-cli2"));!global.hasAnolilabLintStagedMarkdownCli&&!global.hasAnolilabLintStagedMarkdownCli2&&C.push("md");var N={[`**/*.{${["json","json5","jsonc"].join(",")}}`]:async n=>[...await m(n)],[`**/*.{${[C].join(",")}}`]:async n=>[`${a$1()} exec prettier --write ${b$1(n)}`,...await m(n)]},nn=N;
|
|
14
14
|
|
|
15
15
|
export { h as a, nn as b };
|
|
16
16
|
//# sourceMappingURL=out.js.map
|
|
17
|
-
//# sourceMappingURL=chunk-
|
|
17
|
+
//# sourceMappingURL=chunk-UFMJP5NU.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/groups/eslint/index.ts","../src/groups/eslint/create-eslint-commands.ts","../src/utils/lint-staged-config.ts","../src/groups/eslint/group-file-paths-by-directory-name.ts","../src/groups/eslint/remove-ignored-files.ts"],"names":["hasDependency","hasDevDependency","isPackageAvailable","pkg","config","lint_staged_config_default","dirname","groupFilePathsByDirectoryName","filePaths","groups","filePath","directoryName","group_file_paths_by_directory_name_default","ESLint","quote","removeIgnoredFiles","filenames","eslint","ignoredFiles","filename","promise","_","index","is_windows_default","remove_ignored_files_default","eslintSettings","eslintGlobalRulesForFix","configFile","createEslintArguments","eslintArguments","rules","rule","fixType","type","createEslintCommands","filteredFiles","get_package_manager_default","groupedFilesNames","eslintCommands","configName","get_nearest_config_path_default","create_eslint_commands_default","extensions","group","concat_files_default","eslint_default"],"mappings":"kIAAA,OAAS,iBAAAA,EAAe,oBAAAC,MAAwB,+BCAhD,OAAS,iBAAAD,EAAe,oBAAAC,EAAkB,sBAAAC,MAA0B,+BCApE,OAAS,OAAAC,MAAW,+BAEhB,CAAC,OAAO,qCAAuCA,IAE/C,OAAO,oCAAsCA,EAAI,WAAc,oBAAoB,GAGvF,IAAMC,EAA8C,OAAO,qCAAuC,CAAC,EAE5FC,EAAQD,ECTf,OAAS,WAAAE,MAAe,OAExB,IAAMC,EAAiCC,GAAkD,CACrF,IAAMC,EAAmC,CAAC,EAE1C,OAAAD,EAAU,QAASE,GAAa,CAC5B,IAAMC,EAAgBL,EAAQI,CAAQ,EAGjCD,EAAOE,CAAa,IAErBF,EAAOE,CAAa,EAAI,CAAC,GAG5BF,EAAOE,CAAa,EAAe,KAAKD,CAAQ,CACrD,CAAC,EAEMD,CACX,EAEOG,EAAQL,ECpBf,OAAS,UAAAM,MAAc,SACvB,OAAS,SAAAC,MAAa,cAItB,IAAMC,EAAqB,MAAOC,GAA2C,CACzE,IAAMC,EAAS,IAAIJ,EAGbK,GADW,MAAM,QAAQ,WAAWF,EAAU,IAAI,MAAOG,GAAa,MAAMF,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O,kCAAoC,CAAC,OAAO,mCACpDyC,EAAW,KAAK,IAAI,EAGxB,IAAMC,EAAgB,CAClB,CAAC,SAAS,CAAC,OAAQ,QAAS,OAAO,EAAE,KAAK,GAAG,CAAC,GAAG,EAAG,MAAO3B,GAAwB,CAAC,GAAI,MAAMyB,EAAqBzB,CAAS,CAAE,EAC9H,CAAC,SAAS,CAAC0B,CAAU,EAAE,KAAK,GAAG,CAAC,GAAG,EAAG,MAAO1B,GAAwB,CACjE,GAAGoB,EAAkB,CAAC,0BAA0BQ,EAAY5B,CAAS,CAAC,GACtE,GAAI,MAAMyB,EAAqBzB,CAAS,CAC5C,CACJ,EAEO6B,GAAQF","sourcesContent":["import { hasDependency, hasDevDependency } from \"@anolilab/package-json-utils\";\nimport type { Config } from \"lint-staged\";\n\nimport concatFiles from \"../../utils/concat-files\";\nimport getPackageManager from \"../../utils/get-package-manager\";\nimport createEslintCommands from \"./create-eslint-commands\";\n\nconst extensions = [\"cjs\", \"js\", \"mjs\", \"cts\", \"ts\", \"mts\", \"yml\", \"yaml\", \"jsx\", \"tsx\", \"mdx\", \"toml\"];\n\nif (!global.hasAnolilabLintStagedMarkdownCli) {\n global.hasAnolilabLintStagedMarkdownCli = hasDependency(\"markdownlint-cli\") || hasDevDependency(\"markdownlint-cli\");\n}\n\nif (!global.hasAnolilabLintStagedMarkdownCli2) {\n global.hasAnolilabLintStagedMarkdownCli2 = hasDependency(\"markdownlint-cli2\") || hasDevDependency(\"markdownlint-cli2\");\n}\n\nif (!global.hasAnolilabLintStagedMarkdownCli && !global.hasAnolilabLintStagedMarkdownCli2) {\n extensions.push(\"md\");\n}\n\nconst group: Config = {\n [`**/*.{${[\"json\", \"json5\", \"jsonc\"].join(\",\")}}`]: async (filenames: string[]) => [...(await createEslintCommands(filenames))],\n [`**/*.{${[extensions].join(\",\")}}`]: async (filenames: string[]) => [\n `${getPackageManager()} exec prettier --write ${concatFiles(filenames)}`,\n ...(await createEslintCommands(filenames)),\n ],\n};\n\nexport default group;\n","import { hasDependency, hasDevDependency, isPackageAvailable } from \"@anolilab/package-json-utils\";\n\nimport getNearestConfigPath from \"../../utils/get-nearest-config-path\";\nimport getPackageManager from \"../../utils/get-package-manager\";\nimport anolilabLintStagedConfig from \"../../utils/lint-staged-config\";\nimport groupFilePathsByDirectoryName from \"./group-file-paths-by-directory-name\";\nimport removeIgnoredFiles from \"./remove-ignored-files\";\n\ninterface EslintConfig {\n cache?: boolean;\n config?: string;\n \"fix-type\"?: string[];\n \"max-warnings\"?: number | string | false;\n rules?: string[];\n}\n\ninterface ESLintSettings {\n settings?: {\n eslint?: EslintConfig;\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\nconst eslintSettings: EslintConfig = (anolilabLintStagedConfig as ESLintSettings)?.settings?.eslint ?? ({} as EslintConfig);\n\nconst eslintGlobalRulesForFix: string[] = [];\n\nif (hasDependency(\"eslint-plugin-react-hooks\") || hasDevDependency(\"eslint-plugin-react-hooks\")) {\n // react-hooks/eslint and react in general is very strict about exhaustively\n // declaring the dependencies when using the useEffect, useCallback... hooks.\n //\n // In some specific scenarios declaring the deps seems 'less' wanted or 'less' applicable\n // by the developer, leading to some exceptions in the code. That said it should be avoided.\n //\n // While the 'react-hooks/exhaustive-deps' rule is a good rule of thumb, it's not recommended to\n // automatically fix it from lint-staged as it can potentially break a legit intent.\n //\n // Reminder that a good practice is to always declare the dependencies when using the hooks,\n // and if not applicable, add an eslint disable comment to the useEffect, useCallback... such as:\n //\n // // eslint-disable-next-line react-hooks/exhaustive-deps\n //\n // Another approach can be to use hooks such as https://github.com/kentcdodds/use-deep-compare-effect to quickly bypass\n // shallow rendering limitations.\n //\n // @see https://reactjs.org/docs/hooks-rules.html\n // @see https://eslint.org/docs/2.13.1/user-guide/configuring#disabling-rules-with-inline-comments\n eslintGlobalRulesForFix.push(\"react-hooks/exhaustive-deps:off\");\n}\n\nif (\n hasDependency(\"eslint-plugin-eslint-comments\") ||\n hasDevDependency(\"eslint-plugin-eslint-comments\") ||\n isPackageAvailable(\"eslint-plugin-eslint-comments\")\n) {\n eslintGlobalRulesForFix.push(\"eslint-comments/no-unused-disable:off\");\n}\n\nconst configFile = \".eslintrc\";\n\nconst createEslintArguments = (): string[] => {\n const eslintArguments: string[] = [];\n\n if (eslintSettings[\"max-warnings\"] !== undefined && Number.isNaN(eslintSettings[\"max-warnings\"])) {\n eslintArguments.push(`--max-warnings=${eslintSettings[\"max-warnings\"]}`);\n } else if (eslintSettings[\"max-warnings\"] !== false) {\n eslintArguments.push(\"--max-warnings=0\");\n }\n\n const rules = [...(eslintSettings.rules ?? []), ...eslintGlobalRulesForFix].filter((rule) => rule.trim().length > 0);\n\n if (rules.length > 0) {\n eslintArguments.push(rules.map((rule) => `--rule \"${rule}\"`).join(\" \"));\n }\n\n // For lint-staged it's safer to not apply the fix command if it changes the AST\n // @see https://eslint.org/docs/user-guide/command-line-interface#--fix-type\n const fixType = [...(eslintSettings[\"fix-type\"] ?? [\"layout\"])].filter((type) => type.trim().length > 0);\n\n if (fixType.length > 0) {\n eslintArguments.push(`--fix-type ${fixType.join(\",\")}`, \"--fix\");\n }\n\n if (eslintSettings.cache) {\n eslintArguments.push(\"--cache\");\n }\n\n return eslintArguments;\n};\n\nconst createEslintCommands = async (filenames: string[]): Promise<string[]> => {\n const filteredFiles = await removeIgnoredFiles(filenames);\n\n const eslintArguments = createEslintArguments();\n\n if (eslintSettings.config) {\n eslintArguments.push(`--config ${eslintSettings.config}`);\n\n return [`${getPackageManager()} exec eslint ${eslintArguments.join(\" \")} ${filteredFiles.join(\" \")}`];\n }\n\n const groupedFilesNames = groupFilePathsByDirectoryName(filteredFiles);\n const eslintCommands: string[] = [];\n\n Object.values(groupedFilesNames).forEach((filePaths) => {\n let config: string | undefined;\n\n [configFile, `${configFile}.js`, `${configFile}.cjs`, `${configFile}.json`, `${configFile}.yaml`, `${configFile}.yml`].forEach((configName) => {\n if (config) {\n return;\n }\n\n try {\n // eslint-disable-next-line no-template-curly-in-string\n config = getNearestConfigPath(configName, filePaths[0] as \"/${string}\") as string;\n } catch {\n // Ignore\n }\n });\n\n if (config) {\n eslintCommands.push(`${getPackageManager()} exec eslint ${eslintArguments.join(\" \")} --config ${config} ${filePaths.join(\" \")}`);\n }\n });\n\n return eslintCommands;\n};\n\nexport default createEslintCommands;\n","import { pkg } from \"@anolilab/package-json-utils\";\n\nif (!global.anolilabLintStagedPackageJsonConfig && pkg) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access\n global.anolilabLintStagedPackageJsonConfig = pkg[\"anolilab\"]?.[\"lint-staged-config\"];\n}\n\nconst config: Record<string, boolean | undefined> = global.anolilabLintStagedPackageJsonConfig ?? {};\n\nexport default config;\n","import { dirname } from \"node:path\";\n\nconst groupFilePathsByDirectoryName = (filePaths: string[]): Record<string, string[]> => {\n const groups: Record<string, string[]> = {};\n\n filePaths.forEach((filePath) => {\n const directoryName = dirname(filePath);\n\n // eslint-disable-next-line security/detect-object-injection\n if (!groups[directoryName]) {\n // eslint-disable-next-line security/detect-object-injection\n groups[directoryName] = [];\n }\n // eslint-disable-next-line security/detect-object-injection\n (groups[directoryName] as string[]).push(filePath);\n });\n\n return groups;\n};\n\nexport default groupFilePathsByDirectoryName;\n","import { ESLint } from \"eslint\";\nimport { quote } from \"shell-quote\";\n\nimport isWindows from \"../../utils/is-windows\";\n\nconst removeIgnoredFiles = async (filenames: string[]): Promise<string[]> => {\n const eslint = new ESLint();\n // eslint-disable-next-line compat/compat\n const promises = await Promise.allSettled(filenames.map(async (filename) => await eslint.isPathIgnored(filename)));\n const ignoredFiles = promises.map((promise) => {\n if (promise.status === \"fulfilled\") {\n return promise.value;\n }\n\n console.error(`\\nUnable to determine if file is ignored.\\n\\n\\n${promise.reason}`);\n\n throw new Error(\"Stopping lint-staged because of an error.\");\n });\n\n // eslint-disable-next-line security/detect-object-injection\n const filteredFiles = filenames.filter((_, index) => !ignoredFiles[index]);\n\n return filteredFiles.map((filename) => `\"${isWindows ? filename : quote([filename])}\"`);\n};\n\nexport default removeIgnoredFiles;\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkSAPGJRYB_js = require('../../chunk-SAPGJRYB.js');
|
|
4
4
|
require('../../chunk-VU6SMFTD.js');
|
|
5
5
|
require('../../chunk-KP7AH4EU.js');
|
|
6
6
|
require('../../chunk-P4FK54EG.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
module.exports =
|
|
10
|
+
module.exports = chunkSAPGJRYB_js.b;
|
|
11
11
|
//# sourceMappingURL=out.js.map
|
|
12
12
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkLROKPUXN_js = require('./chunk-LROKPUXN.js');
|
|
4
|
-
var
|
|
4
|
+
var chunkSAPGJRYB_js = require('./chunk-SAPGJRYB.js');
|
|
5
5
|
require('./chunk-VU6SMFTD.js');
|
|
6
6
|
var chunkTNK6LFGX_js = require('./chunk-TNK6LFGX.js');
|
|
7
7
|
var chunk4PAU4XRY_js = require('./chunk-4PAU4XRY.js');
|
|
@@ -13,7 +13,7 @@ require('./chunk-P4FK54EG.js');
|
|
|
13
13
|
var process = require('process');
|
|
14
14
|
var packageJsonUtils = require('@anolilab/package-json-utils');
|
|
15
15
|
|
|
16
|
-
var y=[{config:
|
|
16
|
+
var y=[{config:chunkSAPGJRYB_js.b,configName:"eslint",dependencies:["prettier","eslint"]},{config:chunkTNK6LFGX_js.a,configName:"json",dependencies:["prettier","sort-package-json"]},{config:chunk4PAU4XRY_js.a,configName:"markdown",dependencies:["prettier","markdownlint-cli","markdownlint-cli2"]},{config:chunk6IRNLWX6_js.a,configName:"secretlint",dependencies:["secretlint"]},{config:chunk5J6LVG23_js.a,configName:"stylesheets",dependencies:["stylelint"]},{config:chunkAUGHUNNL_js.a,configName:"tests",dependencies:["vite","jest","ava"]},{config:chunkLROKPUXN_js.a,configName:"typescript",dependencies:["typescript"]}],g={},r=[],a={};y.forEach(t=>{let{config:n,configName:i,dependencies:l}=t;if(chunkSAPGJRYB_js.a.plugin?.[i]!==!1){let s=[];l.forEach(e=>{(packageJsonUtils.hasDependency(e)||packageJsonUtils.hasDevDependency(e))&&s.push(e);}),s.length>0?(g={...g,...n},r.push(i)):(a[i]={},l.forEach(e=>{a[i][e]=packageJsonUtils.hasDependency(e)||packageJsonUtils.hasDevDependency(e);}));}});var w={...g};var j=()=>{},k=t=>process.env.NO_LOGS?j:n=>console.log(`${t}${n}`),O=k(""),o=O;if(!global.hasAnolilabStagedLintConfigLoaded){process.env.DEBUG&&(o(`
|
|
17
17
|
@anolilab/lint-stage-config loaded the following plugins:
|
|
18
18
|
`),r.forEach(n=>{o(` ${n}`);}));let t=!1;Object.entries(a).forEach(([n,i])=>{Object.values(i).some(Boolean)&&(t=!0,o(`
|
|
19
19
|
Your package.json container dependencies for the "${n}" plugin, please add the following dependencies with your chosen package manager to enable this plugin:`),Object.entries(i).forEach(([s,e])=>{e||o(` ${s}`);}));}),t&&(o(`
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as a$7 } from './chunk-2ADQIOER.mjs';
|
|
2
|
-
import { a as a$1, b } from './chunk-
|
|
2
|
+
import { a as a$1, b } from './chunk-UFMJP5NU.mjs';
|
|
3
3
|
import './chunk-HGDREIGE.mjs';
|
|
4
4
|
import { a as a$2 } from './chunk-SPRVGS3T.mjs';
|
|
5
5
|
import { a as a$3 } from './chunk-Q3OATPM3.mjs';
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/groups/eslint/index.ts","../src/groups/eslint/create-eslint-commands.ts","../src/utils/lint-staged-config.ts","../src/groups/eslint/group-file-paths-by-directory-name.ts","../src/groups/eslint/remove-ignored-files.ts"],"names":["hasDependency","hasDevDependency","isPackageAvailable","pkg","config","lint_staged_config_default","dirname","groupFilePathsByDirectoryName","filePaths","groups","filePath","directoryName","group_file_paths_by_directory_name_default","ESLint","quote","removeIgnoredFiles","filenames","eslint","ignoredFiles","filename","promise","_","index","is_windows_default","remove_ignored_files_default","eslintSettings","eslintGlobalRulesForFix","configFile","createEslintArguments","eslintArguments","rules","rule","fixType","type","createEslintCommands","filteredFiles","get_package_manager_default","groupedFilesNames","eslintCommands","configName","get_nearest_config_path_default","create_eslint_commands_default","extensions","group","concat_files_default","eslint_default"],"mappings":"kIAAA,OAAS,iBAAAA,EAAe,oBAAAC,MAAwB,+BCAhD,OAAS,iBAAAD,EAAe,oBAAAC,EAAkB,sBAAAC,MAA0B,+BCApE,OAAS,OAAAC,MAAW,+BAEhB,CAAC,OAAO,qCAAuCA,IAE/C,OAAO,oCAAsCA,EAAI,WAAc,oBAAoB,GAGvF,IAAMC,EAA8C,OAAO,qCAAuC,CAAC,EAE5FC,EAAQD,ECTf,OAAS,WAAAE,MAAe,OAExB,IAAMC,EAAiCC,GAAkD,CACrF,IAAMC,EAAmC,CAAC,EAE1C,OAAAD,EAAU,QAASE,GAAa,CAC5B,IAAMC,EAAgBL,EAAQI,CAAQ,EAGjCD,EAAOE,CAAa,IAErBF,EAAOE,CAAa,EAAI,CAAC,GAG5BF,EAAOE,CAAa,EAAe,KAAKD,CAAQ,CACrD,CAAC,EAEMD,CACX,EAEOG,EAAQL,ECpBf,OAAS,UAAAM,MAAc,SACvB,OAAS,SAAAC,MAAa,cAItB,IAAMC,EAAqB,MAAOC,GAA2C,CACzE,IAAMC,EAAS,IAAIJ,EAGbK,GADW,MAAM,QAAQ,WAAWF,EAAU,IAAI,MAAOG,GAAa,MAAMF,EAAO,cAAcE,CAAQ,CAAC,CAAC,GACnF,IAAKC,GAAY,CAC3C,GAAIA,EAAQ,SAAW,YACnB,OAAOA,EAAQ,MAGnB,cAAQ,MAAM;AAAA;AAAA;AA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AAC,GAAG,EAAG,MAAO3B,GAAwB,CAAC,GAAI,MAAMyB,EAAqBzB,CAAS,CAAE,EAC9H,CAAC,SAAS,CAAC0B,CAAU,EAAE,KAAK,GAAG,CAAC,GAAG,EAAG,MAAO1B,GAAwB,CACjE,GAAGoB,EAAkB,CAAC,yBAAyBQ,EAAY5B,CAAS,CAAC,GACrE,GAAI,MAAMyB,EAAqBzB,CAAS,CAC5C,CACJ,EAEO6B,GAAQF","sourcesContent":["import { hasDependency, hasDevDependency } from \"@anolilab/package-json-utils\";\nimport type { Config } from \"lint-staged\";\n\nimport concatFiles from \"../../utils/concat-files\";\nimport getPackageManager from \"../../utils/get-package-manager\";\nimport createEslintCommands from \"./create-eslint-commands\";\n\nconst extensions = [\"cjs\", \"js\", \"mjs\", \"cts\", \"ts\", \"mts\", \"yml\", \"yaml\", \"jsx\", \"tsx\", \"mdx\", \"toml\"];\n\nif (!global.hasAnolilabLintStagedMarkdownCli) {\n global.hasAnolilabLintStagedMarkdownCli = hasDependency(\"markdownlint-cli\") || hasDevDependency(\"markdownlint-cli\");\n}\n\nif (!global.hasAnolilabLintStagedMarkdownCli2) {\n global.hasAnolilabLintStagedMarkdownCli2 = hasDependency(\"markdownlint-cli2\") || hasDevDependency(\"markdownlint-cli2\");\n}\n\nif (!global.hasAnolilabLintStagedMarkdownCli && !global.hasAnolilabLintStagedMarkdownCli2) {\n extensions.push(\"md\");\n}\n\nconst group: Config = {\n [`**/*.{${[\"json\", \"json5\", \"jsonc\"].join(\",\")}}`]: async (filenames: string[]) => [...(await createEslintCommands(filenames))],\n [`**/*.{${[extensions].join(\",\")}}`]: async (filenames: string[]) => [\n `${getPackageManager()} execprettier --write ${concatFiles(filenames)}`,\n ...(await createEslintCommands(filenames)),\n ],\n};\n\nexport default group;\n","import { hasDependency, hasDevDependency, isPackageAvailable } from \"@anolilab/package-json-utils\";\n\nimport getNearestConfigPath from \"../../utils/get-nearest-config-path\";\nimport getPackageManager from \"../../utils/get-package-manager\";\nimport anolilabLintStagedConfig from \"../../utils/lint-staged-config\";\nimport groupFilePathsByDirectoryName from \"./group-file-paths-by-directory-name\";\nimport removeIgnoredFiles from \"./remove-ignored-files\";\n\ninterface EslintConfig {\n cache?: boolean;\n config?: string;\n \"fix-type\"?: string[];\n \"max-warnings\"?: number | string | false;\n rules?: string[];\n}\n\ninterface ESLintSettings {\n settings?: {\n eslint?: EslintConfig;\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\nconst eslintSettings: EslintConfig = (anolilabLintStagedConfig as ESLintSettings)?.settings?.eslint ?? ({} as EslintConfig);\n\nconst eslintGlobalRulesForFix: string[] = [];\n\nif (hasDependency(\"eslint-plugin-react-hooks\") || hasDevDependency(\"eslint-plugin-react-hooks\")) {\n // react-hooks/eslint and react in general is very strict about exhaustively\n // declaring the dependencies when using the useEffect, useCallback... hooks.\n //\n // In some specific scenarios declaring the deps seems 'less' wanted or 'less' applicable\n // by the developer, leading to some exceptions in the code. That said it should be avoided.\n //\n // While the 'react-hooks/exhaustive-deps' rule is a good rule of thumb, it's not recommended to\n // automatically fix it from lint-staged as it can potentially break a legit intent.\n //\n // Reminder that a good practice is to always declare the dependencies when using the hooks,\n // and if not applicable, add an eslint disable comment to the useEffect, useCallback... such as:\n //\n // // eslint-disable-next-line react-hooks/exhaustive-deps\n //\n // Another approach can be to use hooks such as https://github.com/kentcdodds/use-deep-compare-effect to quickly bypass\n // shallow rendering limitations.\n //\n // @see https://reactjs.org/docs/hooks-rules.html\n // @see https://eslint.org/docs/2.13.1/user-guide/configuring#disabling-rules-with-inline-comments\n eslintGlobalRulesForFix.push(\"react-hooks/exhaustive-deps:off\");\n}\n\nif (\n hasDependency(\"eslint-plugin-eslint-comments\") ||\n hasDevDependency(\"eslint-plugin-eslint-comments\") ||\n isPackageAvailable(\"eslint-plugin-eslint-comments\")\n) {\n eslintGlobalRulesForFix.push(\"eslint-comments/no-unused-disable:off\");\n}\n\nconst configFile = \".eslintrc\";\n\nconst createEslintArguments = (): string[] => {\n const eslintArguments: string[] = [];\n\n if (eslintSettings[\"max-warnings\"] !== undefined && Number.isNaN(eslintSettings[\"max-warnings\"])) {\n eslintArguments.push(`--max-warnings=${eslintSettings[\"max-warnings\"]}`);\n } else if (eslintSettings[\"max-warnings\"] !== false) {\n eslintArguments.push(\"--max-warnings=0\");\n }\n\n const rules = [...(eslintSettings.rules ?? []), ...eslintGlobalRulesForFix].filter((rule) => rule.trim().length > 0);\n\n if (rules.length > 0) {\n eslintArguments.push(rules.map((rule) => `--rule \"${rule}\"`).join(\" \"));\n }\n\n // For lint-staged it's safer to not apply the fix command if it changes the AST\n // @see https://eslint.org/docs/user-guide/command-line-interface#--fix-type\n const fixType = [...(eslintSettings[\"fix-type\"] ?? [\"layout\"])].filter((type) => type.trim().length > 0);\n\n if (fixType.length > 0) {\n eslintArguments.push(`--fix-type ${fixType.join(\",\")}`, \"--fix\");\n }\n\n if (eslintSettings.cache) {\n eslintArguments.push(\"--cache\");\n }\n\n return eslintArguments;\n};\n\nconst createEslintCommands = async (filenames: string[]): Promise<string[]> => {\n const filteredFiles = await removeIgnoredFiles(filenames);\n\n const eslintArguments = createEslintArguments();\n\n if (eslintSettings.config) {\n eslintArguments.push(`--config ${eslintSettings.config}`);\n\n return [`${getPackageManager()} exec eslint ${eslintArguments.join(\" \")} ${filteredFiles.join(\" \")}`];\n }\n\n const groupedFilesNames = groupFilePathsByDirectoryName(filteredFiles);\n const eslintCommands: string[] = [];\n\n Object.values(groupedFilesNames).forEach((filePaths) => {\n let config: string | undefined;\n\n [configFile, `${configFile}.js`, `${configFile}.cjs`, `${configFile}.json`, `${configFile}.yaml`, `${configFile}.yml`].forEach((configName) => {\n if (config) {\n return;\n }\n\n try {\n // eslint-disable-next-line no-template-curly-in-string\n config = getNearestConfigPath(configName, filePaths[0] as \"/${string}\") as string;\n } catch {\n // Ignore\n }\n });\n\n if (config) {\n eslintCommands.push(`${getPackageManager()} exec eslint ${eslintArguments.join(\" \")} --config ${config} ${filePaths.join(\" \")}`);\n }\n });\n\n return eslintCommands;\n};\n\nexport default createEslintCommands;\n","import { pkg } from \"@anolilab/package-json-utils\";\n\nif (!global.anolilabLintStagedPackageJsonConfig && pkg) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access\n global.anolilabLintStagedPackageJsonConfig = pkg[\"anolilab\"]?.[\"lint-staged-config\"];\n}\n\nconst config: Record<string, boolean | undefined> = global.anolilabLintStagedPackageJsonConfig ?? {};\n\nexport default config;\n","import { dirname } from \"node:path\";\n\nconst groupFilePathsByDirectoryName = (filePaths: string[]): Record<string, string[]> => {\n const groups: Record<string, string[]> = {};\n\n filePaths.forEach((filePath) => {\n const directoryName = dirname(filePath);\n\n // eslint-disable-next-line security/detect-object-injection\n if (!groups[directoryName]) {\n // eslint-disable-next-line security/detect-object-injection\n groups[directoryName] = [];\n }\n // eslint-disable-next-line security/detect-object-injection\n (groups[directoryName] as string[]).push(filePath);\n });\n\n return groups;\n};\n\nexport default groupFilePathsByDirectoryName;\n","import { ESLint } from \"eslint\";\nimport { quote } from \"shell-quote\";\n\nimport isWindows from \"../../utils/is-windows\";\n\nconst removeIgnoredFiles = async (filenames: string[]): Promise<string[]> => {\n const eslint = new ESLint();\n // eslint-disable-next-line compat/compat\n const promises = await Promise.allSettled(filenames.map(async (filename) => await eslint.isPathIgnored(filename)));\n const ignoredFiles = promises.map((promise) => {\n if (promise.status === \"fulfilled\") {\n return promise.value;\n }\n\n console.error(`\\nUnable to determine if file is ignored.\\n\\n\\n${promise.reason}`);\n\n throw new Error(\"Stopping lint-staged because of an error.\");\n });\n\n // eslint-disable-next-line security/detect-object-injection\n const filteredFiles = filenames.filter((_, index) => !ignoredFiles[index]);\n\n return filteredFiles.map((filename) => `\"${isWindows ? filename : quote([filename])}\"`);\n};\n\nexport default removeIgnoredFiles;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/groups/eslint/index.ts","../src/groups/eslint/create-eslint-commands.ts","../src/utils/lint-staged-config.ts","../src/groups/eslint/group-file-paths-by-directory-name.ts","../src/groups/eslint/remove-ignored-files.ts"],"names":["hasDependency","hasDevDependency","isPackageAvailable","pkg","config","lint_staged_config_default","dirname","groupFilePathsByDirectoryName","filePaths","groups","filePath","directoryName","group_file_paths_by_directory_name_default","ESLint","quote","removeIgnoredFiles","filenames","eslint","ignoredFiles","filename","promise","_","index","is_windows_default","remove_ignored_files_default","eslintSettings","eslintGlobalRulesForFix","configFile","createEslintArguments","eslintArguments","rules","rule","fixType","type","createEslintCommands","filteredFiles","get_package_manager_default","groupedFilesNames","eslintCommands","configName","get_nearest_config_path_default","create_eslint_commands_default","extensions","group","concat_files_default","eslint_default"],"mappings":"+HAAA,OAAS,iBAAAA,EAAe,oBAAAC,MAAwB,+BCAhD,OAAS,iBAAAD,EAAe,oBAAAC,EAAkB,sBAAAC,MAA0B,+BCApE,OAAS,OAAAC,MAAW,+BAEhB,CAAC,OAAO,qCAAuCA,IAE/C,OAAO,oCAAsCA,EAAI,WAAc,oBAAoB,GAGvF,IAAMC,EAA8C,OAAO,qCAAuC,CAAC,EAE5FC,EAAQD,ECTf,OAAS,WAAAE,MAAe,OAExB,IAAMC,EAAiCC,GAAkD,CACrF,IAAMC,EAAmC,CAAC,EAE1C,OAAAD,EAAU,QAASE,GAAa,CAC5B,IAAMC,EAAgBL,EAAQI,CAAQ,EAGjCD,EAAOE,CAAa,IAErBF,EAAOE,CAAa,EAAI,CAAC,GAG5BF,EAAOE,CAAa,EAAe,KAAKD,CAAQ,CACrD,CAAC,EAEMD,CACX,EAEOG,EAAQL,ECpBf,OAAS,UAAAM,MAAc,SACvB,OAAS,SAAAC,MAAa,cAItB,IAAMC,EAAqB,MAAOC,GAA2C,CACzE,IAAMC,EAAS,IAAIJ,EAGbK,GADW,MAAM,QAAQ,WAAWF,EAAU,IAAI,MAAOG,GAAa,MAAMF,EAAO,cAAcE,CAAQ,CAAC,CAAC,GAC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AW,KAAK,IAAI,EAGxB,IAAMC,EAAgB,CAClB,CAAC,SAAS,CAAC,OAAQ,QAAS,OAAO,EAAE,KAAK,GAAG,CAAC,GAAG,EAAG,MAAO3B,GAAwB,CAAC,GAAI,MAAMyB,EAAqBzB,CAAS,CAAE,EAC9H,CAAC,SAAS,CAAC0B,CAAU,EAAE,KAAK,GAAG,CAAC,GAAG,EAAG,MAAO1B,GAAwB,CACjE,GAAGoB,EAAkB,CAAC,yBAAyBQ,EAAY5B,CAAS,CAAC,GACrE,GAAI,MAAMyB,EAAqBzB,CAAS,CAC5C,CACJ,EAEO6B,GAAQF","sourcesContent":["import { hasDependency, hasDevDependency } from \"@anolilab/package-json-utils\";\nimport type { Config } from \"lint-staged\";\n\nimport concatFiles from \"../../utils/concat-files\";\nimport getPackageManager from \"../../utils/get-package-manager\";\nimport createEslintCommands from \"./create-eslint-commands\";\n\nconst extensions = [\"cjs\", \"js\", \"mjs\", \"cts\", \"ts\", \"mts\", \"yml\", \"yaml\", \"jsx\", \"tsx\", \"mdx\", \"toml\"];\n\nif (!global.hasAnolilabLintStagedMarkdownCli) {\n global.hasAnolilabLintStagedMarkdownCli = hasDependency(\"markdownlint-cli\") || hasDevDependency(\"markdownlint-cli\");\n}\n\nif (!global.hasAnolilabLintStagedMarkdownCli2) {\n global.hasAnolilabLintStagedMarkdownCli2 = hasDependency(\"markdownlint-cli2\") || hasDevDependency(\"markdownlint-cli2\");\n}\n\nif (!global.hasAnolilabLintStagedMarkdownCli && !global.hasAnolilabLintStagedMarkdownCli2) {\n extensions.push(\"md\");\n}\n\nconst group: Config = {\n [`**/*.{${[\"json\", \"json5\", \"jsonc\"].join(\",\")}}`]: async (filenames: string[]) => [...(await createEslintCommands(filenames))],\n [`**/*.{${[extensions].join(\",\")}}`]: async (filenames: string[]) => [\n `${getPackageManager()} execprettier --write ${concatFiles(filenames)}`,\n ...(await createEslintCommands(filenames)),\n ],\n};\n\nexport default group;\n","import { hasDependency, hasDevDependency, isPackageAvailable } from \"@anolilab/package-json-utils\";\n\nimport getNearestConfigPath from \"../../utils/get-nearest-config-path\";\nimport getPackageManager from \"../../utils/get-package-manager\";\nimport anolilabLintStagedConfig from \"../../utils/lint-staged-config\";\nimport groupFilePathsByDirectoryName from \"./group-file-paths-by-directory-name\";\nimport removeIgnoredFiles from \"./remove-ignored-files\";\n\ninterface EslintConfig {\n cache?: boolean;\n config?: string;\n \"fix-type\"?: string[];\n \"max-warnings\"?: number | string | false;\n rules?: string[];\n}\n\ninterface ESLintSettings {\n settings?: {\n eslint?: EslintConfig;\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\nconst eslintSettings: EslintConfig = (anolilabLintStagedConfig as ESLintSettings)?.settings?.eslint ?? ({} as EslintConfig);\n\nconst eslintGlobalRulesForFix: string[] = [];\n\nif (hasDependency(\"eslint-plugin-react-hooks\") || hasDevDependency(\"eslint-plugin-react-hooks\")) {\n // react-hooks/eslint and react in general is very strict about exhaustively\n // declaring the dependencies when using the useEffect, useCallback... hooks.\n //\n // In some specific scenarios declaring the deps seems 'less' wanted or 'less' applicable\n // by the developer, leading to some exceptions in the code. That said it should be avoided.\n //\n // While the 'react-hooks/exhaustive-deps' rule is a good rule of thumb, it's not recommended to\n // automatically fix it from lint-staged as it can potentially break a legit intent.\n //\n // Reminder that a good practice is to always declare the dependencies when using the hooks,\n // and if not applicable, add an eslint disable comment to the useEffect, useCallback... such as:\n //\n // // eslint-disable-next-line react-hooks/exhaustive-deps\n //\n // Another approach can be to use hooks such as https://github.com/kentcdodds/use-deep-compare-effect to quickly bypass\n // shallow rendering limitations.\n //\n // @see https://reactjs.org/docs/hooks-rules.html\n // @see https://eslint.org/docs/2.13.1/user-guide/configuring#disabling-rules-with-inline-comments\n eslintGlobalRulesForFix.push(\"react-hooks/exhaustive-deps:off\");\n}\n\nif (\n hasDependency(\"eslint-plugin-eslint-comments\") ||\n hasDevDependency(\"eslint-plugin-eslint-comments\") ||\n isPackageAvailable(\"eslint-plugin-eslint-comments\")\n) {\n eslintGlobalRulesForFix.push(\"eslint-comments/no-unused-disable:off\");\n}\n\nconst configFile = \".eslintrc\";\n\nconst createEslintArguments = (): string[] => {\n const eslintArguments: string[] = [];\n\n if (eslintSettings[\"max-warnings\"] !== undefined && Number.isNaN(eslintSettings[\"max-warnings\"])) {\n eslintArguments.push(`--max-warnings=${eslintSettings[\"max-warnings\"]}`);\n } else if (eslintSettings[\"max-warnings\"] !== false) {\n eslintArguments.push(\"--max-warnings=0\");\n }\n\n const rules = [...(eslintSettings.rules ?? []), ...eslintGlobalRulesForFix].filter((rule) => rule.trim().length > 0);\n\n if (rules.length > 0) {\n eslintArguments.push(rules.map((rule) => `--rule \"${rule}\"`).join(\" \"));\n }\n\n // For lint-staged it's safer to not apply the fix command if it changes the AST\n // @see https://eslint.org/docs/user-guide/command-line-interface#--fix-type\n const fixType = [...(eslintSettings[\"fix-type\"] ?? [\"layout\"])].filter((type) => type.trim().length > 0);\n\n if (fixType.length > 0) {\n eslintArguments.push(`--fix-type ${fixType.join(\",\")}`, \"--fix\");\n }\n\n if (eslintSettings.cache) {\n eslintArguments.push(\"--cache\");\n }\n\n return eslintArguments;\n};\n\nconst createEslintCommands = async (filenames: string[]): Promise<string[]> => {\n const filteredFiles = await removeIgnoredFiles(filenames);\n\n const eslintArguments = createEslintArguments();\n\n if (eslintSettings.config) {\n eslintArguments.push(`--config ${eslintSettings.config}`);\n\n return [`${getPackageManager()} exec eslint ${eslintArguments.join(\" \")} ${filteredFiles.join(\" \")}`];\n }\n\n const groupedFilesNames = groupFilePathsByDirectoryName(filteredFiles);\n const eslintCommands: string[] = [];\n\n Object.values(groupedFilesNames).forEach((filePaths) => {\n let config: string | undefined;\n\n [configFile, `${configFile}.js`, `${configFile}.cjs`, `${configFile}.json`, `${configFile}.yaml`, `${configFile}.yml`].forEach((configName) => {\n if (config) {\n return;\n }\n\n try {\n // eslint-disable-next-line no-template-curly-in-string\n config = getNearestConfigPath(configName, filePaths[0] as \"/${string}\") as string;\n } catch {\n // Ignore\n }\n });\n\n if (config) {\n eslintCommands.push(`${getPackageManager()} exec eslint ${eslintArguments.join(\" \")} --config ${config} ${filePaths.join(\" \")}`);\n }\n });\n\n return eslintCommands;\n};\n\nexport default createEslintCommands;\n","import { pkg } from \"@anolilab/package-json-utils\";\n\nif (!global.anolilabLintStagedPackageJsonConfig && pkg) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access\n global.anolilabLintStagedPackageJsonConfig = pkg[\"anolilab\"]?.[\"lint-staged-config\"];\n}\n\nconst config: Record<string, boolean | undefined> = global.anolilabLintStagedPackageJsonConfig ?? {};\n\nexport default config;\n","import { dirname } from \"node:path\";\n\nconst groupFilePathsByDirectoryName = (filePaths: string[]): Record<string, string[]> => {\n const groups: Record<string, string[]> = {};\n\n filePaths.forEach((filePath) => {\n const directoryName = dirname(filePath);\n\n // eslint-disable-next-line security/detect-object-injection\n if (!groups[directoryName]) {\n // eslint-disable-next-line security/detect-object-injection\n groups[directoryName] = [];\n }\n // eslint-disable-next-line security/detect-object-injection\n (groups[directoryName] as string[]).push(filePath);\n });\n\n return groups;\n};\n\nexport default groupFilePathsByDirectoryName;\n","import { ESLint } from \"eslint\";\nimport { quote } from \"shell-quote\";\n\nimport isWindows from \"../../utils/is-windows\";\n\nconst removeIgnoredFiles = async (filenames: string[]): Promise<string[]> => {\n const eslint = new ESLint();\n // eslint-disable-next-line compat/compat\n const promises = await Promise.allSettled(filenames.map(async (filename) => await eslint.isPathIgnored(filename)));\n const ignoredFiles = promises.map((promise) => {\n if (promise.status === \"fulfilled\") {\n return promise.value;\n }\n\n console.error(`\\nUnable to determine if file is ignored.\\n\\n\\n${promise.reason}`);\n\n throw new Error(\"Stopping lint-staged because of an error.\");\n });\n\n // eslint-disable-next-line security/detect-object-injection\n const filteredFiles = filenames.filter((_, index) => !ignoredFiles[index]);\n\n return filteredFiles.map((filename) => `\"${isWindows ? filename : quote([filename])}\"`);\n};\n\nexport default removeIgnoredFiles;\n"]}
|