Skip to content

Commit

Permalink
squash me: apply other review hints
Browse files Browse the repository at this point in the history
  • Loading branch information
ThorbenLindhauer committed Oct 6, 2023
1 parent 956ed3a commit e8162e9
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 30 deletions.
2 changes: 1 addition & 1 deletion common/diff-sboms-standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const writeFile = function(path, content) {

var args = process.argv.slice(2); // first two arguments are the executable and the JS file

if (args.length != 3) {
if (args.length !== 3) {
throw new Error('Requires three arguments: <path to base SBOM> <path to comparing SBOM> <path to output file>');
}

Expand Down
24 changes: 12 additions & 12 deletions common/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162899,7 +162899,7 @@ module.exports = async function () {
core.info(`Dependency diff:`);
core.info(diff.fullDiff);

octokit.rest.issues.createComment({
await octokit.rest.issues.createComment({
owner: repo.owner.login,
repo: repo.name,
issue_number: prNumber,
Expand Down Expand Up @@ -163156,7 +163156,7 @@ function diffComponents(sbomDiff, baseComponent, comparingComponent) {
dependency the traversal belongs
*/

var componentDiff = sbomDiff.getComponentDiff(baseComponent, comparingComponent);
let componentDiff = sbomDiff.getComponentDiff(baseComponent, comparingComponent);
if (componentDiff) {
/*
* In an SBOM, any unique component has only one set of dependencies.
Expand Down Expand Up @@ -163303,7 +163303,7 @@ module.exports = async function (sbomDiff, template, partials = {}) {
currentIndentationState[times - 1] = lastItemInList;

const visualizationComponents = currentIndentationState.map((lastItemInListAtCurrentLevel, index) => {
const isMostDeeplyNestedList = index == currentIndentationState.length - 1;
const isMostDeeplyNestedList = index === currentIndentationState.length - 1;

if (lastItemInListAtCurrentLevel) {
return isMostDeeplyNestedList ? ' └─ ' : ' ';
Expand All @@ -163328,9 +163328,9 @@ module.exports = async function (sbomDiff, template, partials = {}) {
});

handlebars.registerHelper('hasChanges', function(componentDiff) {
return Object.keys(componentDiff.changedDependencies).length != 0 ||
Object.keys(componentDiff.addedDependencies).length != 0 ||
Object.keys(componentDiff.removedDependencies).length != 0;
return Object.keys(componentDiff.changedDependencies).length !== 0 ||
Object.keys(componentDiff.addedDependencies).length !== 0 ||
Object.keys(componentDiff.removedDependencies).length !== 0;
});

const renderedDiffs = new Set();
Expand All @@ -163346,7 +163346,7 @@ module.exports = async function (sbomDiff, template, partials = {}) {
});

handlebars.registerHelper('hasDependencies', function(component) {
return Object.keys(component.dependencies).length != 0;
return Object.keys(component.dependencies).length !== 0;
});

const renderedTrees = new Set();
Expand Down Expand Up @@ -163496,7 +163496,7 @@ class Component {
result.carefulLicenseTypes = [{type: LicenseType.Unknown, used: true}]
}

result.allLicensesGo = result.licenses.length > 0 && result.licenses.every(license => license.type == LicenseType.Go);
result.allLicensesGo = result.licenses.length > 0 && result.licenses.every(license => license.type === LicenseType.Go);

result.hasMultipleLicenses = result.licenses.length > 1;

Expand Down Expand Up @@ -163639,9 +163639,9 @@ class SBOMComponentDiff {
}

hasChanges() {
return Object.keys(this.changedDependencies).length != 0 ||
Object.keys(this.addedDependencies).length != 0 ||
Object.keys(this.removedDependencies).length != 0;
return Object.keys(this.changedDependencies).length !== 0 ||
Object.keys(this.addedDependencies).length !== 0 ||
Object.keys(this.removedDependencies).length !== 0;
}

addChangedDependency(component, componentDiff) {
Expand Down Expand Up @@ -163738,7 +163738,7 @@ class SBOMParser {
*/

// make a copy because we are modifying this array as we iterate
var dependents = component.dependents.slice();
let dependents = component.dependents.slice();

while (dependents.length > 0) {
const currentDependent = dependents.pop();
Expand Down
2 changes: 1 addition & 1 deletion common/src/diff-sboms.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = async function () {
core.info(`Dependency diff:`);
core.info(diff.fullDiff);

octokit.rest.issues.createComment({
await octokit.rest.issues.createComment({
owner: repo.owner.login,
repo: repo.name,
issue_number: prNumber,
Expand Down
2 changes: 1 addition & 1 deletion common/src/sbom-diff/differ.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function diffComponents(sbomDiff, baseComponent, comparingComponent) {
dependency the traversal belongs
*/

var componentDiff = sbomDiff.getComponentDiff(baseComponent, comparingComponent);
let componentDiff = sbomDiff.getComponentDiff(baseComponent, comparingComponent);
if (componentDiff) {
/*
* In an SBOM, any unique component has only one set of dependencies.
Expand Down
10 changes: 5 additions & 5 deletions common/src/sbom-diff/format-handlebars-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = async function (sbomDiff, template, partials = {}) {
currentIndentationState[times - 1] = lastItemInList;

const visualizationComponents = currentIndentationState.map((lastItemInListAtCurrentLevel, index) => {
const isMostDeeplyNestedList = index == currentIndentationState.length - 1;
const isMostDeeplyNestedList = index === currentIndentationState.length - 1;

if (lastItemInListAtCurrentLevel) {
return isMostDeeplyNestedList ? ' └─ ' : ' ';
Expand All @@ -87,9 +87,9 @@ module.exports = async function (sbomDiff, template, partials = {}) {
});

handlebars.registerHelper('hasChanges', function(componentDiff) {
return Object.keys(componentDiff.changedDependencies).length != 0 ||
Object.keys(componentDiff.addedDependencies).length != 0 ||
Object.keys(componentDiff.removedDependencies).length != 0;
return Object.keys(componentDiff.changedDependencies).length !== 0 ||
Object.keys(componentDiff.addedDependencies).length !== 0 ||
Object.keys(componentDiff.removedDependencies).length !== 0;
});

const renderedDiffs = new Set();
Expand All @@ -105,7 +105,7 @@ module.exports = async function (sbomDiff, template, partials = {}) {
});

handlebars.registerHelper('hasDependencies', function(component) {
return Object.keys(component.dependencies).length != 0;
return Object.keys(component.dependencies).length !== 0;
});

const renderedTrees = new Set();
Expand Down
8 changes: 4 additions & 4 deletions common/src/sbom-diff/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Component {
result.carefulLicenseTypes = [{type: LicenseType.Unknown, used: true}]
}

result.allLicensesGo = result.licenses.length > 0 && result.licenses.every(license => license.type == LicenseType.Go);
result.allLicensesGo = result.licenses.length > 0 && result.licenses.every(license => license.type === LicenseType.Go);

result.hasMultipleLicenses = result.licenses.length > 1;

Expand Down Expand Up @@ -190,9 +190,9 @@ class SBOMComponentDiff {
}

hasChanges() {
return Object.keys(this.changedDependencies).length != 0 ||
Object.keys(this.addedDependencies).length != 0 ||
Object.keys(this.removedDependencies).length != 0;
return Object.keys(this.changedDependencies).length !== 0 ||
Object.keys(this.addedDependencies).length !== 0 ||
Object.keys(this.removedDependencies).length !== 0;
}

addChangedDependency(component, componentDiff) {
Expand Down
2 changes: 1 addition & 1 deletion common/src/sbom-diff/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SBOMParser {
*/

// make a copy because we are modifying this array as we iterate
var dependents = component.dependents.slice();
let dependents = component.dependents.slice();

while (dependents.length > 0) {
const currentDependent = dependents.pop();
Expand Down
12 changes: 12 additions & 0 deletions common/src/test/sbom-diff.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ describe("SBOM diff", () => {

test("it should detect an added dependency", async () => {

// given
const projectA1SBOM = readJson(path.join(__dirname, 'sbom-diff-test-resources', 'project-a1.json'));
const projectA3SBOM = readJson(path.join(__dirname, 'sbom-diff-test-resources', 'project-a3.json'));

// when
const diff = await diffSBOMs(projectA3SBOM, projectA1SBOM, '^org\\.camunda');

// then
const rootComponentDiff = diff.rootComponentDiff;

expect(rootComponentDiff).toDescribeComponent('org.camunda.example', 'project-a', '1.0-SNAPSHOT');
Expand All @@ -28,10 +32,14 @@ describe("SBOM diff", () => {

test("it should detect a removed dependency", async () => {

// given
const projectA1SBOM = readJson(path.join(__dirname, 'sbom-diff-test-resources', 'project-a1.json'));
const projectA3SBOM = readJson(path.join(__dirname, 'sbom-diff-test-resources', 'project-a3.json'));

// when
const diff = await diffSBOMs(projectA1SBOM, projectA3SBOM, '^org\\.camunda');

// then
const rootComponentDiff = diff.rootComponentDiff;

expect(rootComponentDiff).toDescribeComponent('org.camunda.example', 'project-a', '1.0-SNAPSHOT');
Expand All @@ -43,10 +51,14 @@ describe("SBOM diff", () => {

test("it should diff a complex changed dependency", async () => {

// given
const projectA1SBOM = readJson(path.join(__dirname, 'sbom-diff-test-resources', 'project-a1.json'));
const projectA2SBOM = readJson(path.join(__dirname, 'sbom-diff-test-resources', 'project-a2.json'));

// when
const diff = await diffSBOMs(projectA1SBOM, projectA2SBOM, '^org\\.camunda');

// then
const rootComponentDiff = diff.rootComponentDiff;

expect(rootComponentDiff).toDescribeComponent('org.camunda.example', 'project-a', '1.0-SNAPSHOT');
Expand Down
6 changes: 3 additions & 3 deletions common/src/test/sbom-matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function toDescribeComponent(actual, group, name, version) {
throw new Error(`Must be used with an instance of SBOMDiff. Got ${actual}`);
}

var baseComponent = actual.baseComponent;
var comparingComponent = actual.comparingComponent;
const baseComponent = actual.baseComponent;
const comparingComponent = actual.comparingComponent;

const isMatch = component => component.group === group
&& component.name === name
Expand Down Expand Up @@ -52,7 +52,7 @@ function toDescribeComponent(actual, group, name, version) {

const actualChanges = Object.assign({}, actual.changedDependencies);
const unmatchedChanges = [];
var allChangesMatch = true;
let allChangesMatch = true;

changes.forEach(change => {
const actualChange = actualChanges[change.moduleId];
Expand Down
2 changes: 1 addition & 1 deletion common/src/test/sbom-parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("SBOM diff", () => {

expect(components.size).toEqual(19);

var numThirdPartyComponents = 0;
let numThirdPartyComponents = 0;

components.forEach(component => {
if (component.thirdParty) {
Expand Down
2 changes: 1 addition & 1 deletion java-dependency-check/diff.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Omitted due to character limit. See workflow artifacts for full diff file.

{{#each diff.addedDependencies}}
{{#if thirdParty}}
- [ ] {{name}}:{{>componentVersion}}
- [ ] {{name}}: {{>componentVersion}}
{{/if}}
{{/each}}

Expand Down

0 comments on commit e8162e9

Please sign in to comment.