1---2name: sonarjs3description: Use SonarJS-derived rules in .NET repositories that ship JavaScript or TypeScript frontends and need deeper bug-risk, code-smell, or cognitive-complexity checks than a minimal ESLint baseline. USE FOR: SonarQube, SonarCloud, or eslint-plugin-sonarjs setups; frontend code smells; cognitive complexity and deeper bug-risk rules. DO NOT USE FOR: lightweight base lint setups with no extra smell or complexity rules; teams that reject Sonar tooling. INVOKES: inspect the repository context, edit targeted files, and run relevant build, test, lint, or validation commands when changes are made.4---56# SonarJS Rules for Frontend Assets in .NET Repositories78## Trigger On910- the repo already uses SonarQube, SonarCloud, or `eslint-plugin-sonarjs`11- the user asks for frontend code smells, cognitive complexity limits, or deeper bug-risk rules beyond base ESLint12- maintainability and reliability findings on JS or TS code should become a review or CI gate1314## Do Not Use For1516- repos that want only a lightweight base lint setup with no extra smell or complexity rules17- teams that reject SonarQube, SonarCloud, or source-available SonarJS-derived tooling as a default gate18- cases where the problem is runtime page quality rather than source-level maintainability1920## Inputs2122- the nearest `AGENTS.md`23- `package.json`24- existing ESLint config25- any SonarQube, SonarCloud, or scanner config already present in CI2627```mermaid28flowchart LR29 A["Need Sonar-style checks in a .NET repo frontend"] --> B{"Local developer loop or existing server gate?"}30 B -->|Local| C["Install eslint-plugin-sonarjs"]31 C --> D["Run through the normal eslint command"]32 B -->|Existing SonarQube or SonarCloud gate| E["Keep full analysis in the existing scanner pipeline"]33 D --> F["Phase rules and fix code"]34 E --> F35```3637## Workflow38391. Decide the execution path first:40 - local developer loop through `eslint-plugin-sonarjs`41 - server-side analysis through an already adopted SonarQube or SonarCloud pipeline422. For local work, treat SonarJS as an ESLint extension rather than a standalone CLI.433. Keep the first rollout narrow:44 - bug-prone rules45 - cognitive complexity46 - duplicated branching or suspicious control flow474. Add rules to the existing ESLint command instead of inventing a parallel local lint entrypoint.485. If the repo already has SonarQube or SonarCloud, align local rule expectations with the server gate instead of maintaining two conflicting policies.496. Fix code or phase rules deliberately; do not hide the first rollout behind broad disables.507. Document licensing or hosting caveats before making Sonar-based tooling the default quality gate.5152## Current Upstream Notes5354- SonarJS `13.8` adds guidance to prefer native APIs over Axios utility methods and retryable Cypress assertions. It also fixes false positives for deferred Promise chains, ordinary class members, and `Deno.test` declarations, and narrows related test-file and form analysis heuristics.55- Re-run server analysis before preserving suppressions, and review new findings as behavior-specific guidance rather than enabling every new rule blindly. Self-hosted builds now require JDK 21 rather than JDK 17.5657## Bootstrap When Missing58591. Detect current state:60 - `rg --files -g 'package.json' -g 'eslint.config.*' -g '.eslintrc*'`61 - `rg -n '"eslint-plugin-sonarjs"|"sonar"|"sonarqube"|"sonarcloud"' .`622. Prefer the local ESLint-plugin path for developer workflows:63 - `npm install --save-dev eslint-plugin-sonarjs`643. Add the plugin and selected rules to the checked-in ESLint config.654. Verify with the repo's normal lint entrypoint, for example:66 - `npx eslint .`675. If the repo already uses SonarQube or SonarCloud, keep the full analysis in that existing CI path instead of inventing a new local scanner flow.686. Return `status: configured` if SonarJS-derived checks now have explicit ownership, or `status: improved` if an existing setup was tightened.697. Return `status: not_applicable` when the repo explicitly chooses a purely OSS lint baseline without Sonar-based extensions.7071## Handle Failures7273- There is no separate local `sonarjs` CLI from this repo; local developer use should go through ESLint with `eslint-plugin-sonarjs`.74- Plugin-load failures usually mean the ESLint config does not match the installed plugin version or plugin registration syntax.75- If the first rollout produces too many smells, phase rule adoption instead of disabling the plugin wholesale.76- If SonarQube or SonarCloud disagrees with local lint output, treat the server gate as the source of truth and align the local config deliberately.7778## Deliver7980- explicit SonarJS-derived rule ownership81- a clear split between local ESLint-based use and any existing server-side Sonar pipeline82- documented rollout scope and caveats8384## Validate8586- local developer commands still use the repo's standard ESLint entrypoint87- Sonar-based rules are not treated as a standalone local CLI when none exists88- licensing or hosting caveats are documented before broad adoption89- findings are actionable and phased instead of silently suppressed9091## Ralph Loop92931. Plan: analyze current state, target outcome, constraints, and risks.942. Execute one step and produce a concrete delta.953. Review the result and capture findings.964. Apply fixes in small batches and rerun checks.975. Update the plan after each iteration.986. Repeat until outcomes are acceptable.997. If a dependency is missing, bootstrap it or return `status: not_applicable` with a reason.100101### Required Result Format102103- `status`: `complete` | `clean` | `improved` | `configured` | `not_applicable` | `blocked`104- `plan`: concise plan and current step105- `actions_taken`: concrete changes made106- `verification`: commands, checks, or review evidence107- `remaining`: unresolved items or `none`108109## Example Requests110111- "Add SonarJS rules to the existing ESLint setup."112- "Use cognitive complexity checks on the frontend."113- "Explain whether we should use the ESLint plugin or SonarQube here."