Skip to content
This repository was archived by the owner on Jun 16, 2022. It is now read-only.

Commit 2cadeaf

Browse files
authored
More lint
1 parent 4475c08 commit 2cadeaf

File tree

3 files changed

+69
-69
lines changed

3 files changed

+69
-69
lines changed

src/go_mod_parser.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
import {
22
Entry,
3-
ParsedDependencies,
4-
} from "@github/dependency-submission-toolkit/dist/processor";
3+
ParsedDependencies
4+
} from '@github/dependency-submission-toolkit/dist/processor'
55

6-
export function parseDependents(contents: string) {
7-
const stdoutArr: string[] = contents.split("\n");
6+
export function parseDependents (contents: string) {
7+
const stdoutArr: string[] = contents.split('\n')
88
const splitStdoutArr: string[][] = stdoutArr.map(function (line) {
9-
return line.split(" ");
10-
});
9+
return line.split(' ')
10+
})
1111

12-
const entries: ParsedDependencies = {};
13-
const repoName = splitStdoutArr[0][0];
12+
const entries: ParsedDependencies = {}
13+
const repoName = splitStdoutArr[0][0]
1414
splitStdoutArr.forEach((line: string[]) => {
15-
if (line === undefined || line.length < 2) return; // skip empty lines
15+
if (line === undefined || line.length < 2) return // skip empty lines
1616

17-
let targetEntry: Entry;
18-
const targetPkg = `pkg:golang/${line[0]}`;
19-
let dependencyEntry: Entry;
20-
const dependencyPkg = `pkg:golang/${line[1]}`;
17+
let targetEntry: Entry
18+
const targetPkg = `pkg:golang/${line[0]}`
19+
let dependencyEntry: Entry
20+
const dependencyPkg = `pkg:golang/${line[1]}`
2121

22-
const matchFound = line[0].match(repoName);
22+
const matchFound = line[0].match(repoName)
2323
if (matchFound && matchFound.index != null) {
24-
entries[dependencyPkg] = new Entry(dependencyPkg, "direct");
25-
return;
24+
entries[dependencyPkg] = new Entry(dependencyPkg, 'direct')
25+
return
2626
}
2727

2828
if (targetPkg in entries) {
29-
targetEntry = entries[targetPkg];
29+
targetEntry = entries[targetPkg]
3030
} else {
31-
targetEntry = new Entry(targetPkg, "indirect");
32-
entries[targetPkg] = targetEntry;
31+
targetEntry = new Entry(targetPkg, 'indirect')
32+
entries[targetPkg] = targetEntry
3333
}
3434

3535
if (dependencyPkg in entries) {
36-
dependencyEntry = entries[dependencyPkg];
36+
dependencyEntry = entries[dependencyPkg]
3737
} else {
38-
dependencyEntry = new Entry(dependencyPkg, "indirect");
39-
entries[dependencyPkg] = dependencyEntry;
38+
dependencyEntry = new Entry(dependencyPkg, 'indirect')
39+
entries[dependencyPkg] = dependencyEntry
4040
}
4141

42-
targetEntry.addDependency(dependencyEntry);
43-
});
44-
return entries;
42+
targetEntry.addDependency(dependencyEntry)
43+
})
44+
return entries
4545
}

src/index.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
1-
import * as core from "@actions/core";
2-
import { run } from "@github/dependency-submission-toolkit";
3-
import { ProcessDependenciesContent } from "@github/dependency-submission-toolkit/dist/processor";
4-
import { parseDependents } from "./go_mod_parser";
5-
import * as path from "path";
6-
import * as process from "process";
7-
import execa from "execa";
1+
import * as core from '@actions/core'
2+
import { run } from '@github/dependency-submission-toolkit'
3+
import { ProcessDependenciesContent } from '@github/dependency-submission-toolkit/dist/processor'
4+
import { parseDependents } from './go_mod_parser'
5+
import * as path from 'path'
6+
import * as process from 'process'
7+
import execa from 'execa'
88

9-
const parseDependentsFunc: ProcessDependenciesContent = parseDependents;
9+
const parseDependentsFunc: ProcessDependenciesContent = parseDependents
1010

1111
// Set the detector information provided from the action workflow input
1212
const detector = {
13-
name: core.getInput("detector-name"),
14-
url: core.getInput("detector-url"),
15-
version: core.getInput("detector-version"),
16-
};
13+
name: core.getInput('detector-name'),
14+
url: core.getInput('detector-url'),
15+
version: core.getInput('detector-version')
16+
}
1717

