Skip to content

Commit 9687d13

Browse files
committed
Refactoring 2) Sonar
1 parent 008766d commit 9687d13

13 files changed

Lines changed: 185 additions & 103 deletions

python/vTestInterface.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def isManageEnviroOfInterest(enviroNode):
626626

627627
returnValue = False
628628
# we only care about unit test environments
629-
if not enviroNode.definition.env_type == EnvironmentType.COVER:
629+
if enviroNode.definition.env_type != EnvironmentType.COVER:
630630
# we don't care about ignored or monitored environments
631631
if enviroNode.is_active and not enviroNode.is_monitored:
632632
returnValue = True
@@ -635,13 +635,13 @@ def isManageEnviroOfInterest(enviroNode):
635635

636636

637637
def manageEnviroIsBuilt(enviroNode, enviroName):
638-
639638
returnValue = False
640-
if os.path.isdir(enviroNode.build_directory):
641-
if os.path.isfile(
642-
os.path.join(enviroNode.build_directory, enviroName, "UNITDATA.VCD")
643-
):
644-
returnValue = True
639+
640+
if os.path.isdir(enviroNode.build_directory) and os.path.isfile(
641+
os.path.join(enviroNode.build_directory, enviroName, "UNITDATA.VCD")
642+
):
643+
returnValue = True
644+
645645
return returnValue
646646

647647

