Commit 4163f57
committed
fix(install-dynamic-plugins): address Sonar code-smell findings
Resolves the 21 issues flagged by SonarQube on PR redhat-developer#4574:
Prototype pollution (CodeQL, merger.ts)
- `deepMerge` now assigns via `Object.defineProperty` (bypasses the
`__proto__` setter on `Object.prototype`) in addition to the existing
`FORBIDDEN_KEYS` guard. CodeQL recognizes this pattern.
Redundant type assertions
- `index.ts:180`: drop `pc as Record<string, unknown>` — use the
`isPlainObject` type guard already imported from `util.ts`.
- `installer-npm.ts:37`, `installer-oci.ts:35`: replace
`(plugin.pluginConfig ?? {}) as Record<string, unknown>` with a
typed local variable.
- `installer-oci.ts:41,51,71,78`: drop `as string` casts by restructuring
the `isAlreadyInstalled` helper with proper `undefined` checks.
- `merger.ts:136-140`: replace `.slice(-1)[0] as string` with
`.at(-1) ?? ''`.
- `merger.ts:215`: `ReadonlyArray<keyof Plugin | string>` collapses to
`ReadonlyArray<string>`.
Cognitive complexity reductions
- `installOciPlugin` (17 → ~10): extract `resolvePullPolicy` and
`isAlreadyInstalled` helpers.
- `mergeOciPlugin` (20 → ~12): extract `resolveInherit`.
- `npmPluginKey` (16 → ~7): extract `tryParseAlias`, `isGitLikeSpec`,
`stripRefSuffix`.
- `ociPluginKey`: extract `autoDetectPluginPath`.
Modern JS / readability (es2015-es2022)
- `integrity.ts`: `charCodeAt` → `codePointAt` (es2015).
- `oci-key.ts`: use `String.raw` for the regex pieces containing `\s`,
`\d`, `\]`, `\\` instead of escaped string literals (es2015).
- `oci-key.ts:escape`: `.replace(/.../g, ...)` → `.replaceAll(...)` (es2021).
- `plugin-hash.ts`: pass an explicit code-point comparator to `sort` so
deterministic-hash behavior is spelled out. `localeCompare` is NOT
used — it varies per-locale and would break hash stability.
All 115 tests still pass. Bundle rebuilt (415.1 KB).1 parent 7a13480 commit 4163f57
File tree
9 files changed
+351
-259
lines changed- scripts/install-dynamic-plugins
- dist
- src
9 files changed
+351
-259
lines changedLines changed: 141 additions & 114 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
179 | | - | |
180 | | - | |
| 178 | + | |
| 179 | + | |
181 | 180 | | |
182 | 181 | | |
183 | 182 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
0 commit comments