ワンクリックで
helpers
// Provides JavaScript/TypeScript helper functions and utilities for SonarJS rule implementation. Use when implementing rule fixes, searching for existing utilities, or needing to check available helper functions.
// Provides JavaScript/TypeScript helper functions and utilities for SonarJS rule implementation. Use when implementing rule fixes, searching for existing utilities, or needing to check available helper functions.
Use before a SonarJS release or when the Peach Main Analysis workflow on SonarSource/peachee-js shows failed jobs or suspicious project issue-count drops that need triage. Classify failed Peach jobs and flag likely project-configuration regressions using docs/peach-main-analysis.md.
Use before a SonarJS release or when the Peach Main Analysis workflow on SonarSource/peachee-js shows failed jobs or suspicious project issue-count drops that need triage. Classify failed Peach jobs and flag likely project-configuration regressions using docs/peach-main-analysis.md.
Provides guidance on implementing and fixing SonarJS rules. Use also when tracing false positives, working with rule configuration, or understanding native vs external rule implementations.
Add or modify rule options in SonarJS, including the fields array, SonarQube UI visibility, and Java check class configuration. Use when working on rule configurations.
Provides test quality standards and best practices. Use when writing test cases, creating unit tests, implementing tests, or refining/reviewing test code. Essential for test generation and test refinement phases.
Build pipeline for SonarJS. Use when asked to build the project, regenerate metadata, understand the build pipeline, or run npm build scripts.
| name | helpers |
| description | Provides JavaScript/TypeScript helper functions and utilities for SonarJS rule implementation. Use when implementing rule fixes, searching for existing utilities, or needing to check available helper functions. |
Helper functions are located in packages/analysis/src/jsts/rules/helpers/. These provide common utilities for rule implementations.
isCallingMethod() - Check if a call expression is calling a specific methodgetUniqueWriteUsageOrNode() - Track variable assignmentsisRequiredParserServices() - Check if TypeScript type information is availableisArray(), isString(), etc. - Type checking helpersgetImportDeclarations() - Get import declarations from the contextBefore writing any new function, search packages/analysis/src/jsts/rules/helpers/ for an existing equivalent. Key files to check:
ast.ts — generic AST utilities (child enumeration, node classification, ancestor walking)vue.ts — Vue-specific helpersreact.ts — React/JSX-specific helpersReviewers will reject re-implementations of existing helpers.
Anti-pattern: Iterating Object.keys(node) to enumerate child nodes. Use the existing childrenOf helper instead:
// ❌ Do not do this
for (const key of Object.keys(node)) { ... }
// ✅ Use this
for (const child of childrenOf(node)) { ... }
If you write a new utility function that only operates on estree/TSESTree nodes with no rule-specific domain logic, place it in helpers/ast.ts (or helpers/vue.ts, helpers/react.ts for domain-specific utilities) — not inside the individual rule file. Functions buried in a rule file are invisible to future implementers.
To explore available helpers:
ls packages/analysis/src/jsts/rules/helpers/
Read helper implementations to understand their usage and parameters.
childrenOf(node) always returns estree.Node[]. Do not write custom type guard predicates or Array.isArray() checks on its return values — they are dead code:
// ❌ Redundant — childrenOf already guarantees estree.Node[]
for (const child of childrenOf(node)) {
if (typeof child === 'object' && 'type' in child) { ... }
}
// ✅ Iterate directly
for (const child of childrenOf(node)) {
// child is already estree.Node
}