src/callbacks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export async function deleteEnvironmentCallback(
109109
// We check if it is present in the unbuilt list
110110
// If so, we take the id and split it after "vcast:" to get the path
111111
// In case that is not possible, we throw an error message
112-
if (vcastUnbuiltEnviroList.includes(enviroNodeID)) {
112+
if (vcastUnbuiltEnviroList.has(enviroNodeID)) {
113113
const parts = enviroNodeID.split(":");
114114
enviroPath = parts.slice(1).join(":");
115115
} else {

src/extension.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ function configureExtension(context: vscode.ExtensionContext) {
711711
"vectorcastTestExplorer.addCompilerToProject",
712712
async (args: any) => {
713713
// Verify that the command was invoked from a node with an 'id' property.
714-
if (!args || !args.id) {
714+
if (!args?.id) {
715715
vscode.window.showErrorMessage("No project node provided.");
716716
return;
717717
}
@@ -907,7 +907,7 @@ function configureExtension(context: vscode.ExtensionContext) {
907907
// So we check if it is present in the unbuilt list
908908
// If so, we take the id and split it after "vcast:" to get the path
909909
// In case that is not possible, we throw an error message
910-
if (vcastUnbuiltEnviroList.includes(enviroNode.id)) {
910+
if (vcastUnbuiltEnviroList.has(enviroNode.id)) {
911911
const parts = enviroNode.id.split(":");
912912
enviroPath = parts.slice(1).join(":");
913913
} else {
@@ -1352,7 +1352,7 @@ async function installPreActivationEventHandlers(
13521352
const projectData = JSON.stringify(
13531353
Array.from(globalProjectWebviewComboboxItems.entries())
13541354
);
1355-
const initialEnvFile = JSON.stringify(argList[0]?.fsPath || "");
1355+
const initialEnvFile = JSON.stringify(argList[0]?.fsPath ?? "");
13561356

13571357
// load the template
13581358
let html = fs.readFileSync(htmlPath, "utf8");
@@ -1423,7 +1423,7 @@ async function installPreActivationEventHandlers(
14231423
vscode.window.showInformationMessage(
14241424
`Creating environment in ${projectPath} with ${testsuiteArgs.join(", ")} and sources ${sourceFiles.join(", ")}`
14251425
);
1426-
await newEnvironment(argList, params);
1426+
newEnvironment(argList, params);
14271427
panel.dispose();
14281428
} else if (message.command === "cancel") {
14291429
panel.dispose();

src/manage/manageSrc/manageCallbacks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function cleanEnvironmentCallback(
3333
// We check if it is present in the unbuilt list
3434
// If so, we take the id and split it after "vcast:" to get the path
3535
// In case that is not possible, we throw an error message
36-
if (vcastUnbuiltEnviroList.includes(enviroNodeID)) {
36+
if (vcastUnbuiltEnviroList.has(enviroNodeID)) {
3737
const parts = enviroNodeID.split(":");
3838
enviroPath = parts.slice(1).join(":");
3939
} else {

src/manage/manageSrc/manageCommands.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ export async function cleanProjectEnvironment(
8484
const projectName = path.basename(projectPath);
8585
const projectLocation = path.dirname(projectPath);
8686
const progressMessage = `Cleaning up Environment ${level} ...`;
87-
const manageArgs = [`-p${projectName}`, `--level=${level}`, "--clean"];
87+
const manageArgs = [
88+
`-p${projectName}`,
89+
`--level=${level}`,
90+
"--clean",
91+
"--force",
92+
];
8893

8994
// if we are in server mode, close any existing connection to the environment
9095
if (globalEnviroDataServerActive) await closeConnection(enviroPath);

src/manage/webviews/html/importEnv.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
<h2>Create Environment in Project</h2>
1313

1414
<!-- Project Path -->
15-
<label>Project Path:</label>
15+
<label for="projectPath">Project Path:</label>
1616
<div class="single-input-container">
1717
<select id="projectPath"></select>
1818
</div>
1919

2020
<!-- Env File -->
21-
<label>Env File:</label>
21+
<label for="envFileInput">Env File:</label>
2222
<div class="single-input-container">
2323
<input aria-label="envFileInput" type="text" id="envFileInput" placeholder="Select Env File" />
2424
<button type="button" class="select-button" id="btnSelectEnv">Select</button>

src/manage/webviews/html/newEnvProject.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
<div class="modal">
1313
<h2>Create Environment in Project</h2>
1414

15-
<label>Project Path:</label>
15+
<label for="projectPath">Project Path:</label>
1616
<div class="single-input-container">
1717
<select id="projectPath"></select>
1818
</div>
1919

20-
<label>Source Files:</label>
20+
<label for="sourceFilesContainer">Project Path:</label>
2121
<div id="sourceFilesContainer"></div>
2222
<div class="single-add-row">
2323
<button type="button" class="add-button" id="btnAddSource"></button>

src/manage/webviews/webviewScripts/addTestsuite.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// manage/webviewScripts/addTestsuite.js
2-
31
const vscode = acquireVsCodeApi();
42

53
function submitForm() {

src/manage/webviews/webviewScripts/newEnvProject.js

Lines changed: 99 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,143 @@
1+
// Acquire the VS Code API for communication with the extension backend
12
const vscode = acquireVsCodeApi();
3+
4+
// Initialize project mapping and source files from the window's global data
25
const projectMap = new Map(window.projectData || []);
36
const initialSourceFiles = window.initialSourceFiles || [];
47

5-
// receive envFileSelected? (not used here but pattern in other scripts)
8+
// ---------------------------------------
9+
// UI Helper Functions
10+
// ---------------------------------------
611

12+
/**
13+
* Adds a new source file row to the "Source Files" container.
14+
* @param {string} filePath - Optional initial file path to populate.
15+
*/
716
function addSourceRow(filePath = '') {
817
const container = document.getElementById('sourceFilesContainer');
18+
919
const row = document.createElement('div');
1020
row.className = 'single-input-container';
21+
1122
const input = document.createElement('input');
12-
input.type = 'text'; input.value = filePath; input.placeholder = 'Enter Source File';
13-
const rm = document.createElement('button');
14-
rm.className = 'remove-button'; rm.textContent = '✖';
15-
rm.addEventListener('click', () => row.remove());
16-
row.append(input, rm);
23+
input.type = 'text';
24+
input.value = filePath;
25+
input.placeholder = 'Enter Source File';
26+
27+
const removeButton = document.createElement('button');
28+
removeButton.className = 'remove-button';
29+
removeButton.textContent = '✖';
30+
removeButton.addEventListener('click', () => row.remove());
31+
32+
row.append(input, removeButton);
1733
container.appendChild(row);
1834
}
1935

36+
/**
37+
* Adds a new compiler/testsuites row based on the selected project path.
38+
*/
2039
function addCompilerRow() {
21-
const ps = document.getElementById('projectPath');
22-
const info = projectMap.get(ps.value);
23-
if (!info) return;
40+
const projectSelect = document.getElementById('projectPath');
41+
const projectInfo = projectMap.get(projectSelect.value);
42+
43+
if (!projectInfo) return; // No project info available
44+
2445
const row = document.createElement('div');
2546
row.className = 'double-input-container';
26-
const comp = document.createElement('select');
27-
comp.innerHTML = info.compilers.map(c => `<option>${c}</option>`).join('');
28-
const ts = document.createElement('select');
29-
ts.innerHTML = info.testsuites.map(t => `<option>${t}</option>`).join('');
30-
const rm = document.createElement('button');
31-
rm.className = 'remove-button'; rm.textContent = '✖';
32-
rm.addEventListener('click', () => row.remove());
33-
row.append(comp, ts, rm);
47+
48+
const compilerSelect = document.createElement('select');
49+
compilerSelect.innerHTML = projectInfo.compilers.map(c => `<option>${c}</option>`).join('');
50+
51+
const testsuiteSelect = document.createElement('select');
52+
testsuiteSelect.innerHTML = projectInfo.testsuites.map(t => `<option>${t}</option>`).join('');
53+
54+
const removeButton = document.createElement('button');
55+
removeButton.className = 'remove-button';
56+
removeButton.textContent = '✖';
57+
removeButton.addEventListener('click', () => row.remove());
58+
59+
row.append(compilerSelect, testsuiteSelect, removeButton);
3460
document.getElementById('compilerContainer').appendChild(row);
3561
}
3662

63+
/**
64+
* Gathers form data and sends a 'submit' message to the extension.
65+
*/
3766
function submitForm() {
3867
const projectPath = document.getElementById('projectPath').value;
68+
69+
// Collect all source file input values
3970
const sourceFiles = Array.from(
4071
document.querySelectorAll('#sourceFilesContainer input')
41-
).map(i => i.value);
72+
).map(input => input.value);
73+
74+
// Collect compiler/testsuites selections
4275
const testsuiteArgs = Array.from(
4376
document.querySelectorAll('#compilerContainer .double-input-container')
44-
).map(r => {
45-
const [c, t] = r.querySelectorAll('select');
46-
return `${c.value}/${t.value}`;
77+
).map(row => {
78+
const [compilerSelect, testsuiteSelect] = row.querySelectorAll('select');
79+
return `${compilerSelect.value}/${testsuiteSelect.value}`;
4780
});
81+
82+
// Validate form
4883
if (!projectPath || testsuiteArgs.length === 0) {
49-
vscode.postMessage({ command: 'error', message: 'Project Path and Testsuite are required.' });
84+
vscode.postMessage({
85+
command: 'error',
86+
message: 'Project Path and at least one Testsuite are required.'
87+
});
5088
return;
5189
}
52-
vscode.postMessage({ command: 'submit', projectPath, sourceFiles, testsuiteArgs });
90+
91+
// Submit collected data
92+
vscode.postMessage({
93+
command: 'submit',
94+
projectPath,
95+
sourceFiles,
96+
testsuiteArgs
97+
});
5398
}
5499

100+
/**
101+
* Cancels the operation and informs the extension.
102+
*/
55103
function cancel() {
56104
vscode.postMessage({ command: 'cancel' });
57105
}
58106

107+
// ---------------------------------------
108+
// Initialization
109+
// ---------------------------------------
110+
111+
/**
112+
* Initializes the form when the DOM content is fully loaded.
113+
*/
59114
window.addEventListener('DOMContentLoaded', () => {
60-
const ps = document.getElementById('projectPath');
115+
const projectSelect = document.getElementById('projectPath');
116+
117+
// Populate the project path dropdown
61118
for (const [key] of projectMap.entries()) {
62-
const opt = document.createElement('option');
63-
opt.value = key; opt.text = key; ps.append(opt);
119+
const option = document.createElement('option');
120+
option.value = key;
121+
option.text = key;
122+
projectSelect.append(option);
64123
}
65-
initialSourceFiles.forEach(f => addSourceRow(f));
66-
if (initialSourceFiles.length === 0) addSourceRow();
124+
125+
// Populate initial source files, or add an empty one if none exist
126+
initialSourceFiles.forEach(filePath => addSourceRow(filePath));
127+
if (initialSourceFiles.length === 0) {
128+
addSourceRow();
129+
}
130+
131+
// Add an initial compiler/testsuites row
67132
addCompilerRow();
68-
ps.addEventListener('change', () => {
69-
document.querySelectorAll('.double-input-container').forEach(r => r.remove());
133+
134+
// Update compiler/testsuites when the project changes
135+
projectSelect.addEventListener('change', () => {
136+
document.querySelectorAll('.double-input-container').forEach(row => row.remove());
70137
addCompilerRow();
71138
});
139+
140+
// Hook up button event listeners
72141
document.getElementById('btnAddSource').addEventListener('click', () => addSourceRow());
73142
document.getElementById('btnAddCompiler').addEventListener('click', addCompilerRow);
74143
document.getElementById('btnSubmit').addEventListener('click', submitForm);

src/testData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface environmentNodeDataType {
1111
// This is a lookup table for all environment nodes
1212
// in the test case tree. The key is the environmentPath
1313
// and the data is an environmentDataType
14-
export let environmentDataCache = new Map();
14+
export const environmentDataCache = new Map();
1515

1616
export function saveEnviroNodeData(
1717
enviroPath: string,
@@ -45,7 +45,7 @@ export interface testNodeType {
4545
}
4646
// this is a lookup table for the nodes in the test tree
4747
// the key is the nodeID, the data is an testNodeType
48-
export let testNodeCache = new Map();
48+
export const testNodeCache = new Map();
4949

5050
// This function is used to create the top-level environment
5151
// node in the cache, all the other nodes will inherit from

0 commit comments

Comments
 (0)