1+ import { createRequire } from "node:module" ;
2+
13import { hasDependency , hasDevDependency } from "@anolilab/package-json-utils" ;
24import type { Config } from "lint-staged" ;
35
4- import eslintConfig from "./groups/eslint" ;
5- import jsonConfig from "./groups/json" ;
6- import markdownConfig from "./groups/markdown" ;
7- import secretlintConfig from "./groups/secretlint" ;
8- import stylesheetsConfig from "./groups/stylesheets" ;
9- import testsConfig from "./groups/tests" ;
10- import typescriptConfig from "./groups/typescript" ;
116import anolilabLintStagedConfig from "./utils/lint-staged-config" ;
127
8+ const require = createRequire ( import . meta. url ) ;
9+
1310type Groups = {
14- config : Config ;
1511 configName : string ;
1612 dependencies : string [ ] ;
1713} [ ] ;
1814
1915const groups : Groups = [
2016 {
21- config : eslintConfig ,
2217 configName : "eslint" ,
2318 dependencies : [ "eslint" ] ,
2419 } ,
2520 {
26- config : jsonConfig ,
2721 configName : "json" ,
2822 dependencies : [ "prettier" ] ,
2923 } ,
3024 {
31- config : markdownConfig ,
3225 configName : "markdown" ,
3326 dependencies : [ "markdownlint-cli" , "markdownlint-cli2" ] ,
3427 } ,
3528 {
36- config : secretlintConfig ,
3729 configName : "secretlint" ,
3830 dependencies : [ "secretlint" ] ,
3931 } ,
4032 {
41- config : stylesheetsConfig ,
4233 configName : "stylesheets" ,
4334 dependencies : [ "stylelint" ] ,
4435 } ,
4536 {
46- config : testsConfig ,
4737 configName : "tests" ,
4838 dependencies : [ "vite" , "jest" , "ava" ] ,
4939 } ,
5040 {
51- config : typescriptConfig ,
5241 configName : "typescript" ,
5342 dependencies : [ "typescript" ] ,
5443 } ,
@@ -60,7 +49,7 @@ const loadedPluginsNames: string[] = [];
6049const possiblePlugins : Record < string , Record < string , boolean > > = { } ;
6150
6251groups . forEach ( ( plugin ) => {
63- const { config , configName, dependencies } = plugin ;
52+ const { configName, dependencies } = plugin ;
6453
6554 // eslint-disable-next-line security/detect-object-injection
6655 if ( ( anolilabLintStagedConfig as unknown as Record < string , Record < string , false | undefined > > ) [ "plugin" ] ?. [ configName ] !== false ) {
@@ -73,6 +62,9 @@ groups.forEach((plugin) => {
7362 } ) ;
7463
7564 if ( foundDependencies . length > 0 ) {
65+ // eslint-disable-next-line security/detect-non-literal-require,import/no-dynamic-require
66+ const config = require ( `./groups/${ configName } ` ) as Config ;
67+
7668 loadedPlugins = { ...loadedPlugins , ...config } ;
7769 loadedPluginsNames . push ( configName ) ;
7870 } else {
0 commit comments