-
Notifications
You must be signed in to change notification settings - Fork 62
W-20161235: Add getter komaci rules to offline analysis tool #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iowillhoit
merged 9 commits into
salesforcecli:main
from
haifeng-li-at-salesforce:getterValidation
Nov 14, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f5a6daa
feat: add getter komaci rules to offline analysis tool of mobile-web-mcp
haifeng-li-at-salesforce f394a42
test: add tests for getter komaci rules for offline analysis tool of …
haifeng-li-at-salesforce cd10b5f
Merge branch 'main' into getterValidation
haifeng-li-at-salesforce e8c400e
fix: change based on feedback
haifeng-li-at-salesforce 1eea31e
Merge branch 'getterValidation' of github.com:haifeng-li-at-salesforc…
haifeng-li-at-salesforce 373d3a6
fix: change based on feedback. Make instructions more AI friendly
haifeng-li-at-salesforce bf05a9e
Merge branch 'main' into getterValidation
haifeng-li-at-salesforce d0c2bf3
Update packages/mcp-provider-mobile-web/src/tools/offline-analysis/ru…
haifeng-li-at-salesforce fd24913
fix: update graph-analyzer with node 20 engine
haifeng-li-at-salesforce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,6 @@ import { McpTool, type McpToolConfig } from '@salesforce/mcp-provider-api'; | |
| import { ReleaseState, Toolset } from '@salesforce/mcp-provider-api'; | ||
| import { LwcCodeSchema, type LwcCodeType } from '../../schemas/lwcSchema.js'; | ||
| import { CallToolResult } from '@modelcontextprotocol/sdk/types.js'; | ||
| import { z } from 'zod'; | ||
| import lwcGraphAnalyzerPlugin from '@salesforce/eslint-plugin-lwc-graph-analyzer'; | ||
| import { ruleConfigs } from './ruleConfig.js'; | ||
|
|
||
|
|
@@ -34,6 +33,7 @@ import { | |
| const ANALYSIS_EXPERT_NAME = 'Mobile Web Offline Analysis'; | ||
| const PLUGIN_NAME = '@salesforce/lwc-graph-analyzer'; | ||
| const RECOMMENDED_CONFIG = lwcGraphAnalyzerPlugin.configs.recommended; | ||
| const { bundleAnalyzer } = lwcGraphAnalyzerPlugin.processors; | ||
|
|
||
| const LINTER_CONFIG: Linter.Config = { | ||
| name: `config: ${PLUGIN_NAME}`, | ||
|
|
@@ -45,7 +45,6 @@ const LINTER_CONFIG: Linter.Config = { | |
|
|
||
| type InputArgsShape = typeof LwcCodeSchema.shape; | ||
| type OutputArgsShape = typeof ExpertsCodeAnalysisIssuesSchema.shape; | ||
| type InputArgs = z.infer<typeof LwcCodeSchema>; | ||
|
|
||
| export class OfflineAnalysisTool extends McpTool<InputArgsShape, OutputArgsShape> { | ||
| private readonly linter: Linter; | ||
|
|
@@ -82,7 +81,7 @@ export class OfflineAnalysisTool extends McpTool<InputArgsShape, OutputArgsShape | |
| }; | ||
| } | ||
|
|
||
| public async exec(args: InputArgs): Promise<CallToolResult> { | ||
| public async exec(args: LwcCodeType): Promise<CallToolResult> { | ||
| try { | ||
| const analysisResults = await this.analyzeCode(args); | ||
|
|
||
|
|
@@ -119,22 +118,42 @@ export class OfflineAnalysisTool extends McpTool<InputArgsShape, OutputArgsShape | |
| } | ||
|
|
||
| public async analyzeCode(code: LwcCodeType): Promise<ExpertsCodeAnalysisIssuesType> { | ||
| const jsCode = code.js.map((js: { content: string }) => js.content).join('\n'); | ||
| const { messages } = this.linter.verifyAndFix(jsCode, LINTER_CONFIG, { | ||
| fix: true, | ||
| }); | ||
| let offlineAnalysisIssues: ExpertCodeAnalysisIssuesType; | ||
|
|
||
| if (!code.js) { | ||
| offlineAnalysisIssues = { | ||
| expertReviewerName: ANALYSIS_EXPERT_NAME, | ||
| issues: [], | ||
| }; | ||
| } else { | ||
| const jsCode = code.js.content; | ||
| const jsPath = code.js.path; | ||
|
|
||
| const htmlCodes = code.html.length > 0 ? code.html.map((html) => html.content) : ([''] as string[]); | ||
|
|
||
| const baseName = code.name; | ||
|
|
||
| bundleAnalyzer.setLwcBundleFromContent(baseName, jsCode, ...htmlCodes); | ||
|
|
||
| const { messages } = this.linter.verifyAndFix(jsCode, LINTER_CONFIG, { | ||
| fix: true, | ||
| filename: `${baseName}.js`, | ||
| }); | ||
|
|
||
| offlineAnalysisIssues = this.analyzeIssues(jsCode, messages, jsPath); | ||
| } | ||
|
|
||
| const offlineAnalysisIssues = this.analyzeIssues(jsCode, messages); | ||
| return { | ||
| analysisResults: [offlineAnalysisIssues], | ||
| orchestrationInstructions: this.getOrchestrationInstructions(), | ||
| }; | ||
| } | ||
|
|
||
| private getOrchestrationInstructions(): string { | ||
| return ExpertsCodeAnalysisIssuesSchema.shape.orchestrationInstructions.parse(undefined); | ||
| } | ||
|
|
||
| private analyzeIssues(code: string, messages: Linter.LintMessage[]): ExpertCodeAnalysisIssuesType { | ||
| private analyzeIssues(code: string, messages: Linter.LintMessage[], jsPath: string): ExpertCodeAnalysisIssuesType { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the file path to help the model quickly locate the file containing the issues. |
||
| const issues: CodeAnalysisIssueType[] = []; | ||
|
|
||
| for (const violation of messages) { | ||
|
|
@@ -144,6 +163,7 @@ export class OfflineAnalysisTool extends McpTool<InputArgsShape, OutputArgsShape | |
|
|
||
| if (ruleReviewer) { | ||
| const issue: CodeAnalysisIssueType = { | ||
| filePath: jsPath, | ||
| type: ruleReviewer.type, | ||
| description: ruleReviewer.description, | ||
| intentAnalysis: ruleReviewer.intentAnalysis, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LWC has only 1 JS file