Merge pull request #310 from ericcornelissen/eslint-rule/no-shadow
Update code so "no-shadow" passes
This commit is contained in:
commit
c5d599ecb2
22 changed files with 166 additions and 155 deletions
|
|
@ -29,6 +29,8 @@
|
||||||
"no-async-foreach/no-async-foreach": "error",
|
"no-async-foreach/no-async-foreach": "error",
|
||||||
"no-console": "off",
|
"no-console": "off",
|
||||||
"no-sequences": "error",
|
"no-sequences": "error",
|
||||||
|
"no-shadow": "off",
|
||||||
|
"@typescript-eslint/no-shadow": ["error"],
|
||||||
"one-var": ["error", "never"]
|
"one-var": ["error", "never"]
|
||||||
},
|
},
|
||||||
"overrides": [{
|
"overrides": [{
|
||||||
|
|
@ -48,8 +50,7 @@
|
||||||
"@typescript-eslint/require-await": "off",
|
"@typescript-eslint/require-await": "off",
|
||||||
"@typescript-eslint/restrict-template-expressions": "off",
|
"@typescript-eslint/restrict-template-expressions": "off",
|
||||||
"func-style": "off",
|
"func-style": "off",
|
||||||
"github/no-then": "off",
|
"github/no-then": "off"
|
||||||
"no-shadow": "off"
|
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
lib/api-client.js
generated
2
lib/api-client.js
generated
|
|
@ -33,7 +33,7 @@ exports.getApiClient = function (githubAuth, githubUrl, mode, logger, allowLocal
|
||||||
throw new Error("Invalid API call in local run");
|
throw new Error("Invalid API call in local run");
|
||||||
}
|
}
|
||||||
const customOctokit = githubUtils.GitHub.plugin(retry.retry, (octokit, _) => {
|
const customOctokit = githubUtils.GitHub.plugin(retry.retry, (octokit, _) => {
|
||||||
octokit.hook.after("request", (response, _) => {
|
octokit.hook.after("request", (response, __) => {
|
||||||
if (response.status < 400 && !possibleFailureExpected) {
|
if (response.status < 400 && !possibleFailureExpected) {
|
||||||
if (hasBeenWarnedAboutVersion) {
|
if (hasBeenWarnedAboutVersion) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"api-client.js","sourceR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B,cAAsB;IAEtB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,cAAc,EAAE,CAAC,EAAE;QACrD,OAAO,0BAA0B,CAAC,cAAc,CAAC;KAClD;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,cAAc,EAAE,CAAC,EAAE;QACrD,OAAO,0BAA0B,CAAC,cAAc,CAAC;KAClD;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAZD,8CAYC"}
|
||||||
54
lib/codeql.js
generated
54
lib/codeql.js
generated
|
|
@ -418,9 +418,31 @@ function getCodeQLForCmd(cmd) {
|
||||||
/**
|
/**
|
||||||
* Gets the options for `path` of `options` as an array of extra option strings.
|
* Gets the options for `path` of `options` as an array of extra option strings.
|
||||||
*/
|
*/
|
||||||
function getExtraOptionsFromEnv(path) {
|
function getExtraOptionsFromEnv(paths) {
|
||||||
const options = util.getExtraOptionsEnvParam();
|
const options = util.getExtraOptionsEnvParam();
|
||||||
return getExtraOptions(options, path, []);
|
return getExtraOptions(options, paths, []);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Gets `options` as an array of extra option strings.
|
||||||
|
*
|
||||||
|
* - throws an exception mentioning `pathInfo` if this conversion is impossible.
|
||||||
|
*/
|
||||||
|
function asExtraOptions(options, pathInfo) {
|
||||||
|
if (options === undefined) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
if (!Array.isArray(options)) {
|
||||||
|
const msg = `The extra options for '${pathInfo.join(".")}' ('${JSON.stringify(options)}') are not in an array.`;
|
||||||
|
throw new Error(msg);
|
||||||
|
}
|
||||||
|
return options.map((o) => {
|
||||||
|
const t = typeof o;
|
||||||
|
if (t !== "string" && t !== "number" && t !== "boolean") {
|
||||||
|
const msg = `The extra option for '${pathInfo.join(".")}' ('${JSON.stringify(o)}') is not a primitive value.`;
|
||||||
|
throw new Error(msg);
|
||||||
|
}
|
||||||
|
return `${o}`;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Gets the options for `path` of `options` as an array of extra option strings.
|
* Gets the options for `path` of `options` as an array of extra option strings.
|
||||||
|
|
@ -430,34 +452,12 @@ function getExtraOptionsFromEnv(path) {
|
||||||
*
|
*
|
||||||
* Exported for testing.
|
* Exported for testing.
|
||||||
*/
|
*/
|
||||||
function getExtraOptions(options, path, pathInfo) {
|
function getExtraOptions(options, paths, pathInfo) {
|
||||||
var _a, _b, _c;
|
var _a, _b, _c;
|
||||||
/**
|
|
||||||
* Gets `options` as an array of extra option strings.
|
|
||||||
*
|
|
||||||
* - throws an exception mentioning `pathInfo` if this conversion is impossible.
|
|
||||||
*/
|
|
||||||
function asExtraOptions(options, pathInfo) {
|
|
||||||
if (options === undefined) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
if (!Array.isArray(options)) {
|
|
||||||
const msg = `The extra options for '${pathInfo.join(".")}' ('${JSON.stringify(options)}') are not in an array.`;
|
|
||||||
throw new Error(msg);
|
|
||||||
}
|
|
||||||
return options.map((o) => {
|
|
||||||
const t = typeof o;
|
|
||||||
if (t !== "string" && t !== "number" && t !== "boolean") {
|
|
||||||
const msg = `The extra option for '${pathInfo.join(".")}' ('${JSON.stringify(o)}') is not a primitive value.`;
|
|
||||||
throw new Error(msg);
|
|
||||||
}
|
|
||||||
return `${o}`;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const all = asExtraOptions((_a = options) === null || _a === void 0 ? void 0 : _a["*"], pathInfo.concat("*"));
|
const all = asExtraOptions((_a = options) === null || _a === void 0 ? void 0 : _a["*"], pathInfo.concat("*"));
|
||||||
const specific = path.length === 0
|
const specific = paths.length === 0
|
||||||
? asExtraOptions(options, pathInfo)
|
? asExtraOptions(options, pathInfo)
|
||||||
: getExtraOptions((_b = options) === null || _b === void 0 ? void 0 : _b[path[0]], (_c = path) === null || _c === void 0 ? void 0 : _c.slice(1), pathInfo.concat(path[0]));
|
: getExtraOptions((_b = options) === null || _b === void 0 ? void 0 : _b[paths[0]], (_c = paths) === null || _c === void 0 ? void 0 : _c.slice(1), pathInfo.concat(paths[0]));
|
||||||
return all.concat(specific);
|
return all.concat(specific);
|
||||||
}
|
}
|
||||||
exports.getExtraOptions = getExtraOptions;
|
exports.getExtraOptions = getExtraOptions;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
36
lib/config-utils.js
generated
36
lib/config-utils.js
generated
|
|
@ -99,8 +99,8 @@ const builtinSuites = ["security-extended", "security-and-quality"];
|
||||||
* Throws an error if suiteName is not a valid builtin suite.
|
* Throws an error if suiteName is not a valid builtin suite.
|
||||||
*/
|
*/
|
||||||
async function addBuiltinSuiteQueries(languages, codeQL, resultMap, suiteName, configFile) {
|
async function addBuiltinSuiteQueries(languages, codeQL, resultMap, suiteName, configFile) {
|
||||||
const suite = builtinSuites.find((suite) => suite === suiteName);
|
const found = builtinSuites.find((suite) => suite === suiteName);
|
||||||
if (!suite) {
|
if (!found) {
|
||||||
throw new Error(getQueryUsesInvalid(configFile, suiteName));
|
throw new Error(getQueryUsesInvalid(configFile, suiteName));
|
||||||
}
|
}
|
||||||
const suites = languages.map((l) => `${l}-${suiteName}.qls`);
|
const suites = languages.map((l) => `${l}-${suiteName}.qls`);
|
||||||
|
|
@ -190,39 +190,39 @@ const filterPatternCharactersRegex = /.*[?+[\]!].*/;
|
||||||
// to make it valid, or if not possible then throws an error.
|
// to make it valid, or if not possible then throws an error.
|
||||||
function validateAndSanitisePath(originalPath, propertyName, configFile, logger) {
|
function validateAndSanitisePath(originalPath, propertyName, configFile, logger) {
|
||||||
// Take a copy so we don't modify the original path, so we can still construct error messages
|
// Take a copy so we don't modify the original path, so we can still construct error messages
|
||||||
let path = originalPath;
|
let newPath = originalPath;
|
||||||
// All paths are relative to the src root, so strip off leading slashes.
|
// All paths are relative to the src root, so strip off leading slashes.
|
||||||
while (path.charAt(0) === "/") {
|
while (newPath.charAt(0) === "/") {
|
||||||
path = path.substring(1);
|
newPath = newPath.substring(1);
|
||||||
}
|
}
|
||||||
// Trailing ** are redundant, so strip them off
|
// Trailing ** are redundant, so strip them off
|
||||||
if (path.endsWith("/**")) {
|
if (newPath.endsWith("/**")) {
|
||||||
path = path.substring(0, path.length - 2);
|
newPath = newPath.substring(0, newPath.length - 2);
|
||||||
}
|
}
|
||||||
// An empty path is not allowed as it's meaningless
|
// An empty path is not allowed as it's meaningless
|
||||||
if (path === "") {
|
if (newPath === "") {
|
||||||
throw new Error(getConfigFilePropertyError(configFile, propertyName, `"${originalPath}" is not an invalid path. ` +
|
throw new Error(getConfigFilePropertyError(configFile, propertyName, `"${originalPath}" is not an invalid path. ` +
|
||||||
`It is not necessary to include it, and it is not allowed to exclude it.`));
|
`It is not necessary to include it, and it is not allowed to exclude it.`));
|
||||||
}
|
}
|
||||||
// Check for illegal uses of **
|
// Check for illegal uses of **
|
||||||
if (path.match(pathStarsRegex)) {
|
if (newPath.match(pathStarsRegex)) {
|
||||||
throw new Error(getConfigFilePropertyError(configFile, propertyName, `"${originalPath}" contains an invalid "**" wildcard. ` +
|
throw new Error(getConfigFilePropertyError(configFile, propertyName, `"${originalPath}" contains an invalid "**" wildcard. ` +
|
||||||
`They must be immediately preceeded and followed by a slash as in "/**/", or come at the start or end.`));
|
`They must be immediately preceeded and followed by a slash as in "/**/", or come at the start or end.`));
|
||||||
}
|
}
|
||||||
// Check for other regex characters that we don't support.
|
// Check for other regex characters that we don't support.
|
||||||
// Output a warning so the user knows, but otherwise continue normally.
|
// Output a warning so the user knows, but otherwise continue normally.
|
||||||
if (path.match(filterPatternCharactersRegex)) {
|
if (newPath.match(filterPatternCharactersRegex)) {
|
||||||
logger.warning(getConfigFilePropertyError(configFile, propertyName, `"${originalPath}" contains an unsupported character. ` +
|
logger.warning(getConfigFilePropertyError(configFile, propertyName, `"${originalPath}" contains an unsupported character. ` +
|
||||||
`The filter pattern characters ?, +, [, ], ! are not supported and will be matched literally.`));
|
`The filter pattern characters ?, +, [, ], ! are not supported and will be matched literally.`));
|
||||||
}
|
}
|
||||||
// Ban any uses of backslash for now.
|
// Ban any uses of backslash for now.
|
||||||
// This may not play nicely with project layouts.
|
// This may not play nicely with project layouts.
|
||||||
// This restriction can be lifted later if we determine they are ok.
|
// This restriction can be lifted later if we determine they are ok.
|
||||||
if (path.indexOf("\\") !== -1) {
|
if (newPath.indexOf("\\") !== -1) {
|
||||||
throw new Error(getConfigFilePropertyError(configFile, propertyName, `"${originalPath}" contains an "\\" character. These are not allowed in filters. ` +
|
throw new Error(getConfigFilePropertyError(configFile, propertyName, `"${originalPath}" contains an "\\" character. These are not allowed in filters. ` +
|
||||||
`If running on windows we recommend using "/" instead for path filters.`));
|
`If running on windows we recommend using "/" instead for path filters.`));
|
||||||
}
|
}
|
||||||
return path;
|
return newPath;
|
||||||
}
|
}
|
||||||
exports.validateAndSanitisePath = validateAndSanitisePath;
|
exports.validateAndSanitisePath = validateAndSanitisePath;
|
||||||
// An undefined configFile in some of these functions indicates that
|
// An undefined configFile in some of these functions indicates that
|
||||||
|
|
@ -468,22 +468,22 @@ async function loadConfig(languagesInput, queriesInput, configFile, repository,
|
||||||
if (!(parsedYAML[PATHS_IGNORE_PROPERTY] instanceof Array)) {
|
if (!(parsedYAML[PATHS_IGNORE_PROPERTY] instanceof Array)) {
|
||||||
throw new Error(getPathsIgnoreInvalid(configFile));
|
throw new Error(getPathsIgnoreInvalid(configFile));
|
||||||
}
|
}
|
||||||
for (const path of parsedYAML[PATHS_IGNORE_PROPERTY]) {
|
for (const ignorePath of parsedYAML[PATHS_IGNORE_PROPERTY]) {
|
||||||
if (typeof path !== "string" || path === "") {
|
if (typeof ignorePath !== "string" || ignorePath === "") {
|
||||||
throw new Error(getPathsIgnoreInvalid(configFile));
|
throw new Error(getPathsIgnoreInvalid(configFile));
|
||||||
}
|
}
|
||||||
pathsIgnore.push(validateAndSanitisePath(path, PATHS_IGNORE_PROPERTY, configFile, logger));
|
pathsIgnore.push(validateAndSanitisePath(ignorePath, PATHS_IGNORE_PROPERTY, configFile, logger));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (PATHS_PROPERTY in parsedYAML) {
|
if (PATHS_PROPERTY in parsedYAML) {
|
||||||
if (!(parsedYAML[PATHS_PROPERTY] instanceof Array)) {
|
if (!(parsedYAML[PATHS_PROPERTY] instanceof Array)) {
|
||||||
throw new Error(getPathsInvalid(configFile));
|
throw new Error(getPathsInvalid(configFile));
|
||||||
}
|
}
|
||||||
for (const path of parsedYAML[PATHS_PROPERTY]) {
|
for (const includePath of parsedYAML[PATHS_PROPERTY]) {
|
||||||
if (typeof path !== "string" || path === "") {
|
if (typeof includePath !== "string" || includePath === "") {
|
||||||
throw new Error(getPathsInvalid(configFile));
|
throw new Error(getPathsInvalid(configFile));
|
||||||
}
|
}
|
||||||
paths.push(validateAndSanitisePath(path, PATHS_PROPERTY, configFile, logger));
|
paths.push(validateAndSanitisePath(includePath, PATHS_PROPERTY, configFile, logger));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The list of queries should not be empty for any language. If it is then
|
// The list of queries should not be empty for any language. If it is then
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
24
lib/config-utils.test.js
generated
24
lib/config-utils.test.js
generated
|
|
@ -285,7 +285,7 @@ ava_1.default("Queries from config file can be overridden in workflow file", asy
|
||||||
- uses: ./foo`;
|
- uses: ./foo`;
|
||||||
const configFilePath = createConfigFile(inputFileContents, tmpDir);
|
const configFilePath = createConfigFile(inputFileContents, tmpDir);
|
||||||
// This config item should take precedence over the config file but shouldn't affect the default queries.
|
// This config item should take precedence over the config file but shouldn't affect the default queries.
|
||||||
const queries = "./override";
|
const testQueries = "./override";
|
||||||
fs.mkdirSync(path.join(tmpDir, "foo"));
|
fs.mkdirSync(path.join(tmpDir, "foo"));
|
||||||
fs.mkdirSync(path.join(tmpDir, "override"));
|
fs.mkdirSync(path.join(tmpDir, "override"));
|
||||||
const resolveQueriesArgs = [];
|
const resolveQueriesArgs = [];
|
||||||
|
|
@ -296,7 +296,7 @@ ava_1.default("Queries from config file can be overridden in workflow file", asy
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const languages = "javascript";
|
const languages = "javascript";
|
||||||
const config = await configUtils.initConfig(languages, queries, configFilePath, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, "token", "https://github.example.com", "runner", logging_1.getRunnerLogger(true));
|
const config = await configUtils.initConfig(languages, testQueries, configFilePath, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, "token", "https://github.example.com", "runner", logging_1.getRunnerLogger(true));
|
||||||
// Check resolveQueries was called correctly
|
// Check resolveQueries was called correctly
|
||||||
// It'll be called once for the default queries and once for `./override`,
|
// It'll be called once for the default queries and once for `./override`,
|
||||||
// but won't be called for './foo' from the config file.
|
// but won't be called for './foo' from the config file.
|
||||||
|
|
@ -318,7 +318,7 @@ ava_1.default("Queries in workflow file can be used in tandem with the 'disable
|
||||||
name: my config
|
name: my config
|
||||||
disable-default-queries: true`;
|
disable-default-queries: true`;
|
||||||
const configFilePath = createConfigFile(inputFileContents, tmpDir);
|
const configFilePath = createConfigFile(inputFileContents, tmpDir);
|
||||||
const queries = "./workflow-query";
|
const testQueries = "./workflow-query";
|
||||||
fs.mkdirSync(path.join(tmpDir, "workflow-query"));
|
fs.mkdirSync(path.join(tmpDir, "workflow-query"));
|
||||||
const resolveQueriesArgs = [];
|
const resolveQueriesArgs = [];
|
||||||
const codeQL = codeql_1.setCodeQL({
|
const codeQL = codeql_1.setCodeQL({
|
||||||
|
|
@ -328,7 +328,7 @@ ava_1.default("Queries in workflow file can be used in tandem with the 'disable
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const languages = "javascript";
|
const languages = "javascript";
|
||||||
const config = await configUtils.initConfig(languages, queries, configFilePath, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, "token", "https://github.example.com", "runner", logging_1.getRunnerLogger(true));
|
const config = await configUtils.initConfig(languages, testQueries, configFilePath, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, "token", "https://github.example.com", "runner", logging_1.getRunnerLogger(true));
|
||||||
// Check resolveQueries was called correctly
|
// Check resolveQueries was called correctly
|
||||||
// It'll be called once for `./workflow-query`,
|
// It'll be called once for `./workflow-query`,
|
||||||
// but won't be called for the default one since that was disabled
|
// but won't be called for the default one since that was disabled
|
||||||
|
|
@ -345,7 +345,7 @@ ava_1.default("Multiple queries can be specified in workflow file, no config fil
|
||||||
return await util.withTmpDir(async (tmpDir) => {
|
return await util.withTmpDir(async (tmpDir) => {
|
||||||
fs.mkdirSync(path.join(tmpDir, "override1"));
|
fs.mkdirSync(path.join(tmpDir, "override1"));
|
||||||
fs.mkdirSync(path.join(tmpDir, "override2"));
|
fs.mkdirSync(path.join(tmpDir, "override2"));
|
||||||
const queries = "./override1,./override2";
|
const testQueries = "./override1,./override2";
|
||||||
const resolveQueriesArgs = [];
|
const resolveQueriesArgs = [];
|
||||||
const codeQL = codeql_1.setCodeQL({
|
const codeQL = codeql_1.setCodeQL({
|
||||||
async resolveQueries(queries, extraSearchPath) {
|
async resolveQueries(queries, extraSearchPath) {
|
||||||
|
|
@ -354,7 +354,7 @@ ava_1.default("Multiple queries can be specified in workflow file, no config fil
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const languages = "javascript";
|
const languages = "javascript";
|
||||||
const config = await configUtils.initConfig(languages, queries, undefined, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, "token", "https://github.example.com", "runner", logging_1.getRunnerLogger(true));
|
const config = await configUtils.initConfig(languages, testQueries, undefined, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, "token", "https://github.example.com", "runner", logging_1.getRunnerLogger(true));
|
||||||
// Check resolveQueries was called correctly:
|
// Check resolveQueries was called correctly:
|
||||||
// It'll be called once for the default queries,
|
// It'll be called once for the default queries,
|
||||||
// and then once for each of the two queries from the workflow
|
// and then once for each of the two queries from the workflow
|
||||||
|
|
@ -381,7 +381,7 @@ ava_1.default("Queries in workflow file can be added to the set of queries witho
|
||||||
- uses: ./foo`;
|
- uses: ./foo`;
|
||||||
const configFilePath = createConfigFile(inputFileContents, tmpDir);
|
const configFilePath = createConfigFile(inputFileContents, tmpDir);
|
||||||
// These queries shouldn't override anything, because the value is prefixed with "+"
|
// These queries shouldn't override anything, because the value is prefixed with "+"
|
||||||
const queries = "+./additional1,./additional2";
|
const testQueries = "+./additional1,./additional2";
|
||||||
fs.mkdirSync(path.join(tmpDir, "foo"));
|
fs.mkdirSync(path.join(tmpDir, "foo"));
|
||||||
fs.mkdirSync(path.join(tmpDir, "additional1"));
|
fs.mkdirSync(path.join(tmpDir, "additional1"));
|
||||||
fs.mkdirSync(path.join(tmpDir, "additional2"));
|
fs.mkdirSync(path.join(tmpDir, "additional2"));
|
||||||
|
|
@ -393,7 +393,7 @@ ava_1.default("Queries in workflow file can be added to the set of queries witho
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const languages = "javascript";
|
const languages = "javascript";
|
||||||
const config = await configUtils.initConfig(languages, queries, configFilePath, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, "token", "https://github.example.com", "runner", logging_1.getRunnerLogger(true));
|
const config = await configUtils.initConfig(languages, testQueries, configFilePath, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, "token", "https://github.example.com", "runner", logging_1.getRunnerLogger(true));
|
||||||
// Check resolveQueries was called correctly
|
// Check resolveQueries was called correctly
|
||||||
// It'll be called once for the default queries,
|
// It'll be called once for the default queries,
|
||||||
// once for each of additional1 and additional2,
|
// once for each of additional1 and additional2,
|
||||||
|
|
@ -604,11 +604,11 @@ ava_1.default("path validations", (t) => {
|
||||||
// Dummy values to pass to validateAndSanitisePath
|
// Dummy values to pass to validateAndSanitisePath
|
||||||
const propertyName = "paths";
|
const propertyName = "paths";
|
||||||
const configFile = "./.github/codeql/config.yml";
|
const configFile = "./.github/codeql/config.yml";
|
||||||
for (const path of validPaths) {
|
for (const validPath of validPaths) {
|
||||||
t.truthy(configUtils.validateAndSanitisePath(path, propertyName, configFile, logging_1.getRunnerLogger(true)));
|
t.truthy(configUtils.validateAndSanitisePath(validPath, propertyName, configFile, logging_1.getRunnerLogger(true)));
|
||||||
}
|
}
|
||||||
for (const path of invalidPaths) {
|
for (const invalidPath of invalidPaths) {
|
||||||
t.throws(() => configUtils.validateAndSanitisePath(path, propertyName, configFile, logging_1.getRunnerLogger(true)));
|
t.throws(() => configUtils.validateAndSanitisePath(invalidPath, propertyName, configFile, logging_1.getRunnerLogger(true)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ava_1.default("path sanitisation", (t) => {
|
ava_1.default("path sanitisation", (t) => {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
18
lib/fingerprints.js
generated
18
lib/fingerprints.js
generated
|
|
@ -46,7 +46,7 @@ function hash(callback, input) {
|
||||||
// Indexes match up with those from the window variable.
|
// Indexes match up with those from the window variable.
|
||||||
const lineNumbers = Array(BLOCK_SIZE).fill(-1);
|
const lineNumbers = Array(BLOCK_SIZE).fill(-1);
|
||||||
// The current hash value, updated as we read each character
|
// The current hash value, updated as we read each character
|
||||||
let hash = long_1.default.ZERO;
|
let hashRaw = long_1.default.ZERO;
|
||||||
const firstMod = computeFirstMod();
|
const firstMod = computeFirstMod();
|
||||||
// The current index in the window, will wrap around to zero when we reach BLOCK_SIZE
|
// The current index in the window, will wrap around to zero when we reach BLOCK_SIZE
|
||||||
let index = 0;
|
let index = 0;
|
||||||
|
|
@ -61,7 +61,7 @@ function hash(callback, input) {
|
||||||
const hashCounts = {};
|
const hashCounts = {};
|
||||||
// Output the current hash and line number to the callback function
|
// Output the current hash and line number to the callback function
|
||||||
const outputHash = function () {
|
const outputHash = function () {
|
||||||
const hashValue = hash.toUnsigned().toString(16);
|
const hashValue = hashRaw.toUnsigned().toString(16);
|
||||||
if (!hashCounts[hashValue]) {
|
if (!hashCounts[hashValue]) {
|
||||||
hashCounts[hashValue] = 0;
|
hashCounts[hashValue] = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -73,7 +73,7 @@ function hash(callback, input) {
|
||||||
const updateHash = function (current) {
|
const updateHash = function (current) {
|
||||||
const begin = window[index];
|
const begin = window[index];
|
||||||
window[index] = current;
|
window[index] = current;
|
||||||
hash = MOD.multiply(hash)
|
hashRaw = MOD.multiply(hashRaw)
|
||||||
.add(long_1.default.fromInt(current))
|
.add(long_1.default.fromInt(current))
|
||||||
.subtract(firstMod.multiply(long_1.default.fromInt(begin)));
|
.subtract(firstMod.multiply(long_1.default.fromInt(begin)));
|
||||||
index = (index + 1) % BLOCK_SIZE;
|
index = (index + 1) % BLOCK_SIZE;
|
||||||
|
|
@ -130,7 +130,7 @@ function locationUpdateCallback(result, location, logger) {
|
||||||
// using the hash of the first line of the file.
|
// using the hash of the first line of the file.
|
||||||
locationStartLine = 1;
|
locationStartLine = 1;
|
||||||
}
|
}
|
||||||
return function (lineNumber, hash) {
|
return function (lineNumber, hashValue) {
|
||||||
// Ignore hashes for lines that don't concern us
|
// Ignore hashes for lines that don't concern us
|
||||||
if (locationStartLine !== lineNumber) {
|
if (locationStartLine !== lineNumber) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -142,10 +142,10 @@ function locationUpdateCallback(result, location, logger) {
|
||||||
// If the hash doesn't match the existing fingerprint then
|
// If the hash doesn't match the existing fingerprint then
|
||||||
// output a warning and don't overwrite it.
|
// output a warning and don't overwrite it.
|
||||||
if (!existingFingerprint) {
|
if (!existingFingerprint) {
|
||||||
result.partialFingerprints.primaryLocationLineHash = hash;
|
result.partialFingerprints.primaryLocationLineHash = hashValue;
|
||||||
}
|
}
|
||||||
else if (existingFingerprint !== hash) {
|
else if (existingFingerprint !== hashValue) {
|
||||||
logger.warning(`Calculated fingerprint of ${hash} for file ${location.physicalLocation.artifactLocation.uri} line ${lineNumber}, but found existing inconsistent fingerprint value ${existingFingerprint}`);
|
logger.warning(`Calculated fingerprint of ${hashValue} for file ${location.physicalLocation.artifactLocation.uri} line ${lineNumber}, but found existing inconsistent fingerprint value ${existingFingerprint}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -231,9 +231,9 @@ function addFingerprints(sarifContents, checkoutPath, logger) {
|
||||||
// Now hash each file that was found
|
// Now hash each file that was found
|
||||||
for (const [filepath, callbacks] of Object.entries(callbacksByFile)) {
|
for (const [filepath, callbacks] of Object.entries(callbacksByFile)) {
|
||||||
// A callback that forwards the hash to all other callbacks for that file
|
// A callback that forwards the hash to all other callbacks for that file
|
||||||
const teeCallback = function (lineNumber, hash) {
|
const teeCallback = function (lineNumber, hashValue) {
|
||||||
for (const c of Object.values(callbacks)) {
|
for (const c of Object.values(callbacks)) {
|
||||||
c(lineNumber, hash);
|
c(lineNumber, hashValue);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const fileContents = fs.readFileSync(filepath).toString();
|
const fileContents = fs.readFileSync(filepath).toString();
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
4
lib/fingerprints.test.js
generated
4
lib/fingerprints.test.js
generated
|
|
@ -108,7 +108,9 @@ ava_1.default("hash", (t) => {
|
||||||
});
|
});
|
||||||
function testResolveUriToFile(uri, index, artifactsURIs) {
|
function testResolveUriToFile(uri, index, artifactsURIs) {
|
||||||
const location = { uri, index };
|
const location = { uri, index };
|
||||||
const artifacts = artifactsURIs.map((uri) => ({ location: { uri } }));
|
const artifacts = artifactsURIs.map((artifactURI) => ({
|
||||||
|
location: { uri: artifactURI },
|
||||||
|
}));
|
||||||
return fingerprints.resolveUriToFile(location, artifacts, process.cwd(), logging_1.getRunnerLogger(true));
|
return fingerprints.resolveUriToFile(location, artifacts, process.cwd(), logging_1.getRunnerLogger(true));
|
||||||
}
|
}
|
||||||
ava_1.default("resolveUriToFile", (t) => {
|
ava_1.default("resolveUriToFile", (t) => {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
4
lib/upload-lib.js
generated
4
lib/upload-lib.js
generated
|
|
@ -75,8 +75,8 @@ async function upload(sarifPath, repositoryNwo, commitOid, ref, analysisKey, ana
|
||||||
.readdirSync(sarifPath)
|
.readdirSync(sarifPath)
|
||||||
.filter((f) => f.endsWith(".sarif"))
|
.filter((f) => f.endsWith(".sarif"))
|
||||||
.map((f) => path.resolve(sarifPath, f));
|
.map((f) => path.resolve(sarifPath, f));
|
||||||
for (const path of paths) {
|
for (const filepath of paths) {
|
||||||
sarifFiles.push(path);
|
sarifFiles.push(filepath);
|
||||||
}
|
}
|
||||||
if (sarifFiles.length === 0) {
|
if (sarifFiles.length === 0) {
|
||||||
throw new Error(`No SARIF files found to upload in "${sarifPath}".`);
|
throw new Error(`No SARIF files found to upload in "${sarifPath}".`);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -34,7 +34,7 @@ export const getApiClient = function (
|
||||||
throw new Error("Invalid API call in local run");
|
throw new Error("Invalid API call in local run");
|
||||||
}
|
}
|
||||||
const customOctokit = githubUtils.GitHub.plugin(retry.retry, (octokit, _) => {
|
const customOctokit = githubUtils.GitHub.plugin(retry.retry, (octokit, _) => {
|
||||||
octokit.hook.after("request", (response: OctokitResponse<any>, _) => {
|
octokit.hook.after("request", (response: OctokitResponse<any>, __) => {
|
||||||
if (response.status < 400 && !possibleFailureExpected) {
|
if (response.status < 400 && !possibleFailureExpected) {
|
||||||
if (hasBeenWarnedAboutVersion) {
|
if (hasBeenWarnedAboutVersion) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -631,9 +631,36 @@ function getCodeQLForCmd(cmd: string): CodeQL {
|
||||||
/**
|
/**
|
||||||
* Gets the options for `path` of `options` as an array of extra option strings.
|
* Gets the options for `path` of `options` as an array of extra option strings.
|
||||||
*/
|
*/
|
||||||
function getExtraOptionsFromEnv(path: string[]) {
|
function getExtraOptionsFromEnv(paths: string[]) {
|
||||||
const options: ExtraOptions = util.getExtraOptionsEnvParam();
|
const options: ExtraOptions = util.getExtraOptionsEnvParam();
|
||||||
return getExtraOptions(options, path, []);
|
return getExtraOptions(options, paths, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets `options` as an array of extra option strings.
|
||||||
|
*
|
||||||
|
* - throws an exception mentioning `pathInfo` if this conversion is impossible.
|
||||||
|
*/
|
||||||
|
function asExtraOptions(options: any, pathInfo: string[]): string[] {
|
||||||
|
if (options === undefined) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
if (!Array.isArray(options)) {
|
||||||
|
const msg = `The extra options for '${pathInfo.join(
|
||||||
|
"."
|
||||||
|
)}' ('${JSON.stringify(options)}') are not in an array.`;
|
||||||
|
throw new Error(msg);
|
||||||
|
}
|
||||||
|
return options.map((o) => {
|
||||||
|
const t = typeof o;
|
||||||
|
if (t !== "string" && t !== "number" && t !== "boolean") {
|
||||||
|
const msg = `The extra option for '${pathInfo.join(
|
||||||
|
"."
|
||||||
|
)}' ('${JSON.stringify(o)}') is not a primitive value.`;
|
||||||
|
throw new Error(msg);
|
||||||
|
}
|
||||||
|
return `${o}`;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -646,43 +673,17 @@ function getExtraOptionsFromEnv(path: string[]) {
|
||||||
*/
|
*/
|
||||||
export function getExtraOptions(
|
export function getExtraOptions(
|
||||||
options: any,
|
options: any,
|
||||||
path: string[],
|
paths: string[],
|
||||||
pathInfo: string[]
|
pathInfo: string[]
|
||||||
): string[] {
|
): string[] {
|
||||||
/**
|
|
||||||
* Gets `options` as an array of extra option strings.
|
|
||||||
*
|
|
||||||
* - throws an exception mentioning `pathInfo` if this conversion is impossible.
|
|
||||||
*/
|
|
||||||
function asExtraOptions(options: any, pathInfo: string[]): string[] {
|
|
||||||
if (options === undefined) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
if (!Array.isArray(options)) {
|
|
||||||
const msg = `The extra options for '${pathInfo.join(
|
|
||||||
"."
|
|
||||||
)}' ('${JSON.stringify(options)}') are not in an array.`;
|
|
||||||
throw new Error(msg);
|
|
||||||
}
|
|
||||||
return options.map((o) => {
|
|
||||||
const t = typeof o;
|
|
||||||
if (t !== "string" && t !== "number" && t !== "boolean") {
|
|
||||||
const msg = `The extra option for '${pathInfo.join(
|
|
||||||
"."
|
|
||||||
)}' ('${JSON.stringify(o)}') is not a primitive value.`;
|
|
||||||
throw new Error(msg);
|
|
||||||
}
|
|
||||||
return `${o}`;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const all = asExtraOptions(options?.["*"], pathInfo.concat("*"));
|
const all = asExtraOptions(options?.["*"], pathInfo.concat("*"));
|
||||||
const specific =
|
const specific =
|
||||||
path.length === 0
|
paths.length === 0
|
||||||
? asExtraOptions(options, pathInfo)
|
? asExtraOptions(options, pathInfo)
|
||||||
: getExtraOptions(
|
: getExtraOptions(
|
||||||
options?.[path[0]],
|
options?.[paths[0]],
|
||||||
path?.slice(1),
|
paths?.slice(1),
|
||||||
pathInfo.concat(path[0])
|
pathInfo.concat(paths[0])
|
||||||
);
|
);
|
||||||
return all.concat(specific);
|
return all.concat(specific);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -477,7 +477,7 @@ test("Queries from config file can be overridden in workflow file", async (t) =>
|
||||||
const configFilePath = createConfigFile(inputFileContents, tmpDir);
|
const configFilePath = createConfigFile(inputFileContents, tmpDir);
|
||||||
|
|
||||||
// This config item should take precedence over the config file but shouldn't affect the default queries.
|
// This config item should take precedence over the config file but shouldn't affect the default queries.
|
||||||
const queries = "./override";
|
const testQueries = "./override";
|
||||||
|
|
||||||
fs.mkdirSync(path.join(tmpDir, "foo"));
|
fs.mkdirSync(path.join(tmpDir, "foo"));
|
||||||
fs.mkdirSync(path.join(tmpDir, "override"));
|
fs.mkdirSync(path.join(tmpDir, "override"));
|
||||||
|
|
@ -500,7 +500,7 @@ test("Queries from config file can be overridden in workflow file", async (t) =>
|
||||||
|
|
||||||
const config = await configUtils.initConfig(
|
const config = await configUtils.initConfig(
|
||||||
languages,
|
languages,
|
||||||
queries,
|
testQueries,
|
||||||
configFilePath,
|
configFilePath,
|
||||||
{ owner: "github", repo: "example " },
|
{ owner: "github", repo: "example " },
|
||||||
tmpDir,
|
tmpDir,
|
||||||
|
|
@ -541,7 +541,7 @@ test("Queries in workflow file can be used in tandem with the 'disable default q
|
||||||
disable-default-queries: true`;
|
disable-default-queries: true`;
|
||||||
const configFilePath = createConfigFile(inputFileContents, tmpDir);
|
const configFilePath = createConfigFile(inputFileContents, tmpDir);
|
||||||
|
|
||||||
const queries = "./workflow-query";
|
const testQueries = "./workflow-query";
|
||||||
fs.mkdirSync(path.join(tmpDir, "workflow-query"));
|
fs.mkdirSync(path.join(tmpDir, "workflow-query"));
|
||||||
|
|
||||||
const resolveQueriesArgs: Array<{
|
const resolveQueriesArgs: Array<{
|
||||||
|
|
@ -562,7 +562,7 @@ test("Queries in workflow file can be used in tandem with the 'disable default q
|
||||||
|
|
||||||
const config = await configUtils.initConfig(
|
const config = await configUtils.initConfig(
|
||||||
languages,
|
languages,
|
||||||
queries,
|
testQueries,
|
||||||
configFilePath,
|
configFilePath,
|
||||||
{ owner: "github", repo: "example " },
|
{ owner: "github", repo: "example " },
|
||||||
tmpDir,
|
tmpDir,
|
||||||
|
|
@ -594,7 +594,7 @@ test("Multiple queries can be specified in workflow file, no config file require
|
||||||
fs.mkdirSync(path.join(tmpDir, "override1"));
|
fs.mkdirSync(path.join(tmpDir, "override1"));
|
||||||
fs.mkdirSync(path.join(tmpDir, "override2"));
|
fs.mkdirSync(path.join(tmpDir, "override2"));
|
||||||
|
|
||||||
const queries = "./override1,./override2";
|
const testQueries = "./override1,./override2";
|
||||||
|
|
||||||
const resolveQueriesArgs: Array<{
|
const resolveQueriesArgs: Array<{
|
||||||
queries: string[];
|
queries: string[];
|
||||||
|
|
@ -614,7 +614,7 @@ test("Multiple queries can be specified in workflow file, no config file require
|
||||||
|
|
||||||
const config = await configUtils.initConfig(
|
const config = await configUtils.initConfig(
|
||||||
languages,
|
languages,
|
||||||
queries,
|
testQueries,
|
||||||
undefined,
|
undefined,
|
||||||
{ owner: "github", repo: "example " },
|
{ owner: "github", repo: "example " },
|
||||||
tmpDir,
|
tmpDir,
|
||||||
|
|
@ -660,7 +660,7 @@ test("Queries in workflow file can be added to the set of queries without overri
|
||||||
const configFilePath = createConfigFile(inputFileContents, tmpDir);
|
const configFilePath = createConfigFile(inputFileContents, tmpDir);
|
||||||
|
|
||||||
// These queries shouldn't override anything, because the value is prefixed with "+"
|
// These queries shouldn't override anything, because the value is prefixed with "+"
|
||||||
const queries = "+./additional1,./additional2";
|
const testQueries = "+./additional1,./additional2";
|
||||||
|
|
||||||
fs.mkdirSync(path.join(tmpDir, "foo"));
|
fs.mkdirSync(path.join(tmpDir, "foo"));
|
||||||
fs.mkdirSync(path.join(tmpDir, "additional1"));
|
fs.mkdirSync(path.join(tmpDir, "additional1"));
|
||||||
|
|
@ -684,7 +684,7 @@ test("Queries in workflow file can be added to the set of queries without overri
|
||||||
|
|
||||||
const config = await configUtils.initConfig(
|
const config = await configUtils.initConfig(
|
||||||
languages,
|
languages,
|
||||||
queries,
|
testQueries,
|
||||||
configFilePath,
|
configFilePath,
|
||||||
{ owner: "github", repo: "example " },
|
{ owner: "github", repo: "example " },
|
||||||
tmpDir,
|
tmpDir,
|
||||||
|
|
@ -1090,20 +1090,20 @@ test("path validations", (t) => {
|
||||||
const propertyName = "paths";
|
const propertyName = "paths";
|
||||||
const configFile = "./.github/codeql/config.yml";
|
const configFile = "./.github/codeql/config.yml";
|
||||||
|
|
||||||
for (const path of validPaths) {
|
for (const validPath of validPaths) {
|
||||||
t.truthy(
|
t.truthy(
|
||||||
configUtils.validateAndSanitisePath(
|
configUtils.validateAndSanitisePath(
|
||||||
path,
|
validPath,
|
||||||
propertyName,
|
propertyName,
|
||||||
configFile,
|
configFile,
|
||||||
getRunnerLogger(true)
|
getRunnerLogger(true)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for (const path of invalidPaths) {
|
for (const invalidPath of invalidPaths) {
|
||||||
t.throws(() =>
|
t.throws(() =>
|
||||||
configUtils.validateAndSanitisePath(
|
configUtils.validateAndSanitisePath(
|
||||||
path,
|
invalidPath,
|
||||||
propertyName,
|
propertyName,
|
||||||
configFile,
|
configFile,
|
||||||
getRunnerLogger(true)
|
getRunnerLogger(true)
|
||||||
|
|
|
||||||
|
|
@ -216,8 +216,8 @@ async function addBuiltinSuiteQueries(
|
||||||
suiteName: string,
|
suiteName: string,
|
||||||
configFile?: string
|
configFile?: string
|
||||||
) {
|
) {
|
||||||
const suite = builtinSuites.find((suite) => suite === suiteName);
|
const found = builtinSuites.find((suite) => suite === suiteName);
|
||||||
if (!suite) {
|
if (!found) {
|
||||||
throw new Error(getQueryUsesInvalid(configFile, suiteName));
|
throw new Error(getQueryUsesInvalid(configFile, suiteName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -388,20 +388,20 @@ export function validateAndSanitisePath(
|
||||||
logger: Logger
|
logger: Logger
|
||||||
): string {
|
): string {
|
||||||
// Take a copy so we don't modify the original path, so we can still construct error messages
|
// Take a copy so we don't modify the original path, so we can still construct error messages
|
||||||
let path = originalPath;
|
let newPath = originalPath;
|
||||||
|
|
||||||
// All paths are relative to the src root, so strip off leading slashes.
|
// All paths are relative to the src root, so strip off leading slashes.
|
||||||
while (path.charAt(0) === "/") {
|
while (newPath.charAt(0) === "/") {
|
||||||
path = path.substring(1);
|
newPath = newPath.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trailing ** are redundant, so strip them off
|
// Trailing ** are redundant, so strip them off
|
||||||
if (path.endsWith("/**")) {
|
if (newPath.endsWith("/**")) {
|
||||||
path = path.substring(0, path.length - 2);
|
newPath = newPath.substring(0, newPath.length - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// An empty path is not allowed as it's meaningless
|
// An empty path is not allowed as it's meaningless
|
||||||
if (path === "") {
|
if (newPath === "") {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
getConfigFilePropertyError(
|
getConfigFilePropertyError(
|
||||||
configFile,
|
configFile,
|
||||||
|
|
@ -413,7 +413,7 @@ export function validateAndSanitisePath(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for illegal uses of **
|
// Check for illegal uses of **
|
||||||
if (path.match(pathStarsRegex)) {
|
if (newPath.match(pathStarsRegex)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
getConfigFilePropertyError(
|
getConfigFilePropertyError(
|
||||||
configFile,
|
configFile,
|
||||||
|
|
@ -426,7 +426,7 @@ export function validateAndSanitisePath(
|
||||||
|
|
||||||
// Check for other regex characters that we don't support.
|
// Check for other regex characters that we don't support.
|
||||||
// Output a warning so the user knows, but otherwise continue normally.
|
// Output a warning so the user knows, but otherwise continue normally.
|
||||||
if (path.match(filterPatternCharactersRegex)) {
|
if (newPath.match(filterPatternCharactersRegex)) {
|
||||||
logger.warning(
|
logger.warning(
|
||||||
getConfigFilePropertyError(
|
getConfigFilePropertyError(
|
||||||
configFile,
|
configFile,
|
||||||
|
|
@ -440,7 +440,7 @@ export function validateAndSanitisePath(
|
||||||
// Ban any uses of backslash for now.
|
// Ban any uses of backslash for now.
|
||||||
// This may not play nicely with project layouts.
|
// This may not play nicely with project layouts.
|
||||||
// This restriction can be lifted later if we determine they are ok.
|
// This restriction can be lifted later if we determine they are ok.
|
||||||
if (path.indexOf("\\") !== -1) {
|
if (newPath.indexOf("\\") !== -1) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
getConfigFilePropertyError(
|
getConfigFilePropertyError(
|
||||||
configFile,
|
configFile,
|
||||||
|
|
@ -451,7 +451,7 @@ export function validateAndSanitisePath(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return newPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// An undefined configFile in some of these functions indicates that
|
// An undefined configFile in some of these functions indicates that
|
||||||
|
|
@ -890,12 +890,17 @@ async function loadConfig(
|
||||||
if (!(parsedYAML[PATHS_IGNORE_PROPERTY] instanceof Array)) {
|
if (!(parsedYAML[PATHS_IGNORE_PROPERTY] instanceof Array)) {
|
||||||
throw new Error(getPathsIgnoreInvalid(configFile));
|
throw new Error(getPathsIgnoreInvalid(configFile));
|
||||||
}
|
}
|
||||||
for (const path of parsedYAML[PATHS_IGNORE_PROPERTY]!) {
|
for (const ignorePath of parsedYAML[PATHS_IGNORE_PROPERTY]!) {
|
||||||
if (typeof path !== "string" || path === "") {
|
if (typeof ignorePath !== "string" || ignorePath === "") {
|
||||||
throw new Error(getPathsIgnoreInvalid(configFile));
|
throw new Error(getPathsIgnoreInvalid(configFile));
|
||||||
}
|
}
|
||||||
pathsIgnore.push(
|
pathsIgnore.push(
|
||||||
validateAndSanitisePath(path, PATHS_IGNORE_PROPERTY, configFile, logger)
|
validateAndSanitisePath(
|
||||||
|
ignorePath,
|
||||||
|
PATHS_IGNORE_PROPERTY,
|
||||||
|
configFile,
|
||||||
|
logger
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -904,12 +909,12 @@ async function loadConfig(
|
||||||
if (!(parsedYAML[PATHS_PROPERTY] instanceof Array)) {
|
if (!(parsedYAML[PATHS_PROPERTY] instanceof Array)) {
|
||||||
throw new Error(getPathsInvalid(configFile));
|
throw new Error(getPathsInvalid(configFile));
|
||||||
}
|
}
|
||||||
for (const path of parsedYAML[PATHS_PROPERTY]!) {
|
for (const includePath of parsedYAML[PATHS_PROPERTY]!) {
|
||||||
if (typeof path !== "string" || path === "") {
|
if (typeof includePath !== "string" || includePath === "") {
|
||||||
throw new Error(getPathsInvalid(configFile));
|
throw new Error(getPathsInvalid(configFile));
|
||||||
}
|
}
|
||||||
paths.push(
|
paths.push(
|
||||||
validateAndSanitisePath(path, PATHS_PROPERTY, configFile, logger)
|
validateAndSanitisePath(includePath, PATHS_PROPERTY, configFile, logger)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,9 @@ test("hash", (t: ava.Assertions) => {
|
||||||
|
|
||||||
function testResolveUriToFile(uri: any, index: any, artifactsURIs: any[]) {
|
function testResolveUriToFile(uri: any, index: any, artifactsURIs: any[]) {
|
||||||
const location = { uri, index };
|
const location = { uri, index };
|
||||||
const artifacts = artifactsURIs.map((uri) => ({ location: { uri } }));
|
const artifacts = artifactsURIs.map((artifactURI) => ({
|
||||||
|
location: { uri: artifactURI },
|
||||||
|
}));
|
||||||
return fingerprints.resolveUriToFile(
|
return fingerprints.resolveUriToFile(
|
||||||
location,
|
location,
|
||||||
artifacts,
|
artifacts,
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ export function hash(callback: hashCallback, input: string) {
|
||||||
const lineNumbers = Array(BLOCK_SIZE).fill(-1);
|
const lineNumbers = Array(BLOCK_SIZE).fill(-1);
|
||||||
|
|
||||||
// The current hash value, updated as we read each character
|
// The current hash value, updated as we read each character
|
||||||
let hash = Long.ZERO;
|
let hashRaw = Long.ZERO;
|
||||||
const firstMod = computeFirstMod();
|
const firstMod = computeFirstMod();
|
||||||
|
|
||||||
// The current index in the window, will wrap around to zero when we reach BLOCK_SIZE
|
// The current index in the window, will wrap around to zero when we reach BLOCK_SIZE
|
||||||
|
|
@ -63,7 +63,7 @@ export function hash(callback: hashCallback, input: string) {
|
||||||
|
|
||||||
// Output the current hash and line number to the callback function
|
// Output the current hash and line number to the callback function
|
||||||
const outputHash = function () {
|
const outputHash = function () {
|
||||||
const hashValue = hash.toUnsigned().toString(16);
|
const hashValue = hashRaw.toUnsigned().toString(16);
|
||||||
if (!hashCounts[hashValue]) {
|
if (!hashCounts[hashValue]) {
|
||||||
hashCounts[hashValue] = 0;
|
hashCounts[hashValue] = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -76,7 +76,7 @@ export function hash(callback: hashCallback, input: string) {
|
||||||
const updateHash = function (current: number) {
|
const updateHash = function (current: number) {
|
||||||
const begin = window[index];
|
const begin = window[index];
|
||||||
window[index] = current;
|
window[index] = current;
|
||||||
hash = MOD.multiply(hash)
|
hashRaw = MOD.multiply(hashRaw)
|
||||||
.add(Long.fromInt(current))
|
.add(Long.fromInt(current))
|
||||||
.subtract(firstMod.multiply(Long.fromInt(begin)));
|
.subtract(firstMod.multiply(Long.fromInt(begin)));
|
||||||
|
|
||||||
|
|
@ -138,7 +138,7 @@ function locationUpdateCallback(
|
||||||
// using the hash of the first line of the file.
|
// using the hash of the first line of the file.
|
||||||
locationStartLine = 1;
|
locationStartLine = 1;
|
||||||
}
|
}
|
||||||
return function (lineNumber: number, hash: string) {
|
return function (lineNumber: number, hashValue: string) {
|
||||||
// Ignore hashes for lines that don't concern us
|
// Ignore hashes for lines that don't concern us
|
||||||
if (locationStartLine !== lineNumber) {
|
if (locationStartLine !== lineNumber) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -153,10 +153,10 @@ function locationUpdateCallback(
|
||||||
// If the hash doesn't match the existing fingerprint then
|
// If the hash doesn't match the existing fingerprint then
|
||||||
// output a warning and don't overwrite it.
|
// output a warning and don't overwrite it.
|
||||||
if (!existingFingerprint) {
|
if (!existingFingerprint) {
|
||||||
result.partialFingerprints.primaryLocationLineHash = hash;
|
result.partialFingerprints.primaryLocationLineHash = hashValue;
|
||||||
} else if (existingFingerprint !== hash) {
|
} else if (existingFingerprint !== hashValue) {
|
||||||
logger.warning(
|
logger.warning(
|
||||||
`Calculated fingerprint of ${hash} for file ${location.physicalLocation.artifactLocation.uri} line ${lineNumber}, but found existing inconsistent fingerprint value ${existingFingerprint}`
|
`Calculated fingerprint of ${hashValue} for file ${location.physicalLocation.artifactLocation.uri} line ${lineNumber}, but found existing inconsistent fingerprint value ${existingFingerprint}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -279,9 +279,9 @@ export function addFingerprints(
|
||||||
// Now hash each file that was found
|
// Now hash each file that was found
|
||||||
for (const [filepath, callbacks] of Object.entries(callbacksByFile)) {
|
for (const [filepath, callbacks] of Object.entries(callbacksByFile)) {
|
||||||
// A callback that forwards the hash to all other callbacks for that file
|
// A callback that forwards the hash to all other callbacks for that file
|
||||||
const teeCallback = function (lineNumber: number, hash: string) {
|
const teeCallback = function (lineNumber: number, hashValue: string) {
|
||||||
for (const c of Object.values(callbacks)) {
|
for (const c of Object.values(callbacks)) {
|
||||||
c(lineNumber, hash);
|
c(lineNumber, hashValue);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const fileContents = fs.readFileSync(filepath).toString();
|
const fileContents = fs.readFileSync(filepath).toString();
|
||||||
|
|
|
||||||
|
|
@ -108,8 +108,8 @@ export async function upload(
|
||||||
.readdirSync(sarifPath)
|
.readdirSync(sarifPath)
|
||||||
.filter((f) => f.endsWith(".sarif"))
|
.filter((f) => f.endsWith(".sarif"))
|
||||||
.map((f) => path.resolve(sarifPath, f));
|
.map((f) => path.resolve(sarifPath, f));
|
||||||
for (const path of paths) {
|
for (const filepath of paths) {
|
||||||
sarifFiles.push(path);
|
sarifFiles.push(filepath);
|
||||||
}
|
}
|
||||||
if (sarifFiles.length === 0) {
|
if (sarifFiles.length === 0) {
|
||||||
throw new Error(`No SARIF files found to upload in "${sarifPath}".`);
|
throw new Error(`No SARIF files found to upload in "${sarifPath}".`);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue