Skip to content

Commit

Permalink
Merge pull request #98 from forcedotcom/release-0.7.0
Browse files Browse the repository at this point in the history
RELEASE @W-16039195@ Releasing v0.7.0
  • Loading branch information
stephen-carter-at-sf authored Jun 25, 2024
2 parents a6a410f + e454583 commit 0401d9f
Show file tree
Hide file tree
Showing 15 changed files with 1,400 additions and 261 deletions.
2 changes: 1 addition & 1 deletion SHA256.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ make sure that their SHA values match the values in the list below.
shasum -a 256 <location_of_the_downloaded_file>

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

Expand Down
29 changes: 29 additions & 0 deletions code-fixtures/fixer-tests/MyClass2.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
public class MyClass2 {

public static boolean someBooleanMethod() {
// some comment that includes public class MyClass2 {
return false;
}
/* some other comment in a single line */
public static boolean someOtherBooleanMethod() {
/*
some other comment that includes public class MyClass 2 {
*/
return false;
}

public static boolean someOtherMethod() {
public static String someString = 'this string has \' class MyClass2 { ';
return true;
}

private class MyInnerClass {
// Some inner class
}
}
45 changes: 41 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"color": "#ECECEC",
"theme": "light"
},
"version": "0.6.0",
"version": "0.7.0",
"publisher": "salesforce",
"license": "BSD-3-Clause",
"engines": {
Expand Down Expand Up @@ -76,15 +76,23 @@
"commands": [
{
"command": "sfca.runOnActiveFile",
"title": "SF: Scan current file with Code Analyzer"
"title": "SFDX: Scan current file with Code Analyzer"
},
{
"command": "sfca.runOnSelected",
"title": "SF: Scan selected files or folders with Code Analyzer"
"title": "SFDX: Scan selected files or folders with Code Analyzer"
},
{
"command": "sfca.runDfaOnSelectedMethod",
"title": "SF: Scan selected method with Graph Engine path-based analysis"
"title": "SFDX: Scan selected method with Graph Engine path-based analysis"
},
{
"command": "sfca.removeDiagnosticsOnActiveFile",
"title": "SFDX: Clear Code Analyzer violations from current file"
},
{
"command": "sfca.removeDiagnosticsOnSelectedFile",
"title": "SFDX: Clear Code Analyzer violations from selected files or folders"
}
],
"configuration": {
Expand Down Expand Up @@ -123,6 +131,20 @@
"type": "boolean",
"default": false,
"description": "Scan files on open automatically."
},
"codeAnalyzer.scanner.engines": {
"type": "string",
"default": "pmd,retire-js,eslint-lwc",
"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."
},
"codeAnalyzer.normalizeSeverity.enabled": {
"type": "boolean",
"default": false,
"description": "Output normalized severity (high, moderate, low) and engine-specific severity across all engines."
},
"codeAnalyzer.rules.category": {
"type": "string",
"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."
}
}
},
Expand All @@ -139,6 +161,14 @@
{
"command": "sfca.runDfaOnSelectedMethod",
"when": "false"
},
{
"command": "sfca.removeDiagnosticsOnActiveFile",
"when": "true"
},
{
"command": "sfca.removeDiagnosticsOnSelectedFile",
"when": "false"
}
],
"editor/context": [
Expand All @@ -147,11 +177,18 @@
},
{
"command": "sfca.runDfaOnSelectedMethod"
},
{
"command": "sfca.removeDiagnosticsOnActiveFile"
}
],
"explorer/context": [
{
"command": "sfca.runOnSelected"
},
{
"command": "sfca.removeDiagnosticsOnSelectedFile",
"when": "true"
}
]
},
Expand Down
66 changes: 64 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as Constants from './lib/constants';
import * as path from 'path';
import { SIGKILL } from 'constants';

