Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Resolve violations of github/array-foreach lint
Resolves #199
Michael Huynh committed Sep 20, 2020

Unverified

No user is associated with the committer email.
1 parent b2dfa6e commit 4666a0e
Showing 19 changed files with 52 additions and 37 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
@@ -46,7 +46,6 @@
"@typescript-eslint/restrict-template-expressions": "off",
"eslint-comments/no-use": "off",
"func-style": "off",
"github/array-foreach": "off",
"github/no-then": "off",
"import/no-extraneous-dependencies": "off",
"no-shadow": "off",
8 changes: 4 additions & 4 deletions lib/config-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/config-utils.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.test.js.map

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions lib/fingerprints.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/fingerprints.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/init-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init-action.js.map
4 changes: 3 additions & 1 deletion lib/runner.js
2 changes: 1 addition & 1 deletion lib/runner.js.map

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions lib/upload-lib.js
2 changes: 1 addition & 1 deletion lib/upload-lib.js.map
4 changes: 2 additions & 2 deletions src/config-utils.test.ts
@@ -386,9 +386,9 @@ test("Default queries are used", async (t) => {
*/
function queriesToResolvedQueryForm(queries: string[]) {
const dummyResolvedQueries = {};
queries.forEach((q) => {
for (const q of queries) {
dummyResolvedQueries[q] = {};
});
}
return {
byLanguage: {
javascript: dummyResolvedQueries,
8 changes: 4 additions & 4 deletions src/config-utils.ts
@@ -875,28 +875,28 @@ async function loadConfig(
if (!(parsedYAML[PATHS_IGNORE_PROPERTY] instanceof Array)) {
throw new Error(getPathsIgnoreInvalid(configFile));
}
parsedYAML[PATHS_IGNORE_PROPERTY]!.forEach((path) => {
for (const path of parsedYAML[PATHS_IGNORE_PROPERTY]!) {
if (typeof path !== "string" || path === "") {
throw new Error(getPathsIgnoreInvalid(configFile));
}
pathsIgnore.push(
validateAndSanitisePath(path, PATHS_IGNORE_PROPERTY, configFile, logger)
);
});
}
}

if (PATHS_PROPERTY in parsedYAML) {
if (!(parsedYAML[PATHS_PROPERTY] instanceof Array)) {
throw new Error(getPathsInvalid(configFile));
}
parsedYAML[PATHS_PROPERTY]!.forEach((path) => {
for (const path of parsedYAML[PATHS_PROPERTY]!) {
if (typeof path !== "string" || path === "") {
throw new Error(getPathsInvalid(configFile));
}
paths.push(
validateAndSanitisePath(path, PATHS_PROPERTY, configFile, logger)
);
});
}
}

// The list of queries should not be empty for any language. If it is then
8 changes: 5 additions & 3 deletions src/fingerprints.ts
@@ -276,14 +276,16 @@ export function addFingerprints(
}

// Now hash each file that was found
Object.entries(callbacksByFile).forEach(([filepath, callbacks]) => {
for (const [filepath, callbacks] of Object.entries(callbacksByFile)) {
// A callback that forwards the hash to all other callbacks for that file
const teeCallback = function (lineNumber: number, hash: string) {
Object.values(callbacks).forEach((c) => c(lineNumber, hash));
for (const c of Object.values(callbacks)) {
c(lineNumber, hash);
}
};
const fileContents = fs.readFileSync(filepath).toString();
hash(teeCallback, fileContents);
});
}

return JSON.stringify(sarif);
}
6 changes: 3 additions & 3 deletions src/init-action.ts
@@ -141,9 +141,9 @@ async function run() {

const tracerConfig = await runInit(codeql, config);
if (tracerConfig !== undefined) {
Object.entries(tracerConfig.env).forEach(([key, value]) =>
core.exportVariable(key, value)
);
for (const [key, value] of Object.entries(tracerConfig.env)) {
core.exportVariable(key, value);
}

if (process.platform === "win32") {
await injectWindowsTracer(
4 changes: 3 additions & 1 deletion src/runner.ts
@@ -61,7 +61,9 @@ function importTracerEnvironment(config: Config) {
if (!("ODASA_TRACER_CONFIGURATION" in process.env)) {
const jsonEnvFile = path.join(config.tempDir, codeqlEnvJsonFilename);
const env = JSON.parse(fs.readFileSync(jsonEnvFile).toString("utf-8"));
Object.keys(env).forEach((key) => (process.env[key] = env[key]));
for (const key of Object.keys(env)) {
process.env[key] = env[key];
}
}
}

9 changes: 6 additions & 3 deletions src/upload-lib.ts
@@ -153,10 +153,13 @@ export async function upload(
throw new Error(`Path does not exist: ${sarifPath}`);
}
if (fs.lstatSync(sarifPath).isDirectory()) {
fs.readdirSync(sarifPath)
const paths = fs
.readdirSync(sarifPath)
.filter((f) => f.endsWith(".sarif"))
.map((f) => path.resolve(sarifPath, f))
.forEach((f) => sarifFiles.push(f));
.map((f) => path.resolve(sarifPath, f));
for (const path of paths) {
sarifFiles.push(path);
}
if (sarifFiles.length === 0) {
throw new Error(`No SARIF files found to upload in "${sarifPath}".`);
}

0 comments on commit 4666a0e

Please sign in to comment.