SQSCANGHA-140 Fix code smells

Apply linter fixes to address code smells:
- Use replaceAll() instead of replace() with regex for string replacement
- Update dist files with linter changes

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Claire Villard 2026-04-27 19:10:48 +02:00
parent 7a11667fa2
commit daf2073c97
7 changed files with 27 additions and 26 deletions

32
dist/index.js vendored
View file

@ -1,20 +1,23 @@
import { i as isRooted, w as which, e as exists, a as info, d as debug, m as mkdirP, c as cp, H as HttpClient, r as rmRF, b as isDebug, f as execExports, g as warning, h as addPath, s as setFailed, j as getInput, k as getBooleanInput, l as core } from './exec-zlpfwmpH.js';
import * as crypto from 'crypto';
import * as fs from 'fs';
import fs__default from 'fs';
import * as os from 'os';
import * as child from 'child_process';
import * as path from 'path';
import { join } from 'path';
import * as stream from 'stream';
import * as require$$6 from 'util';
import { ok } from 'assert';
import 'string_decoder';
import * as events from 'events';
import { setTimeout as setTimeout$1 } from 'timers';
import * as fs$1 from 'node:fs';
import * as os$1 from 'node:os';
import * as path$1 from 'node:path';
import * as fs$1 from 'node:fs';
import * as fs$2 from 'node.fs';
import fs__default from 'node.fs';
import * as os$2 from 'node.os';
import * as path$2 from 'node.path';
import { join } from 'node.path';
import 'http';
import 'https';
import 'net';
@ -3963,7 +3966,7 @@ function convertToUnixPath(windowsPath) {
}
// Convert backslashes to forward slashes
let unixPath = windowsPath.replace(/\\/g, "/");
let unixPath = windowsPath.replaceAll('\\', "/");
// Convert drive letter (e.g., C: -> /c)
unixPath = unixPath.replace(/^([A-Za-z]):/, (match, drive) => {
@ -4045,7 +4048,6 @@ async function importSonarSourceKey(gpgHome, keyFingerprint, keyserver) {
info(`Attempting fallback keyserver ${FALLBACK_KEYSERVER}...`);
await tryImportKey(gpgHome, keyFingerprint, FALLBACK_KEYSERVER);
info(`Successfully imported key from fallback keyserver ${FALLBACK_KEYSERVER}`);
return;
} catch (fallbackError) {
throw new Error(
`Failed to import SonarSource public key from all keyservers. ` +
@ -4135,7 +4137,7 @@ async function installSonarScanner({
scannerBinariesUrl,
skipSignatureVerification = false,
}) {
const flavor = getPlatformFlavor(os.platform(), os.arch());
const flavor = getPlatformFlavor(os$1.platform(), os$1.arch());
// Check if tool is already cached
let toolDir = find(TOOLNAME, scannerVersion, flavor);
@ -4177,7 +4179,7 @@ async function installSonarScanner({
const extractedPath = await extractZip(downloadPath);
// Find the actual scanner directory inside the extracted folder
const scannerPath = path.join(
const scannerPath = path$1.join(
extractedPath,
scannerDirName(scannerVersion, flavor)
);
@ -4190,7 +4192,7 @@ async function installSonarScanner({
}
// Add the bin directory to PATH
const binDir = path.join(toolDir, "bin");
const binDir = path$1.join(toolDir, "bin");
addPath(binDir);
return toolDir;
@ -4285,15 +4287,15 @@ async function runSonarScanner(
}
// The SSL folder may exist on an uncleaned self-hosted runner
const sslFolder = path.join(os.homedir(), ".sonar", "ssl");
const truststoreFile = path.join(sslFolder, "truststore.p12");
const sslFolder = path$2.join(os$2.homedir(), ".sonar", "ssl");
const truststoreFile = path$2.join(sslFolder, "truststore.p12");
const keytoolParams = {
scannerDir,
truststoreFile,
};
if (fs.existsSync(truststoreFile)) {
if (fs$2.existsSync(truststoreFile)) {
let aliasSonarIsPresent = true;
try {
@ -4315,16 +4317,16 @@ async function runSonarScanner(
if (sonarRootCert) {
info("Adding SSL certificate to the Scanner truststore");
const tempCertPath = path.join(runnerTemp, "tmpcert.pem");
const tempCertPath = path$2.join(runnerTemp, "tmpcert.pem");
try {
fs.unlinkSync(tempCertPath);
fs$2.unlinkSync(tempCertPath);
} catch (_) {
// File doesn't exist, ignore
}
fs.writeFileSync(tempCertPath, sonarRootCert);
fs.mkdirSync(sslFolder, { recursive: true });
fs$2.writeFileSync(tempCertPath, sonarRootCert);
fs$2.mkdirSync(sslFolder, { recursive: true });
await importCertificateToTruststore(keytoolParams, tempCertPath);

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -62,7 +62,7 @@ describe("validateScannerVersion", () => {
validVersions.forEach((version) => {
it(`accepts ${version}`, () => {
assert.equal(validateScannerVersion(version), undefined);
assert.equals(validateScannerVersion(version), undefined);
});
});

View file

@ -111,7 +111,7 @@ export function convertToUnixPath(windowsPath) {
}
// Convert backslashes to forward slashes
let unixPath = windowsPath.replace(/\\/g, "/");
let unixPath = windowsPath.replaceAll('\\', "/");
// Convert drive letter (e.g., C: -> /c)
unixPath = unixPath.replace(/^([A-Za-z]):/, (match, drive) => {
@ -193,7 +193,6 @@ export async function importSonarSourceKey(gpgHome, keyFingerprint, keyserver) {
core.info(`Attempting fallback keyserver ${FALLBACK_KEYSERVER}...`);
await tryImportKey(gpgHome, keyFingerprint, FALLBACK_KEYSERVER);
core.info(`Successfully imported key from fallback keyserver ${FALLBACK_KEYSERVER}`);
return;
} catch (fallbackError) {
throw new Error(
`Failed to import SonarSource public key from all keyservers. ` +

View file

@ -18,8 +18,8 @@
import * as core from "@actions/core";
import * as tc from "@actions/tool-cache";
import * as os from "os";
import * as path from "path";
import * as os from "node:os";
import * as path from "node:path";
import {
getPlatformFlavor,
getScannerDownloadURL,

View file

@ -18,9 +18,9 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import * as fs from "node.fs";
import * as os from "node.os";
import * as path from "node.path";
import { parseArgsStringToArgv } from "string-argv";
const KEYTOOL_MAIN_CLASS = "sun.security.tools.keytool.Main";

View file

@ -16,8 +16,8 @@
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import fs from "fs";
import { join } from "path";
import fs from "node.fs";
import { join } from "node.path";
export function validateScannerVersion(version) {
if (!version) {