type RunInfo = {
export type RunInfo = {
diagnosticCollection?: vscode.DiagnosticCollection;
outputChannel: vscode.LogOutputChannel;
commandName: string;
Expand Down Expand Up @@ -78,6 +78,23 @@ export async function activate(context: vscode.ExtensionContext): Promise<vscode
outputChannel
});
});
const removeDiagnosticsOnActiveFile = vscode.commands.registerCommand(Constants.COMMAND_REMOVE_DIAGNOSTICS_ON_ACTIVE_FILE, async () => {
return _clearDiagnosticsForSelectedFiles([], {
commandName: Constants.COMMAND_REMOVE_DIAGNOSTICS_ON_ACTIVE_FILE,
diagnosticCollection,
outputChannel
});
});
const removeDiagnosticsOnSelectedFile = vscode.commands.registerCommand(Constants.COMMAND_REMOVE_DIAGNOSTICS_ON_SELECTED_FILE, async (selection: vscode.Uri, multiSelect?: vscode.Uri[]) => {
return _clearDiagnosticsForSelectedFiles(multiSelect && multiSelect.length > 0 ? multiSelect : [selection], {
commandName: Constants.COMMAND_REMOVE_DIAGNOSTICS_ON_SELECTED_FILE,
diagnosticCollection,
outputChannel
});
});
const removeDiagnosticsInRange = vscode.commands.registerCommand(Constants.COMMAND_DIAGNOSTICS_IN_RANGE, (uri: vscode.Uri, range: vscode.Range) => {
_removeDiagnosticsInRange(uri, range, diagnosticCollection);
});
outputChannel.appendLine(`Registered command as part of sfdx-code-analyzer-vscode activation.`);
registerScanOnSave(outputChannel);
registerScanOnOpen(outputChannel);
Expand Down Expand Up @@ -110,12 +127,22 @@ export async function activate(context: vscode.ExtensionContext): Promise<vscode
});
}
});
context.subscriptions.push(runOnActiveFile, runOnSelected, runDfaOnSelectedMethod);
context.subscriptions.push(runOnActiveFile, runOnSelected, runDfaOnSelectedMethod, removeDiagnosticsOnActiveFile, removeDiagnosticsOnSelectedFile, removeDiagnosticsInRange);
TelemetryService.sendExtensionActivationEvent(extensionHrStart);
outputChannel.appendLine(`Extension sfdx-code-analyzer-vscode activated.`);
return Promise.resolve(context);
}

export function _removeDiagnosticsInRange(uri: vscode.Uri, range: vscode.Range, diagnosticCollection: vscode.DiagnosticCollection) {
const currentDiagnostics = diagnosticCollection.get(uri) || [];
const updatedDiagnostics = filterOutDiagnosticsInRange(currentDiagnostics, range);
diagnosticCollection.set(uri, updatedDiagnostics);
}

function filterOutDiagnosticsInRange(currentDiagnostics: readonly vscode.Diagnostic[], range: vscode.Range) {
return currentDiagnostics.filter(diagnostic => (diagnostic.range.start.line != range.start.line && diagnostic.range.end.line != range.end.line));
}

export async function _stopExistingDfaRun(context: vscode.ExtensionContext, outputChannel: vscode.LogOutputChannel): Promise<void> {
const pid = context.workspaceState.get(Constants.WORKSPACE_DFA_PROCESS);
if (pid) {
Expand Down Expand Up @@ -308,6 +335,41 @@ export function _clearDiagnostics(): void {
diagnosticCollection.clear();
}

/**
* Clear diagnostics for a specific files
* @param selections selected files
* @param runInfo command and diagnostic collection object
*/
export async function _clearDiagnosticsForSelectedFiles(selections: vscode.Uri[], runInfo: RunInfo): Promise<void> {
const {
diagnosticCollection,
outputChannel,
commandName
} = runInfo;
const startTime = Date.now();

try {
const targets: string[] = await targeting.getTargets(selections);

for (const target of targets) {
diagnosticCollection.delete(vscode.Uri.file(target));
}

TelemetryService.sendCommandEvent(Constants.TELEM_SUCCESSFUL_STATIC_ANALYSIS, {
executedCommand: commandName,
duration: (Date.now() - startTime).toString()
});
} catch (e) {
const errMsg = e instanceof Error ? e.message : e as string;
console.log(errMsg);
TelemetryService.sendException(Constants.TELEM_FAILED_STATIC_ANALYSIS, errMsg, {
executedCommand: commandName,
duration: (Date.now() - startTime).toString()
});
outputChannel.error(errMsg);
outputChannel.show();
}
}
/**
* 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.
* @param targets The files that were scanned. This may be a superset of the files that actually had violations.
Expand Down
4 changes: 4 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export const EXTENSION_PACK_ID = 'salesforce.salesforcedx-vscode';
export const COMMAND_RUN_ON_ACTIVE_FILE = 'sfca.runOnActiveFile';
export const COMMAND_RUN_ON_SELECTED = 'sfca.runOnSelected';
export const COMMAND_RUN_DFA_ON_SELECTED_METHOD = 'sfca.runDfaOnSelectedMethod';
export const COMMAND_REMOVE_DIAGNOSTICS_ON_ACTIVE_FILE = 'sfca.removeDiagnosticsOnActiveFile';
export const COMMAND_REMOVE_DIAGNOSTICS_ON_SELECTED_FILE = 'sfca.removeDiagnosticsOnSelectedFile';
export const COMMAND_DIAGNOSTICS_IN_RANGE = 'sfca.removeDiagnosticsInRange'


// telemetry event keys
export const TELEM_SUCCESSFUL_STATIC_ANALYSIS = 'sfdx__codeanalyzer_static_run_complete';
Expand Down
Loading

0 comments on commit 0401d9f

Please sign in to comment.