Skip to content

Commit 0401d9f

Browse files
Merge pull request #98 from forcedotcom/release-0.7.0
RELEASE @W-16039195@ Releasing v0.7.0
2 parents a6a410f + e454583 commit 0401d9f

15 files changed

+1400
-261
lines changed

SHA256.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ make sure that their SHA values match the values in the list below.
1515
shasum -a 256 <location_of_the_downloaded_file>
1616

1717
3. Confirm that the SHA in your output matches the value in this list of SHAs.
18-
3a28223251a6c7fe66c9e03142dcbe105a1ff879251c3b3ca0b56b5679d33cd3 ./sfdx-code-analyzer-vscode-0.5.0.vsix
18+
e34c5dd98fb29b52c2f02d04905f9f3c158700c36f0254be366038ec842271af ./extensions/sfdx-code-analyzer-vscode-0.6.0.vsix
1919
4. Change the filename extension for the file that you downloaded from .zip to
2020
.vsix.
2121

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2023, Salesforce, Inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
public class MyClass2 {
8+
9+
public static boolean someBooleanMethod() {
10+
// some comment that includes public class MyClass2 {
11+
return false;
12+
}
13+
/* some other comment in a single line */
14+
public static boolean someOtherBooleanMethod() {
15+
/*
16+
some other comment that includes public class MyClass 2 {
17+
*/
18+
return false;
19+
}
20+
21+
public static boolean someOtherMethod() {
22+
public static String someString = 'this string has \' class MyClass2 { ';
23+
return true;
24+
}
25+
26+
private class MyInnerClass {
27+
// Some inner class
28+
}
29+
}

package.json

+41-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"color": "#ECECEC",
1414
"theme": "light"
1515
},
16-
"version": "0.6.0",
16+
"version": "0.7.0",
1717
"publisher": "salesforce",
1818
"license": "BSD-3-Clause",
1919
"engines": {
@@ -76,15 +76,23 @@
7676
"commands": [
7777
{
7878
"command": "sfca.runOnActiveFile",
79-
"title": "SF: Scan current file with Code Analyzer"
79+
"title": "SFDX: Scan current file with Code Analyzer"
8080
},
8181
{
8282
"command": "sfca.runOnSelected",
83-
"title": "SF: Scan selected files or folders with Code Analyzer"
83+
"title": "SFDX: Scan selected files or folders with Code Analyzer"
8484
},
8585
{
8686
"command": "sfca.runDfaOnSelectedMethod",
87-
"title": "SF: Scan selected method with Graph Engine path-based analysis"
87+
"title": "SFDX: Scan selected method with Graph Engine path-based analysis"
88+
},
89+
{
90+
"command": "sfca.removeDiagnosticsOnActiveFile",
91+
"title": "SFDX: Clear Code Analyzer violations from current file"
92+
},
93+
{
94+
"command": "sfca.removeDiagnosticsOnSelectedFile",
95+
"title": "SFDX: Clear Code Analyzer violations from selected files or folders"
8896
}
8997
],
9098
"configuration": {
@@ -123,6 +131,20 @@
123131
"type": "boolean",
124132
"default": false,
125133
"description": "Scan files on open automatically."
134+
},
135+
"codeAnalyzer.scanner.engines": {
136+
"type": "string",
137+
"default": "pmd,retire-js,eslint-lwc",
138+
"description": "The engines to run. Specify multiple values as a comma-separated list. Possible values are pmd, retire-js, eslint, eslint-lwc, and eslint-typescript."
139+
},
140+
"codeAnalyzer.normalizeSeverity.enabled": {
141+
"type": "boolean",
142+
"default": false,
143+
"description": "Output normalized severity (high, moderate, low) and engine-specific severity across all engines."
144+
},
145+
"codeAnalyzer.rules.category": {
146+
"type": "string",
147+
"description": "The categories of rules to run. Specify multiple values as a comma-separated list. Run 'sf scanner rule list -e' in the terminal for the list of categories associated with a specific engine."
126148
}
127149
}
128150
},
@@ -139,6 +161,14 @@
139161
{
140162
"command": "sfca.runDfaOnSelectedMethod",
141163
"when": "false"
164+
},
165+
{
166+
"command": "sfca.removeDiagnosticsOnActiveFile",
167+
"when": "true"
168+
},
169+
{
170+
"command": "sfca.removeDiagnosticsOnSelectedFile",
171+
"when": "false"
142172
}
143173
],
144174
"editor/context": [
@@ -147,11 +177,18 @@
147177
},
148178
{
149179
"command": "sfca.runDfaOnSelectedMethod"
180+
},
181+
{
182+
"command": "sfca.removeDiagnosticsOnActiveFile"
150183
}
151184
],
152185
"explorer/context": [
153186
{
154187
"command": "sfca.runOnSelected"
188+
},
189+
{
190+
"command": "sfca.removeDiagnosticsOnSelectedFile",
191+
"when": "true"
155192
}
156193
]
157194
},

