diff --git a/eslint.config.mjs b/eslint.config.mjs index bd12d12c70..ae9cf27460 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -131,6 +131,7 @@ export default [ "no-sequences": "error", "no-shadow": "off", "@typescript-eslint/no-shadow": "error", + "@typescript-eslint/prefer-optional-chain": "error", "one-var": ["error", "never"], }, }, diff --git a/lib/analyze-action.js b/lib/analyze-action.js index 8b936b19d2..168be4f510 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -91887,13 +91887,13 @@ async function getTarVersion() { } if (stdout.includes("GNU tar")) { const match = stdout.match(/tar \(GNU tar\) ([0-9.]+)/); - if (!match || !match[1]) { + if (!match?.[1]) { throw new Error("Failed to parse output of tar --version."); } return { type: "gnu", version: match[1] }; } else if (stdout.includes("bsdtar")) { const match = stdout.match(/bsdtar ([0-9.]+)/); - if (!match || !match[1]) { + if (!match?.[1]) { throw new Error("Failed to parse output of tar --version."); } return { type: "bsd", version: match[1] }; @@ -92273,7 +92273,7 @@ function tryGetTagNameFromUrl(url2, logger) { return void 0; } const match = matches[matches.length - 1]; - if (match === null || match.length !== 2) { + if (match?.length !== 2) { logger.debug( `Could not determine tag name for URL ${url2}. Matched ${JSON.stringify( match diff --git a/lib/init-action-post.js b/lib/init-action-post.js index b2de76f433..5ebaaa8722 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -129872,13 +129872,13 @@ async function getTarVersion() { } if (stdout.includes("GNU tar")) { const match = stdout.match(/tar \(GNU tar\) ([0-9.]+)/); - if (!match || !match[1]) { + if (!match?.[1]) { throw new Error("Failed to parse output of tar --version."); } return { type: "gnu", version: match[1] }; } else if (stdout.includes("bsdtar")) { const match = stdout.match(/bsdtar ([0-9.]+)/); - if (!match || !match[1]) { + if (!match?.[1]) { throw new Error("Failed to parse output of tar --version."); } return { type: "bsd", version: match[1] }; @@ -130258,7 +130258,7 @@ function tryGetTagNameFromUrl(url2, logger) { return void 0; } const match = matches[matches.length - 1]; - if (match === null || match.length !== 2) { + if (match?.length !== 2) { logger.debug( `Could not determine tag name for URL ${url2}. Matched ${JSON.stringify( match @@ -133655,7 +133655,7 @@ function getInputOrThrow(workflow, jobName, actionName, inputName, matrixVars) { input = input.replace(`\${{matrix.${key}}}`, value); } } - if (input !== void 0 && input.includes("${{")) { + if (input?.includes("${{")) { throw new Error( `Could not get ${inputName} input to ${actionName} since it contained an unrecognized dynamic value.` ); diff --git a/lib/init-action.js b/lib/init-action.js index 18e350024c..324b93b6ef 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -88036,7 +88036,7 @@ function parseQueriesFromInput(rawQueriesInput, queriesInputCombines, errorToThr } function combineQueries(logger, config, augmentationProperties) { const result = []; - if (augmentationProperties.repoPropertyQueries && augmentationProperties.repoPropertyQueries.input) { + if (augmentationProperties.repoPropertyQueries?.input) { logger.info( `Found query configuration in the repository properties (${"github-codeql-extra-queries" /* EXTRA_QUERIES */}): ${augmentationProperties.repoPropertyQueries.input.map((q) => q.uses).join(", ")}` ); @@ -89584,7 +89584,7 @@ async function getRemoteConfig(logger, configFile, apiDetails, validateConfig) { "(?[^/]+)/(?[^/]+)/(?[^@]+)@(?.*)" ); const pieces = format.exec(configFile); - if (pieces === null || pieces.groups === void 0 || pieces.length < 5) { + if (pieces?.groups === void 0 || pieces.length < 5) { throw new ConfigurationError( getConfigFileRepoFormatInvalidMessage(configFile) ); @@ -90194,13 +90194,13 @@ async function getTarVersion() { } if (stdout.includes("GNU tar")) { const match = stdout.match(/tar \(GNU tar\) ([0-9.]+)/); - if (!match || !match[1]) { + if (!match?.[1]) { throw new Error("Failed to parse output of tar --version."); } return { type: "gnu", version: match[1] }; } else if (stdout.includes("bsdtar")) { const match = stdout.match(/bsdtar ([0-9.]+)/); - if (!match || !match[1]) { + if (!match?.[1]) { throw new Error("Failed to parse output of tar --version."); } return { type: "bsd", version: match[1] }; @@ -90580,7 +90580,7 @@ function tryGetTagNameFromUrl(url, logger) { return void 0; } const match = matches[matches.length - 1]; - if (match === null || match.length !== 2) { + if (match?.length !== 2) { logger.debug( `Could not determine tag name for URL ${url}. Matched ${JSON.stringify( match diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index 37fc43ec6d..7434669fc9 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -87151,13 +87151,13 @@ async function getTarVersion() { } if (stdout.includes("GNU tar")) { const match = stdout.match(/tar \(GNU tar\) ([0-9.]+)/); - if (!match || !match[1]) { + if (!match?.[1]) { throw new Error("Failed to parse output of tar --version."); } return { type: "gnu", version: match[1] }; } else if (stdout.includes("bsdtar")) { const match = stdout.match(/bsdtar ([0-9.]+)/); - if (!match || !match[1]) { + if (!match?.[1]) { throw new Error("Failed to parse output of tar --version."); } return { type: "bsd", version: match[1] }; @@ -87537,7 +87537,7 @@ function tryGetTagNameFromUrl(url, logger) { return void 0; } const match = matches[matches.length - 1]; - if (match === null || match.length !== 2) { + if (match?.length !== 2) { logger.debug( `Could not determine tag name for URL ${url}. Matched ${JSON.stringify( match diff --git a/lib/start-proxy-action-post.js b/lib/start-proxy-action-post.js index b224695c4b..94c68de174 100644 --- a/lib/start-proxy-action-post.js +++ b/lib/start-proxy-action-post.js @@ -118975,7 +118975,7 @@ async function runWrapper() { getTemporaryDirectory(), logger ); - if (config && config.debugMode || core13.isDebug()) { + if (config?.debugMode || core13.isDebug()) { const logFilePath = core13.getState("proxy-log-file"); logger.info( "Debug mode is on. Uploading proxy log as Actions debugging artifact..." diff --git a/lib/upload-lib.js b/lib/upload-lib.js index a952f35ab4..bb5628b24b 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -89703,13 +89703,13 @@ async function getTarVersion() { } if (stdout.includes("GNU tar")) { const match = stdout.match(/tar \(GNU tar\) ([0-9.]+)/); - if (!match || !match[1]) { + if (!match?.[1]) { throw new Error("Failed to parse output of tar --version."); } return { type: "gnu", version: match[1] }; } else if (stdout.includes("bsdtar")) { const match = stdout.match(/bsdtar ([0-9.]+)/); - if (!match || !match[1]) { + if (!match?.[1]) { throw new Error("Failed to parse output of tar --version."); } return { type: "bsd", version: match[1] }; @@ -90089,7 +90089,7 @@ function tryGetTagNameFromUrl(url2, logger) { return void 0; } const match = matches[matches.length - 1]; - if (match === null || match.length !== 2) { + if (match?.length !== 2) { logger.debug( `Could not determine tag name for URL ${url2}. Matched ${JSON.stringify( match diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index 9596cc4512..af65a9ee26 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -90376,13 +90376,13 @@ async function getTarVersion() { } if (stdout.includes("GNU tar")) { const match = stdout.match(/tar \(GNU tar\) ([0-9.]+)/); - if (!match || !match[1]) { + if (!match?.[1]) { throw new Error("Failed to parse output of tar --version."); } return { type: "gnu", version: match[1] }; } else if (stdout.includes("bsdtar")) { const match = stdout.match(/bsdtar ([0-9.]+)/); - if (!match || !match[1]) { + if (!match?.[1]) { throw new Error("Failed to parse output of tar --version."); } return { type: "bsd", version: match[1] }; @@ -90762,7 +90762,7 @@ function tryGetTagNameFromUrl(url2, logger) { return void 0; } const match = matches[matches.length - 1]; - if (match === null || match.length !== 2) { + if (match?.length !== 2) { logger.debug( `Could not determine tag name for URL ${url2}. Matched ${JSON.stringify( match diff --git a/src/config-utils.ts b/src/config-utils.ts index f523213b1d..3a1d040db0 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -943,7 +943,7 @@ async function getRemoteConfig( ); const pieces = format.exec(configFile); // 5 = 4 groups + the whole expression - if (pieces === null || pieces.groups === undefined || pieces.length < 5) { + if (pieces?.groups === undefined || pieces.length < 5) { throw new ConfigurationError( errorMessages.getConfigFileRepoFormatInvalidMessage(configFile), ); diff --git a/src/config/db-config.ts b/src/config/db-config.ts index 16cda3abf3..3293535f39 100644 --- a/src/config/db-config.ts +++ b/src/config/db-config.ts @@ -380,10 +380,7 @@ function combineQueries( const result: QuerySpec[] = []; // Query settings obtained from the repository properties have the highest precedence. - if ( - augmentationProperties.repoPropertyQueries && - augmentationProperties.repoPropertyQueries.input - ) { + if (augmentationProperties.repoPropertyQueries?.input) { logger.info( `Found query configuration in the repository properties (${RepositoryPropertyName.EXTRA_QUERIES}): ` + `${augmentationProperties.repoPropertyQueries.input.map((q) => q.uses).join(", ")}`, diff --git a/src/setup-codeql.ts b/src/setup-codeql.ts index 9ee0c4b82a..9488930229 100644 --- a/src/setup-codeql.ts +++ b/src/setup-codeql.ts @@ -168,7 +168,7 @@ export function tryGetTagNameFromUrl( // assumes less about the structure of the URL. const match = matches[matches.length - 1]; - if (match === null || match.length !== 2) { + if (match?.length !== 2) { logger.debug( `Could not determine tag name for URL ${url}. Matched ${JSON.stringify( match, diff --git a/src/start-proxy-action-post.ts b/src/start-proxy-action-post.ts index 100b8a75ff..5042d5229f 100644 --- a/src/start-proxy-action-post.ts +++ b/src/start-proxy-action-post.ts @@ -30,7 +30,7 @@ async function runWrapper() { logger, ); - if ((config && config.debugMode) || core.isDebug()) { + if (config?.debugMode || core.isDebug()) { const logFilePath = core.getState("proxy-log-file"); logger.info( "Debug mode is on. Uploading proxy log as Actions debugging artifact...", diff --git a/src/tar.ts b/src/tar.ts index 280f3d7f7b..93e9a05548 100644 --- a/src/tar.ts +++ b/src/tar.ts @@ -35,14 +35,14 @@ async function getTarVersion(): Promise { // Return whether this is GNU tar or BSD tar, and the version number if (stdout.includes("GNU tar")) { const match = stdout.match(/tar \(GNU tar\) ([0-9.]+)/); - if (!match || !match[1]) { + if (!match?.[1]) { throw new Error("Failed to parse output of tar --version."); } return { type: "gnu", version: match[1] }; } else if (stdout.includes("bsdtar")) { const match = stdout.match(/bsdtar ([0-9.]+)/); - if (!match || !match[1]) { + if (!match?.[1]) { throw new Error("Failed to parse output of tar --version."); } diff --git a/src/workflow.ts b/src/workflow.ts index ee95c337f5..adcb22baec 100644 --- a/src/workflow.ts +++ b/src/workflow.ts @@ -371,7 +371,7 @@ function getInputOrThrow( input = input.replace(`\${{matrix.${key}}}`, value); } } - if (input !== undefined && input.includes("${{")) { + if (input?.includes("${{")) { throw new Error( `Could not get ${inputName} input to ${actionName} since it contained an unrecognized dynamic value.`, );