18-
async function searchForFile(filename: string) {
19-
console.log(`searching for ${filename} in ${process.cwd()}`);
18+
async function searchForFile (filename: string) {
19+
console.log(`searching for ${filename} in ${process.cwd()}`)
2020

21-
const { stdout } = await execa("find", [process.cwd(), "-name", filename]);
21+
const { stdout } = await execa('find', [process.cwd(), '-name', filename])
2222

2323
const dirs = stdout
24-
.split("\n")
24+
.split('\n')
2525
.filter((s) => s.length > 0)
2626
// remove the file name
2727
.map((filename) => path.dirname(filename))
2828
// map to absolute path
29-
.map((pathname) => path.resolve(process.cwd(), pathname));
29+
.map((pathname) => path.resolve(process.cwd(), pathname))
3030

31-
return dirs;
31+
return dirs
3232
}
3333

3434
// Enumerate directories
35-
async function detect() {
36-
const goModPaths = await searchForFile("go.mod");
35+
async function detect () {
36+
const goModPaths = await searchForFile('go.mod')
3737

3838
// If provided, set the metadata provided from the action workflow input
39-
const metadataInput = core.getInput("metadata");
39+
const metadataInput = core.getInput('metadata')
4040

4141
goModPaths.forEach((path) => {
42-
process.chdir(path);
43-
console.log(`Running go mod graph in ${path}`);
42+
process.chdir(path)
43+
console.log(`Running go mod graph in ${path}`)
4444
if (metadataInput.length < 1) {
45-
run(parseDependentsFunc, { command: "go mod graph" }, { detector });
45+
run(parseDependentsFunc, { command: 'go mod graph' }, { detector })
4646
} else {
47-
const metadata = JSON.parse(metadataInput);
47+
const metadata = JSON.parse(metadataInput)
4848
run(
4949
parseDependentsFunc,
50-
{ command: "go mod graph" },
50+
{ command: 'go mod graph' },
5151
{ metadata, detector }
52-
);
52+
)
5353
}
54-
});
54+
})
5555
}
5656

57-
detect();
57+
detect()

test/go_mod_parser.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { describe, expect, test } from "@jest/globals";
2-
import { parseDependents } from "../src/go_mod_parser";
1+
import { describe, expect, test } from '@jest/globals'
2+
import { parseDependents } from '../src/go_mod_parser'
33

44
/*
55
Expected dependency tree:
@@ -22,26 +22,26 @@ github.com/jaffee/[email protected] github.com/spf13/[email protected]
2222
github.com/jaffee/[email protected] github.com/spf13/[email protected]
2323
github.com/spf13/[email protected] github.com/armon/[email protected]
2424
github.com/spf13/[email protected] github.com/coreos/[email protected]
25-
`;
25+
`
2626

27-
describe("test go mod graph dependenciesProcessorFunc", () => {
28-
test("parses output of go mod graph into dependencies", async () => {
29-
const dependencies = parseDependents(GO_MOD_GRAPH);
27+
describe('test go mod graph dependenciesProcessorFunc', () => {
28+
test('parses output of go mod graph into dependencies', async () => {
29+
const dependencies = parseDependents(GO_MOD_GRAPH)
3030

3131
// Should have 7 total dependencies: 2 direct, 5 indirect
32-
expect(Object.values(dependencies).length).toEqual(7);
32+
expect(Object.values(dependencies).length).toEqual(7)
3333

3434
expect(
35-
dependencies["pkg:golang/github.com/jaffee/[email protected]"]
35+
dependencies['pkg:golang/github.com/jaffee/[email protected]']
3636
.relationship
37-
).toEqual("direct");
37+
).toEqual('direct')
3838

3939
expect(
40-
dependencies["pkg:golang/github.com/spf13/[email protected]"].relationship
41-
).toEqual("direct");
40+
dependencies['pkg:golang/github.com/spf13/[email protected]'].relationship
41+
).toEqual('direct')
4242

4343
expect(
44-
dependencies["pkg:golang/github.com/spf13/[email protected]"].dependencies
45-
).toContainEqual(dependencies["pkg:golang/github.com/coreos/[email protected]"]);
46-
});
47-
});
44+
dependencies['pkg:golang/github.com/spf13/[email protected]'].dependencies
45+
).toContainEqual(dependencies['pkg:golang/github.com/coreos/[email protected]'])
46+
})
47+
})

0 commit comments

Comments
 (0)