@@ -39,15 +39,13 @@ function generateFilesToAnalyze(codacyrc: Codacyrc): string[] {
3939 ? codacyrc . files
4040 : defaultFilesToAnalyze ;
4141
42- // Files to exclude
4342 const excludedFiles = [
4443 "package.json" ,
4544 "package-lock.json" ,
4645 "yarn.lock" ,
4746 "pnpm-lock.yaml"
4847 ] ;
4948
50- // Filter out excluded files
5149 const filteredFiles = files . filter (
5250 file => ! excludedFiles . some ( excluded => file . endsWith ( excluded ) )
5351 ) ;
@@ -81,30 +79,25 @@ async function generateEslintOptions (
8179
8280 const options : ESLint . Options = Object . assign ( { } , baseOptions , cloneDeep ( defaultOptions ) )
8381
82+ // Initialize baseConfig if it doesn't exist
83+ if ( ! options . baseConfig ) {
84+ options . baseConfig = { }
85+ }
86+
8487 if ( DEBUG && useRepoPatterns && ! existsEslintConfig ) {
8588 const patternsSet = "recommended"
8689 patterns = await retrieveCodacyPatterns ( patternsSet )
8790 options . baseConfig . rules = convertPatternsToEslintRules ( patterns )
8891 debug ( `options: setting ${ patternsSet } (${ patterns . length } ) patterns` )
8992 } else if ( useCodacyPatterns ) {
90- //TODO: move this logic to a generic (or specific) plugin function
91-
92- // There are some plugins that their rules should only apply for
93- // some specific file types / files names. So when those are enabled
94- // explicitly we need to apply them with a bit of customization.
95- //
96- // example: a rule for the storybook should only apply to files with
97- // "story" or "stories" in the name. If enabled for all files it
98- // reports false positives on normal files.
99- // check: conf file @ eslint-plugin-storybook/configs/recommended.js
100-
10193 const [ storybookPatterns , otherPatterns ] = partition ( patterns , ( p : Pattern ) =>
10294 p . patternId . startsWith ( "storybook" )
10395 )
10496
105- // configure override in case storybook plugin rules being turned on
10697 if ( storybookPatterns . length ) {
10798 debug ( `options: setting ${ storybookPatterns . length } storybook patterns` )
99+ // Ensure overrides is initialized
100+ options . baseConfig . overrides ||= [ ]
108101 options . baseConfig . overrides . push ( {
109102 "files" : [
110103 "*.stories.@(ts|tsx|js|jsx|mjs|cjs)" ,
@@ -114,25 +107,26 @@ async function generateEslintOptions (
114107 } )
115108 }
116109
117- // explicitly use only the rules being passed by codacyrc
118110 if ( otherPatterns . length ) {
119111 debug ( `options: setting ${ otherPatterns . length } patterns` )
120112 options . baseConfig . rules = convertPatternsToEslintRules ( otherPatterns )
121113 }
122114 }
115+ // Ensure plugins is initialized
116+ options . baseConfig . plugins ||= [ ]
123117
124118 // load only the plugins that are being used in loaded rules
125119 const prefixes = getPatternsUniquePrefixes ( patterns )
126- prefixes
127- . filter ( ( prefix ) => prefix !== "" )
128- . forEach ( async ( prefix ) => {
129- ( await getPluginsName ( ) ) . includes ( prefix )
130- ? options . baseConfig . plugins . push ( prefix )
131- : debug ( `options: plugin ${ prefix } not found` )
132- } )
133120
134- debug ( "options: finished" )
121+ for ( const prefix of prefixes . filter ( ( p ) => p !== "" ) ) {
122+ if ( ( await getPluginsName ( ) ) . includes ( prefix ) ) {
123+ options . baseConfig . plugins . push ( prefix )
124+ } else {
125+ debug ( `options: plugin ${ prefix } not found` )
126+ }
127+ }
135128
129+ debug ( "options: finished" )
136130 return options
137131}
138132
@@ -192,7 +186,6 @@ async function retrieveCodacyPatterns (set: "recommended" | "all" = "recommended
192186 . filter ( ( [ patternId , rule ] ) =>
193187 ! isBlacklisted ( patternId )
194188 && ! ( rule ?. meta ?. deprecated && rule . meta . deprecated === true )
195- // problems with the path generated (win vs nix) for this specific pattern
196189 && ( ! DEBUG || patternId != "spellcheck_spell-checker" )
197190 && ( set !== "recommended" || DocGenerator . isDefaultPattern ( patternIdToEslint ( patternId ) , rule . meta ) )
198191 )
@@ -212,4 +205,4 @@ async function retrieveCodacyPatterns (set: "recommended" | "all" = "recommended
212205
213206 debug ( `options: returning ${ set } (${ patterns . length } ) patterns` )
214207 return patterns
215- }
208+ }
0 commit comments