Skip to content

Commit 9bec6cc

Browse files
fix webpack (#4856)
* fix webpack * fix jsx configuration
1 parent 5162278 commit 9bec6cc

File tree

7 files changed

+731
-703
lines changed

7 files changed

+731
-703
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ tsconfig.tsbuildinfo
77
.vscode
88
.codarcyrc
99
/tests
10-
.eslintcache
10+
.eslintcache
11+
12+
#Ignore vscode AI rules
13+
.github/copilot-instructions.md

docs/multiple-tests/security-node/src/.eslintrc.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@
44
],
55
"extends": [
66
"plugin:security-node/recommended"
7-
],
8-
"rules": {
9-
"security-node/non-literal-reg-expr": "warn"
10-
}
7+
]
118
}

package-lock.json

Lines changed: 689 additions & 654 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,11 @@
7474
"@angular/compiler": "^17.3.9",
7575
"@babel/cli": "^7.24.8",
7676
"@babel/core": "^7.24.5",
77-
"@babel/eslint-parser": "^7.25.1",
7877
"@babel/eslint-plugin": "^7.24.5",
7978
"@babel/plugin-proposal-throw-expressions": "^7.24.7",
8079
"@babel/plugin-transform-object-assign": "^7.24.7",
8180
"@babel/plugin-transform-object-rest-spread": "^7.24.5",
8281
"@babel/plugin-transform-runtime": "^7.24.3",
83-
"@babel/preset-env": "^7.24.5",
84-
"@babel/preset-react": "^7.24.1",
8582
"@babel/register": "^7.23.7",
8683
"@babel/runtime": "^7.25.0",
8784
"@cityelectricalfactors/eslint-config-base": "^1.0.3",
@@ -390,6 +387,9 @@
390387
"yup": "^1.4.0"
391388
},
392389
"devDependencies": {
390+
"@babel/eslint-parser": "^7.28.0",
391+
"@babel/preset-env": "^7.28.0",
392+
"@babel/preset-react": "^7.27.1",
393393
"@trivago/prettier-plugin-sort-imports": "^5.2.2"
394394
}
395395
}

src/configCreator.ts

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

src/eslintDefaultOptions.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ export const defaultOptions: ESLint.Options = {
121121
},
122122
"typescript": {
123123
"alwaysTryTypes": true
124-
},
125-
"webpack": true
124+
}
126125
},
127126
"jest": {
128127
"version": 29
@@ -218,20 +217,21 @@ export const defaultOptions: ESLint.Options = {
218217
"rules": {
219218
"json/json": "off"
220219
}
221-
}
220+
},
222221
// JSX with Babel
223-
// https://www.npmjs.com/package/@babel/eslint-parser
224-
// "When should I use @babel/eslint-parser?"
225-
// {
226-
// "files": ["**/*.jsx"],
227-
// "parser": "@babel/eslint-parser",
228-
// "parserOptions": {
229-
// "babelOptions": {
230-
// "presets": ["@babel/preset-env"]
231-
// },
232-
// "requireConfigFile": false
233-
// }
234-
// }
222+
{
223+
"files": ["**/*.jsx"],
224+
"parser": "@babel/eslint-parser",
225+
"parserOptions": {
226+
"babelOptions": {
227+
"presets": [
228+
"@babel/preset-env",
229+
"@babel/preset-react"
230+
]
231+
},
232+
"requireConfigFile": false
233+
}
234+
}
235235
]
236236
}
237237
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
"src/**/*.ts",
2020
"package.json"
2121
]
22-
}
22+
}

0 commit comments

Comments
 (0)