src/extension.ts

+64-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import * as Constants from './lib/constants';
2121
import * as path from 'path';
2222
import { SIGKILL } from 'constants';
2323

24-
type RunInfo = {
24+
export type RunInfo = {
2525
diagnosticCollection?: vscode.DiagnosticCollection;
2626
outputChannel: vscode.LogOutputChannel;
2727
commandName: string;
@@ -78,6 +78,23 @@ export async function activate(context: vscode.ExtensionContext): Promise<vscode
7878
outputChannel
7979
});
8080
});
81+
const removeDiagnosticsOnActiveFile = vscode.commands.registerCommand(Constants.COMMAND_REMOVE_DIAGNOSTICS_ON_ACTIVE_FILE, async () => {
82+
return _clearDiagnosticsForSelectedFiles([], {
83+
commandName: Constants.COMMAND_REMOVE_DIAGNOSTICS_ON_ACTIVE_FILE,
84+
diagnosticCollection,
85+
outputChannel
86+
});
87+
});
88+
const removeDiagnosticsOnSelectedFile = vscode.commands.registerCommand(Constants.COMMAND_REMOVE_DIAGNOSTICS_ON_SELECTED_FILE, async (selection: vscode.Uri, multiSelect?: vscode.Uri[]) => {
89+
return _clearDiagnosticsForSelectedFiles(multiSelect && multiSelect.length > 0 ? multiSelect : [selection], {
90+
commandName: Constants.COMMAND_REMOVE_DIAGNOSTICS_ON_SELECTED_FILE,
91+
diagnosticCollection,
92+
outputChannel
93+
});
94+
});
95+
const removeDiagnosticsInRange = vscode.commands.registerCommand(Constants.COMMAND_DIAGNOSTICS_IN_RANGE, (uri: vscode.Uri, range: vscode.Range) => {
96+
_removeDiagnosticsInRange(uri, range, diagnosticCollection);
97+
});
8198
outputChannel.appendLine(`Registered command as part of sfdx-code-analyzer-vscode activation.`);
8299
registerScanOnSave(outputChannel);
83100
registerScanOnOpen(outputChannel);
@@ -110,12 +127,22 @@ export async function activate(context: vscode.ExtensionContext): Promise<vscode
110127
});
111128
}
112129
});
113-
context.subscriptions.push(runOnActiveFile, runOnSelected, runDfaOnSelectedMethod);
130+
context.subscriptions.push(runOnActiveFile, runOnSelected, runDfaOnSelectedMethod, removeDiagnosticsOnActiveFile, removeDiagnosticsOnSelectedFile, removeDiagnosticsInRange);
114131
TelemetryService.sendExtensionActivationEvent(extensionHrStart);
115132
outputChannel.appendLine(`Extension sfdx-code-analyzer-vscode activated.`);
116133
return Promise.resolve(context);
117134
}
118135

