configuring-code-analyzer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseConfiguring Code Analyzer Skill
配置Code Analyzer技能
Overview
概述
This skill manages the configuration file — the single source of truth for how Code Analyzer behaves in a project. All customization (engines, rules, ignores, suppressions) is done by creating or editing this file. If the file doesn't exist, this skill creates it in the current working directory.
code-analyzer.yml本技能管理配置文件——它是Code Analyzer在项目中行为的唯一可信来源。所有自定义设置(引擎、规则、忽略项、抑制项)都通过创建或编辑该文件完成。如果文件不存在,本技能会在当前工作目录中创建它。
code-analyzer.ymlScope
适用范围
In scope:
- Checking prerequisites (sf CLI, Java, Node.js, Python, org auth)
- Installing/updating the Code Analyzer plugin
- Creating if it doesn't exist
code-analyzer.yml - Editing for all configuration changes
code-analyzer.yml - Engine settings, rule overrides, ignore patterns, suppressions
- CI/CD pipeline setup (GitHub Actions, Jenkins, etc.)
- Environment validation and troubleshooting
Out of scope:
- Running scans (use skill)
running-code-analyzer - Fixing violations, explaining rules, creating custom rules, suppression management
包含内容:
- 检查前置条件(sf CLI、Java、Node.js、Python、org授权)
- 安装/更新Code Analyzer插件
- 若不存在则创建该文件
code-analyzer.yml - 编辑以完成所有配置变更
code-analyzer.yml - 引擎设置、规则覆盖、忽略模式、抑制项
- CI/CD流水线设置(GitHub Actions、Jenkins等)
- 环境验证和故障排查
不包含内容:
- 运行扫描(请使用技能)
running-code-analyzer - 修复违规问题、解释规则、创建自定义规则、管理抑制项
Tool Usage Rules
工具使用规则
Allowed: Bash (sf, java, node, python3, git, npm), Read, Write, Edit
Forbidden: MCP tools, Agent tool, Web tools, other skills, , , , searching for binaries
whichfindlocate允许使用: Bash(sf、java、node、python3、git、npm)、读取、写入、编辑
禁止使用: MCP工具、Agent工具、Web工具、其他技能、、、、搜索二进制文件
whichfindlocateCore Principle: YAML Only When Customizing
核心原则:仅在自定义时创建YAML
Code Analyzer works out of the box with NO config file — all defaults are built into the tool. The file is ONLY created when the user explicitly requests a customization.
code-analyzer.ymlRules:
- Do NOT create proactively — only when user asks to change something
code-analyzer.yml - Do NOT duplicate built-in defaults — only write entries that intentionally override behavior
- Always place at project root — where or
sfdx-project.jsonlivessf-project.json - The CLI auto-discovers it — from project root automatically picks up
sf code-analyzer runin that directory. Nocode-analyzer.ymlflag needed.--config-file - User says "configure code analyzer" with no specifics? → Ask what they want to customize. Don't create an empty or boilerplate file.
Workflow:
- User requests a customization (e.g., "disable PMD", "ignore test files", "increase SFGE memory")
- Check if exists at project root
code-analyzer.yml - If NO → create it at project root with ONLY the requested override
- If YES → read it, then edit in the requested change
- Validate with
sf code-analyzer config
Code Analyzer无需配置文件即可开箱即用——所有默认设置都内置在工具中。仅当用户明确要求自定义时,才创建文件。
code-analyzer.yml规则:
- 请勿主动创建——仅当用户要求更改设置时才创建
code-analyzer.yml - 请勿重复内置默认值——仅写入有意覆盖行为的条目
- 始终放置在项目根目录——即或
sfdx-project.json所在位置sf-project.json - CLI会自动发现该文件——从项目根目录运行时,会自动识别该目录下的
sf code-analyzer run,无需使用code-analyzer.yml参数--config-file - 用户仅说“configure code analyzer”但未指定具体内容?→ 询问用户想要自定义的内容。请勿创建空文件或模板文件。
工作流程:
- 用户请求自定义(例如:“disable PMD”“ignore test files”“increase SFGE memory”)
- 检查项目根目录是否存在
code-analyzer.yml - 如果不存在→在项目根目录创建该文件,仅包含用户请求的覆盖配置
- 如果存在→读取文件,然后编辑以添加/修改请求的变更
- 使用验证配置
sf code-analyzer config
Step 1: Understand Intent and Map to Config Sections
步骤1:理解用户意图并映射到配置章节
The user can request ANY combination of configuration changes in natural language. Your job is to:
- Parse what they want — may be one thing or many things combined
- Map each request to the correct section(s) of
code-analyzer.yml - Create the file if it doesn't exist, then apply all changes
用户可能用自然语言请求任意组合的配置变更。你的任务是:
- 解析用户需求——可能是单一需求或多个需求组合
- 将每个请求映射到的对应章节
code-analyzer.yml - 如果文件不存在则创建,然后应用所有变更
The code-analyzer.yml
Structure (what you can write/edit)
code-analyzer.ymlcode-analyzer.yml
结构(可写入/编辑的内容)
code-analyzer.ymlyaml
config_root: . # Root for relative path resolution
log_folder: <path> # Where logs are written
log_level: <1-5> # 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Fine
ignores: # Files/folders excluded from scanning
files: [<glob patterns>]
engines: # Per-engine settings
<engine_name>:
disable_engine: <bool>
<engine_specific_keys>: ...
rules: # Per-rule overrides
<engine_name>:
<rule_name>:
severity: <1-5>
tags: [<strings>]
disabled: <bool>
suppressions: # Bulk suppression configuration
disable_suppressions: <bool>
"<file_or_folder_path>":
- rule_selector: "<selector>"
max_suppressed_violations: <number|null>
reason: "<why>"yaml
config_root: . # 相对路径解析的根目录
log_folder: <path> # 日志写入路径
log_level: <1-5> # 1=错误, 2=警告, 3=信息, 4=调试, 5=详细
ignores: # 排除在扫描外的文件/文件夹
files: [<glob patterns>]
engines: # 各引擎的设置
<engine_name>:
disable_engine: <bool>
<engine_specific_keys>: ...
rules: # 各规则的覆盖配置
<engine_name>:
<rule_name>:
severity: <1-5>
tags: [<strings>]
disabled: <bool>
suppressions: # 批量抑制配置
disable_suppressions: <bool>
"<file_or_folder_path>":
- rule_selector: "<selector>"
max_suppressed_violations: <number|null>
reason: "<why>"Mapping Principle
映射原则
Any user request maps to one or more sections above. Parse the intent and edit the right section(s):
| Intent Category | Maps To | Examples of What User Might Say |
|---|---|---|
| Setup / Install | Step 2 (prerequisites + install) | "set up", "install", "get started", "new laptop", "from scratch" |
| Diagnose / Fix | Step 2A (systematic debug) | "not working", "broken", "fix my setup", "scan fails", "getting errors" |
| Engine control | | "disable X", "turn off Y", "only use Z", "enable all" |
| Engine tuning | | "increase memory", "change heap", "use my eslint config", "set tokens to 50" |
| File exclusions | | "exclude", "ignore", "skip", "don't scan X" |
| Rule severity | | "make X critical", "promote", "demote", "change severity" |
| Rule disable | | "disable rule X", "turn off Y rule", "remove Z" |
| Rule tags | | "tag X as security", "add recommended tag" |
| Suppressions | | "suppress X in folder Y", "allow N violations" |
| CI/CD | Generate pipeline file (separate from config) | "github actions", "CI", "quality gate" |
| View/inspect | Read file + | "show config", "what's configured", "current settings" |
任何用户请求都会映射到上述一个或多个章节。解析意图并编辑对应章节:
| 意图类别 | 映射到 | 用户可能的表述示例 |
|---|---|---|
| 安装/设置 | 步骤2(前置条件+安装) | "set up"、"install"、"get started"、"new laptop"、"from scratch" |
| 诊断/修复 | 步骤2A(系统化调试) | "not working"、"broken"、"fix my setup"、"scan fails"、"getting errors" |
| 引擎控制 | | "disable X"、"turn off Y"、"only use Z"、"enable all" |
| 引擎调优 | | "increase memory"、"change heap"、"use my eslint config"、"set tokens to 50" |
| 文件排除 | | "exclude"、"ignore"、"skip"、"don't scan X" |
| 规则严重程度 | | "make X critical"、"promote"、"demote"、"change severity" |
| 规则禁用 | | "disable rule X"、"turn off Y rule"、"remove Z" |
| 规则标签 | | "tag X as security"、"add recommended tag" |
| 抑制项 | | "suppress X in folder Y"、"allow N violations" |
| CI/CD | 生成流水线文件(与配置文件分离) | "github actions"、"CI"、"quality gate" |
| 查看/检查 | 读取文件 + | "show config"、"what's configured"、"current settings" |
File Existence Decision
文件存在性判断
BEFORE editing anything, check if exists at project root:
code-analyzer.ymlbash
ls code-analyzer.yml code-analyzer.yaml 2>/dev/null- File does NOT exist → Create it at project root with ONLY the user's requested override(s)
- File exists → Read it, then Edit to add/modify the requested section(s)
The CLI auto-discovers in the current directory. Since scans run from project root, the file must live there.
code-analyzer.yml在编辑任何内容之前,检查项目根目录是否存在:
code-analyzer.ymlbash
ls code-analyzer.yml code-analyzer.yaml 2>/dev/null- 文件不存在→在项目根目录创建该文件,仅包含用户请求的覆盖配置
- 文件存在→读取文件,然后编辑以添加/修改请求的章节
CLI会自动识别当前目录下的。由于扫描从项目根目录运行,该文件必须放在此处。
code-analyzer.yml⚠️ Rule Name Resolution — ALWAYS Before Writing YAML
⚠️规则名称解析——写入YAML前必须完成
When a user references rules by partial, descriptive, or approximate names (e.g., "the doc rule", "CRUD violation", "console rule", "hardcoded values"), you MUST resolve to exact rule names using the lookup in Step 6.1 BEFORE writing any YAML. The file silently ignores rule names that don't exactly match — there is no error, the override just won't apply.
code-analyzer.ymlExamples of fuzzy → exact resolution needed:
- "Disable the ApexDoc rule" → lookup confirms (engine:
ApexDoc)pmd - "Demote no-console to low" → lookup confirms (engine:
no-console)eslint - "Make CRUD violations critical" → lookup confirms (engine:
ApexCRUDViolation)pmd - "Turn off the hardcoded values check" → lookup finds (engine:
@salesforce-ux/slds/no-hardcoded-values-slds2)eslint - "Disable the injection rule" → multiple matches possible → ask user which one
Only skip the lookup when the user provides an unambiguous, exact, well-known name (e.g., "ApexDoc", "no-console", "no-unused-vars").
当用户通过部分描述性或近似名称引用规则时(例如:"the doc rule"、"CRUD violation"、"console rule"、"hardcoded values"),你必须在写入任何YAML之前,使用步骤6.1中的查找方法解析为准确的规则名称。文件会静默忽略不匹配的规则名称——不会报错,但覆盖配置不会生效。
code-analyzer.yml模糊→准确解析示例:
- "Disable the ApexDoc rule"→查找确认(引擎:
ApexDoc)pmd - "Demote no-console to low"→查找确认(引擎:
no-console)eslint - "Make CRUD violations critical"→查找确认(引擎:
ApexCRUDViolation)pmd - "Turn off the hardcoded values check"→查找发现(引擎:
@salesforce-ux/slds/no-hardcoded-values-slds2)eslint - "Disable the injection rule"→可能有多个匹配项→询问用户具体指哪一个
仅当用户提供明确、准确、知名的名称时(例如:"ApexDoc"、"no-console"、"no-unused-vars"),可跳过查找步骤。
Handling Combined/Complex Requests
处理组合/复杂请求
Users will often combine multiple changes in one request. Handle ALL of them in a single edit:
- "Disable PMD's ApexDoc rule and make CRUD violations critical" → edit two entries under
rules.pmd - "Exclude test files and vendor code, and increase SFGE memory" → edit +
ignores.filesengines.sfge.java_max_heap_size - "Set up code analyzer with only ESLint and PMD, ignore node_modules" → create file with (disable others) +
enginesignores - "Make all security rules severity 1" → look up rules via , then override each
sf code-analyzer rules --rule-selector Security - "Configure code analyzer" (no specifics) → ask user what they want to customize before creating any file
用户通常会在一个请求中提出多个变更。需在一次编辑中处理所有请求:
- "Disable PMD's ApexDoc rule and make CRUD violations critical"→编辑下的两个条目
rules.pmd - "Exclude test files and vendor code, and increase SFGE memory"→编辑+
ignores.filesengines.sfge.java_max_heap_size - "Set up code analyzer with only ESLint and PMD, ignore node_modules"→创建包含(禁用其他引擎)+
engines的文件ignores - "Make all security rules severity 1"→通过查找规则,然后逐个覆盖
sf code-analyzer rules --rule-selector Security - "Configure code analyzer"(无具体内容)→在创建任何文件之前,询问用户想要自定义的内容
Quick Reference: Common Requests → Config Output
快速参考:常见请求→配置输出
| User Says | Resulting YAML |
|---|---|
| "configure code analyzer" | Ask user what to customize — don't create file until there's an actual override |
| "disable the ApexDoc rule" | |
| "only scan Apex, no JavaScript" | |
| "ignore all test files" | |
| "make security rules critical" | Look up rules, then |
| "increase SFGE memory to 8g" | |
| "use my project's ESLint config" | |
| "suppress CRUD violations in legacy folder" | |
The AI must understand the YAML schema and write valid config for ANY request, not just the examples above.
| 用户表述 | 生成的YAML |
|---|---|
| "configure code analyzer" | 询问用户想要自定义的内容——直到有实际的覆盖请求才创建文件 |
| "disable the ApexDoc rule" | |
| "only scan Apex, no JavaScript" | |
| "ignore all test files" | |
| "make security rules critical" | 查找规则,然后为每个规则添加 |
| "increase SFGE memory to 8g" | |
| "use my project's ESLint config" | |
| "suppress CRUD violations in legacy folder" | |
AI必须理解YAML模式,并能为任意请求编写有效的配置,而不仅仅是上述示例。
Step 2: Check Prerequisites and Install
步骤2:检查前置条件并安装
Run or check manually:
bash "<skill_dir>/scripts/check-prerequisites.sh"bash
sf --version 2>&1 # sf CLI
sf plugins --core 2>&1 | grep -i "code-analyzer" # Plugin
java -version 2>&1 # Java 11+ (PMD, CPD, SFGE)
node --version 2>&1 # Node 18+ (ESLint, RetireJS)
python3 --version 2>&1 # Python 3 (Flow engine)If anything is missing, install it (always ask user first):
bash
npm install -g @salesforce/cli # sf CLI
sf plugins install @salesforce/plugin-code-analyzer # Code Analyzer pluginFor Java/Node/Python installs, read .
If install fails, read .
<skill_dir>/references/engine-prerequisites.md<skill_dir>/references/troubleshooting.md运行或手动检查:
bash "<skill_dir>/scripts/check-prerequisites.sh"bash
sf --version 2>&1 # sf CLI
sf plugins --core 2>&1 | grep -i "code-analyzer" # 插件
java -version 2>&1 # Java 11+(PMD、CPD、SFGE)
node --version 2>&1 # Node 18+(ESLint、RetireJS)
python3 --version 2>&1 # Python 3(Flow引擎)如果缺少任何项,先询问用户,再进行安装:
bash
npm install -g @salesforce/cli # sf CLI
sf plugins install @salesforce/plugin-code-analyzer # Code Analyzer插件关于Java/Node/Python的安装,请阅读。
如果安装失败,请阅读。
<skill_dir>/references/engine-prerequisites.md<skill_dir>/references/troubleshooting.mdStep 2A: Diagnose and Fix a Broken Setup
步骤2A:诊断并修复故障设置
TRIGGER: User says "not working", "broken", "getting errors", "scan fails", "help me fix", etc.
Read for the complete layered diagnostic procedure, fix table, and anti-patterns.
<skill_dir>/references/diagnostic-flow.mdKey principles (always apply):
- Never search for binaries (,
which,find)ls /opt/homebrew/bin/ - Never use as a workaround — only
sfdxsf - Fix layer by layer: CLI → Plugin → Engine deps → verify scan
- Give user ONE command at a time, wait for confirmation before continuing
- After fix succeeds, proceed to run the full scan automatically
触发条件: 用户提及“not working”“broken”“getting errors”“scan fails”“help me fix”等。
**阅读**获取完整的分层诊断流程、修复表和反模式说明。
<skill_dir>/references/diagnostic-flow.md核心原则(始终遵循):
- 切勿搜索二进制文件(、
which、find)ls /opt/homebrew/bin/ - 切勿使用作为替代方案——仅使用
sfdxsf - 逐层修复:CLI → 插件 → 引擎依赖 → 验证扫描
- 一次只给用户一个命令,等待确认后再继续
- 修复成功后,自动运行完整扫描
Step 3: Create or Edit code-analyzer.yml
code-analyzer.yml步骤3:创建或编辑code-analyzer.yml
code-analyzer.ymlOnly triggered when user requests a customization. Never create proactively.
仅在用户请求自定义时触发。切勿主动创建。
Creating (file doesn't exist)
创建(文件不存在)
Choose one of the two approaches below — do not run both:
Option A — Auto-generate from project type (recommended for first-time setup):
Run . This detects Apex, LWC, and Flow markers and produces a minimal suited to the project. Skip to the "After any create/edit, validate" section.
bash "<skill_dir>/scripts/generate-config.sh"code-analyzer.ymlNote: The script exits with an error ifalready exists. Delete the existing file first if you need to regenerate.code-analyzer.yml
Option B — Write manually (when the user has specific customizations in mind):
Read the appropriate example config as a reference for structure:
- For Apex-only projects, read
<skill_dir>/examples/apex-project-config.yml - For LWC-only projects, read
<skill_dir>/examples/lwc-project-config.yml - For full-stack (Apex + LWC + Flows), read
<skill_dir>/examples/fullstack-project-config.yml
Write the file at project root using the Write tool. Include ONLY the user's requested changes:
bash
undefined选择以下两种方式之一——不要同时运行:
选项A——根据项目类型自动生成(首次设置推荐):
运行。该脚本会检测Apex、LWC和Flow标记,生成适合项目的最小化。跳至“创建/编辑后验证”章节。
bash "<skill_dir>/scripts/generate-config.sh"code-analyzer.yml注意:如果已存在,脚本会报错退出。如果需要重新生成,请先删除现有文件。code-analyzer.yml
选项B——手动编写(用户有特定自定义需求时):
读取相应的示例配置作为结构参考:
- 仅Apex项目:读取
<skill_dir>/examples/apex-project-config.yml - 仅LWC项目:读取
<skill_dir>/examples/lwc-project-config.yml - 全栈项目(Apex + LWC + Flows):读取
<skill_dir>/examples/fullstack-project-config.yml
使用写入工具在项目根目录创建文件,仅包含用户请求的变更:
bash
undefinedExample: user said "ignore test files and increase SFGE memory"
示例:用户说“ignore test files and increase SFGE memory”
→ Write to project root (where sfdx-project.json lives):
→ 写入项目根目录(sfdx-project.json所在位置):
```yaml
ignores:
files:
- "**/test/**"
- "**/__tests__/**"
engines:
sfge:
java_max_heap_size: "4g"Do NOT add , , or any other field the user didn't ask for.
config_rootlog_folder
```yaml
ignores:
files:
- "**/test/**"
- "**/__tests__/**"
engines:
sfge:
java_max_heap_size: "4g"请勿添加、或任何用户未提及的字段。
config_rootlog_folderEditing (file already exists)
编辑(文件已存在)
Read the file, then use the Edit tool to add/modify only the relevant section. Preserve everything else.
读取文件,然后使用编辑工具添加/修改相关章节,保留其他所有内容。
After any create/edit, validate:
创建/编辑后验证:
Run to validate YAML syntax and schema correctness, or use the CLI directly:
bash "<skill_dir>/scripts/validate-config.sh"bash
sf code-analyzer config(No needed — the CLI auto-discovers in CWD.)
--config-filecode-analyzer.yml运行验证YAML语法和模式正确性,或直接使用CLI:
bash "<skill_dir>/scripts/validate-config.sh"bash
sf code-analyzer config(无需参数——CLI会自动识别当前目录下的。)
--config-filecode-analyzer.ymlIf user says "configure code analyzer" with no specifics
如果用户仅说“configure code analyzer”无具体内容
Ask: "What would you like to customize? For example: ignore certain files, change rule severities, tune engine settings, or disable engines you don't need."
询问:“你想要自定义哪些内容?例如:忽略特定文件、更改规则严重程度、调优引擎设置,或禁用不需要的引擎。”
Step 4: Enable/Disable Engines
步骤4:启用/禁用引擎
Edit the section in :
enginescode-analyzer.ymlyaml
engines:
pmd:
disable_engine: true # Disable PMD
eslint:
disable_engine: false # Enable ESLint (default)Valid engine names: , , , , , , ,
pmdcpdeslintregexretire-jsflowsfgeapexguruAlways validate after editing:
bash
sf code-analyzer config --config-file code-analyzer.yml编辑中的章节:
code-analyzer.ymlenginesyaml
engines:
pmd:
disable_engine: true # 禁用PMD
eslint:
disable_engine: false # 启用ESLint(默认)有效的引擎名称:、、、、、、、
pmdcpdeslintregexretire-jsflowsfgeapexguru编辑后始终验证:
bash
sf code-analyzer config --config-file code-analyzer.ymlStep 5: Ignore Patterns
步骤5:忽略模式
Edit the section in :
ignorescode-analyzer.ymlyaml
ignores:
files:
- "**/node_modules/**"
- "**/.sfdx/**"
- "**/.sf/**"
- "**/vendor/**"
- "**/*.min.js"Common patterns:
| Pattern | Excludes |
|---|---|
| npm dependencies |
| SF CLI internals |
| Test directories |
| Test files |
| Jest mocks |
| Third-party/minified |
| Static resources |
编辑中的章节:
code-analyzer.ymlignoresyaml
ignores:
files:
- "**/node_modules/**"
- "**/.sfdx/**"
- "**/.sf/**"
- "**/vendor/**"
- "**/*.min.js"常见模式:
| 模式 | 排除内容 |
|---|---|
| npm依赖 |
| SF CLI内部文件 |
| 测试目录 |
| 测试文件 |
| Jest模拟文件 |
| 第三方/压缩文件 |
| 静态资源 |
Step 6: Rule Overrides
步骤6:规则覆盖
Edit the section in . Each rule can have , , and overrides:
rulescode-analyzer.ymlseveritytagsdisabledyaml
rules:
pmd:
ApexCRUDViolation:
severity: 1 # Promote to Critical
AvoidGlobalModifier:
disabled: true # Turn off entirely
ApexDoc:
severity: 5 # Demote to Info
tags: ["Documentation"]
eslint:
no-console:
severity: 4 # Demote to Low
no-unused-vars:
severity: 2 # Promote to HighSeverity values: /Critical, /High, /Moderate, /Low, /Info
12345编辑中的章节。每个规则可设置、和覆盖项:
code-analyzer.ymlrulesseveritytagsdisabledyaml
rules:
pmd:
ApexCRUDViolation:
severity: 1 # 提升为Critical
AvoidGlobalModifier:
disabled: true # 完全禁用
ApexDoc:
severity: 5 # 降级为Info
tags: ["Documentation"]
eslint:
no-console:
severity: 4 # 降级为Low
no-unused-vars:
severity: 2 # 提升为High严重程度值: /Critical、/High、/Moderate、/Low、/Info
123456.1 Rule Name Resolution (Fuzzy Matching)
6.1规则名称解析(模糊匹配)
⚠️ CRITICAL: A misspelled or partial rule name in is SILENTLY IGNORED — no error, the override just won't apply.
code-analyzer.ymlWhen users reference rules by approximate names (e.g., "the doc rule", "CRUD violation", "hardcoded values"), resolve to exact names BEFORE writing YAML:
bash
sf code-analyzer rules --rule-selector all 2>&1 | grep -i "<USER_KEYWORD>"- 1 match → use that exact name + its engine for the YAML path
- Multiple matches → ask user which one they meant
- 0 matches → try broader keywords or inform user
Skip the lookup only when the name is unambiguous and exact (e.g., "ApexDoc", "no-console", "no-unused-vars").
For detailed matching strategies, common fuzzy→exact mappings, and engine identification: Read .
<skill_dir>/references/rule-name-resolution.md⚠️关键注意事项: 中拼写错误或部分匹配的规则名称会被静默忽略——不会报错,但覆盖配置不会生效。
code-analyzer.yml当用户通过近似名称引用规则时(例如:"the doc rule"、"CRUD violation"、"hardcoded values"),在写入YAML之前解析为准确名称:
bash
sf code-analyzer rules --rule-selector all 2>&1 | grep -i "<USER_KEYWORD>"- 1个匹配项→使用该准确名称及其引擎作为YAML路径
- 多个匹配项→询问用户具体指哪一个
- 0个匹配项→尝试更宽泛的关键词或告知用户
仅当名称明确且准确时(例如:"ApexDoc"、"no-console"、"no-unused-vars"),可跳过查找步骤。
关于详细匹配策略、常见模糊→准确映射以及引擎识别: 请阅读。
<skill_dir>/references/rule-name-resolution.mdStep 7: Engine-Specific Settings
步骤7:引擎特定设置
Edit the section. Most common overrides:
enginesyaml
engines:
sfge:
java_max_heap_size: "4g" # <200 classes→"2g", 200-500→"4g", 500+→"6g"/"8g"
java_thread_count: 4
java_thread_timeout: 900000
eslint:
auto_discover_eslint_config: true # Use project's own ESLint config
eslint_config_file: "./eslint.config.mjs"
pmd:
custom_rulesets: ["./config/custom-pmd-rules.xml"]
java_classpath_entries: ["./lib/custom-rules.jar"]
cpd:
minimum_tokens: { apex: 100, javascript: 100 }
apexguru:
target_org: "my-org-alias"
flow:
python_command: "python3"
regex:
custom_rules:
NoHardcodedIds:
regex: "/[a-zA-Z0-9]{15,18}/"
file_extensions: [".cls", ".trigger"]
description: "Detects hardcoded Salesforce record IDs"
severity: 2
tags: ["Security"]For full property list per engine, read .
<skill_dir>/references/config-schema.md编辑章节。最常见的覆盖配置:
enginesyaml
engines:
sfge:
java_max_heap_size: "4g" # <200个类→"2g", 200-500个→"4g", 500+→"6g"/"8g"
java_thread_count: 4
java_thread_timeout: 900000
eslint:
auto_discover_eslint_config: true # 使用项目自身的ESLint配置
eslint_config_file: "./eslint.config.mjs"
pmd:
custom_rulesets: ["./config/custom-pmd-rules.xml"]
java_classpath_entries: ["./lib/custom-rules.jar"]
cpd:
minimum_tokens: { apex: 100, javascript: 100 }
apexguru:
target_org: "my-org-alias"
flow:
python_command: "python3"
regex:
custom_rules:
NoHardcodedIds:
regex: "/[a-zA-Z0-9]{15,18}/"
file_extensions: [".cls", ".trigger"]
description: "Detects hardcoded Salesforce record IDs"
severity: 2
tags: ["Security"]关于每个引擎的完整属性列表,请阅读。
<skill_dir>/references/config-schema.mdStep 8: CI/CD Pipeline Setup
步骤8:CI/CD流水线设置
Detect CI system from workspace ( → GitHub Actions, → Jenkins, etc.). Read for templates. Use as GitHub Actions base. Key flags: (gate), (GitHub scanning), .
.github/workflows/Jenkinsfile<skill_dir>/references/ci-cd-templates.md<skill_dir>/examples/ci-github-actions.yml--severity-threshold 2--output-file results.sarif--config-file code-analyzer.yml从工作区检测CI系统(→GitHub Actions,→Jenkins等)。阅读获取模板。使用作为GitHub Actions基础配置。关键参数:(质量门)、(GitHub扫描)、。
.github/workflows/Jenkinsfile<skill_dir>/references/ci-cd-templates.md<skill_dir>/examples/ci-github-actions.yml--severity-threshold 2--output-file results.sarif--config-file code-analyzer.ymlStep 9: View Current Configuration
步骤9:查看当前配置
bash
sf code-analyzer config # Show effective config
sf code-analyzer config --rule-selector pmd:Security # Specific rules
sf code-analyzer config --include-unmodified-rules # All defaultsbash
sf code-analyzer config # 显示有效配置
sf code-analyzer config --rule-selector pmd:Security # 特定规则
sf code-analyzer config --include-unmodified-rules # 所有默认值Cross-Skill Integration
跨技能集成
This skill works together with . The AI agent should seamlessly hand off between them:
running-code-analyzer本技能与协同工作。AI代理应在两者间无缝切换:
running-code-analyzerWhen running-code-analyzer
delegates HERE:
running-code-analyzer当running-code-analyzer
委托至本技能时:
running-code-analyzerIf a user says "scan my code" / "run code analyzer" but it fails (CLI missing, plugin not installed, or scan errors out), delegates to this skill. In that case:
running-code-analyzer- Run the diagnose and fix flow (Step 2A) — find what's broken, fix it
- After everything works, automatically proceed to run the scan — do not stop and ask. The user's original intent was to scan.
- Hand execution back to behavior (build command, execute, parse results).
running-code-analyzer
如果用户说“scan my code”/“run code analyzer”但运行失败(缺少CLI、未安装插件或扫描报错),会委托至本技能。此时:
running-code-analyzer- 执行诊断和修复流程(步骤2A)——找出故障点并修复
- 修复完成后,自动继续运行扫描——不要停止并询问。用户的原始意图是扫描。
- 将执行权交回(构建命令、执行、解析结果)。
running-code-analyzer
When THIS skill hands off to running-code-analyzer
:
running-code-analyzer当本技能委托至running-code-analyzer
时:
running-code-analyzerAfter any successful configuration action, offer to run a scan (e.g., "Setup complete! Want me to run a scan?", "Config updated — want to scan and verify?"). If user says yes, proceed with behavior.
running-code-analyzer任何配置操作成功后,主动提出运行扫描(例如:“设置完成!需要我运行扫描吗?”“配置已更新——需要扫描验证吗?”)。如果用户同意,执行的操作流程。
running-code-analyzerWhen user intent spans BOTH skills:
当用户意图涉及两个技能时:
Handle end-to-end: "not working" → Diagnose → Fix → Scan. "Set up and scan" → Install → Scan. "Disable ESLint and scan Apex" → Edit config → Run with . Always follow through to the user's final intent.
--rule-selector pmd端到端处理:“not working”→诊断→修复→扫描。“Set up and scan”→安装→扫描。“Disable ESLint and scan Apex”→编辑配置→使用运行扫描。始终跟进至用户的最终意图。
--rule-selector pmdRules / Constraints
规则/约束
| Constraint | Rationale |
|---|---|
| Only create YAML when user requests a customization | Defaults work without any file — don't create boilerplate |
| Place YAML at project root only | CLI auto-discovers |
| Write only overrides, never duplicate defaults | Keep file minimal and intentional |
| Use Write tool to create, Edit tool to modify | Preserves existing settings |
| Validate after every change | |
| Ask before installing prerequisites | Never auto-install without consent |
| Never delete existing config without asking | User may have custom settings |
| After setup, offer to scan | Close the loop — config without scan is incomplete |
| 约束 | 理由 |
|---|---|
| 仅在用户请求自定义时创建YAML | 默认设置无需文件即可生效——请勿创建模板文件 |
| YAML仅放置在项目根目录 | CLI会自动识别当前目录下的 |
| 仅写入覆盖配置,绝不重复默认值 | 保持文件精简且有针对性 |
| 使用写入工具创建,编辑工具修改 | 保留现有设置 |
| 每次变更后验证 | |
| 安装前置条件前先询问用户 | 切勿未经同意自动安装 |
| 未经询问切勿删除现有配置 | 用户可能有自定义设置 |
| 设置完成后主动提出扫描 | 闭环流程——仅配置不扫描不完整 |
Gotchas
常见问题
| Issue | Solution |
|---|---|
| Config not picked up | Must be |
| YAML validation fails | Spaces only (no tabs), check colon spacing |
| SFGE out of memory | Increase |
| ESLint rules missing | Set |
For full troubleshooting, read .
<skill_dir>/references/troubleshooting.md| 问题 | 解决方案 |
|---|---|
| 配置未被识别 | 必须是当前目录下的 |
| YAML验证失败 | 仅使用空格(不要用制表符),检查冒号后的空格 |
| SFGE内存不足 | 在engines章节增加 |
| ESLint规则缺失 | 设置 |
完整故障排查内容,请阅读。
<skill_dir>/references/troubleshooting.mdReference File Index
参考文件索引
<skill_dir>| File | Purpose |
|---|---|
| Environment check |
| Auto-detect project type and generate config |
| Validate YAML after changes |
| Full YAML schema documentation |
| Step 2A: layered diagnostic procedure and fix table |
| Step 6.1: fuzzy rule name lookup strategies and mappings |
| Install instructions per engine |
| CI/CD pipeline templates |
| Common setup issues and fixes |
| Config for Apex-only project |
| Config for LWC-only project |
| Config for Apex + LWC + Flows |
| GitHub Actions workflow |
<skill_dir>| 文件 | 用途 |
|---|---|
| 环境检查 |
| 自动检测项目类型并生成配置 |
| 变更后验证YAML |
| 完整YAML模式文档 |
| 步骤2A:分层诊断流程和修复表 |
| 步骤6.1:模糊规则名称查找策略和映射 |
| 各引擎安装说明 |
| CI/CD流水线模板 |
| 常见设置问题及修复方案 |
| 仅Apex项目的配置 |
| 仅LWC项目的配置 |
| Apex + LWC + Flows项目的配置 |
| GitHub Actions工作流 |