136+
export function _removeDiagnosticsInRange(uri: vscode.Uri, range: vscode.Range, diagnosticCollection: vscode.DiagnosticCollection) {
137+
const currentDiagnostics = diagnosticCollection.get(uri) || [];
138+
const updatedDiagnostics = filterOutDiagnosticsInRange(currentDiagnostics, range);
139+
diagnosticCollection.set(uri, updatedDiagnostics);
140+
}
141+
142+
function filterOutDiagnosticsInRange(currentDiagnostics: readonly vscode.Diagnostic[], range: vscode.Range) {
143+
return currentDiagnostics.filter(diagnostic => (diagnostic.range.start.line != range.start.line && diagnostic.range.end.line != range.end.line));
144+
}
145+
119146
export async function _stopExistingDfaRun(context: vscode.ExtensionContext, outputChannel: vscode.LogOutputChannel): Promise<void> {
120147
const pid = context.workspaceState.get(Constants.WORKSPACE_DFA_PROCESS);
121148
if (pid) {
@@ -308,6 +335,41 @@ export function _clearDiagnostics(): void {
308335
diagnosticCollection.clear();
309336
}
310337

338+
/**
339+
* Clear diagnostics for a specific files
340+
* @param selections selected files
341+
* @param runInfo command and diagnostic collection object
342+
*/
343+
export async function _clearDiagnosticsForSelectedFiles(selections: vscode.Uri[], runInfo: RunInfo): Promise<void> {
344+
const {
345+
diagnosticCollection,
346+
outputChannel,
347+
commandName
348+
} = runInfo;
349+
const startTime = Date.now();
350+
351+
try {
352+
const targets: string[] = await targeting.getTargets(selections);
353+
354+
for (const target of targets) {
355+
diagnosticCollection.delete(vscode.Uri.file(target));
356+
}
357+
358+
TelemetryService.sendCommandEvent(Constants.TELEM_SUCCESSFUL_STATIC_ANALYSIS, {
359+
executedCommand: commandName,
360+
duration: (Date.now() - startTime).toString()
361+
});
362+
} catch (e) {
363+
const errMsg = e instanceof Error ? e.message : e as string;
364+
console.log(errMsg);
365+
TelemetryService.sendException(Constants.TELEM_FAILED_STATIC_ANALYSIS, errMsg, {
366+
executedCommand: commandName,
367+
duration: (Date.now() - startTime).toString()
368+
});
369+
outputChannel.error(errMsg);
370+
outputChannel.show();
371+
}
372+
}
311373
/**
312374
* Display a Toast summarizing the results of a non-DFA scan, i.e. how many files were scanned, how many had violations, and how many violations were found.
313375
* @param targets The files that were scanned. This may be a superset of the files that actually had violations.

src/lib/constants.ts

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export const EXTENSION_PACK_ID = 'salesforce.salesforcedx-vscode';
1313
export const COMMAND_RUN_ON_ACTIVE_FILE = 'sfca.runOnActiveFile';
1414
export const COMMAND_RUN_ON_SELECTED = 'sfca.runOnSelected';
1515
export const COMMAND_RUN_DFA_ON_SELECTED_METHOD = 'sfca.runDfaOnSelectedMethod';
16+
export const COMMAND_REMOVE_DIAGNOSTICS_ON_ACTIVE_FILE = 'sfca.removeDiagnosticsOnActiveFile';
17+
export const COMMAND_REMOVE_DIAGNOSTICS_ON_SELECTED_FILE = 'sfca.removeDiagnosticsOnSelectedFile';
18+
export const COMMAND_DIAGNOSTICS_IN_RANGE = 'sfca.removeDiagnosticsInRange'
19+
1620

1721
// telemetry event keys
1822
export const TELEM_SUCCESSFUL_STATIC_ANALYSIS = 'sfdx__codeanalyzer_static_run_complete';

0 commit comments

Comments
 (0)