Skip to content

Commit

Permalink
Merge pull request #61 from snyk/fix/add-category-array-to-sarif-prop…
Browse files Browse the repository at this point in the history
…erties

fix: add catergories in a seperate property field in the property bag
  • Loading branch information
j-sp4 authored Mar 8, 2021
2 parents 0b8f758 + 7cf8990 commit 7919781
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/interfaces/analysis-result.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface CommitChangeLine {

export interface RuleProperties {
tags: string[];
categories: string[];
exampleCommitFixes?: ExampleCommitFix[];
exampleCommitDescriptions?: string[];
precision: string;
Expand Down
21 changes: 12 additions & 9 deletions src/sarif_converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ function getSuggestions(analysisResults: IAnalysisResult): ISarifSuggestions {
}
}
return suggestions;
};
}

function getRulesAndAllIssues(analysisResults: IAnalysisResult, allIssuesBySuggestions: ISarifSuggestions): { rules: ReportingDescriptor[], allIssues: ISarifSuggestion[] } {
function getRulesAndAllIssues(
analysisResults: IAnalysisResult,
allIssuesBySuggestions: ISarifSuggestions,
): { rules: ReportingDescriptor[]; allIssues: ISarifSuggestion[] } {
let ruleIndex = 0;
const rules: ReportingDescriptor[] = [];
const allIssues: ISarifSuggestion[] = [];
Expand All @@ -67,10 +70,11 @@ function getRulesAndAllIssues(analysisResults: IAnalysisResult, allIssuesBySugge
const language = suggestion.id.split('%2F')[0];
const suggestionId = `${language}/${suggestion.rule}`;
const ruleProperties: RuleProperties = {
tags: [language, ...suggestion.tags, ...suggestion.categories],
tags: [language, ...suggestion.tags],
categories: suggestion.categories,
exampleCommitFixes: suggestion.exampleCommitFixes,
exampleCommitDescriptions: suggestion.exampleCommitDescriptions,
precision: 'very-high'
precision: 'very-high',
};

const rule = {
Expand All @@ -86,7 +90,7 @@ function getRulesAndAllIssues(analysisResults: IAnalysisResult, allIssuesBySugge
markdown: suggestion.text,
text: '',
},
properties: ruleProperties
properties: ruleProperties,
};

if (suggestion.cwe?.length) {
Expand All @@ -106,12 +110,11 @@ function getRulesAndAllIssues(analysisResults: IAnalysisResult, allIssuesBySugge
id: suggestionId,
text: suggestion.message,
});

});
ruleIndex += 1;
}
return { rules, allIssues };
};
}

function getResults(allIssues: ISarifSuggestion[]): Result[] {
const output = [];
Expand Down Expand Up @@ -142,7 +145,7 @@ function getResults(allIssues: ISarifSuggestion[]): Result[] {
},
},
},
]
],
};

if (issue.fingerprints) {
Expand Down Expand Up @@ -223,7 +226,7 @@ function getResults(allIssues: ISarifSuggestion[]): Result[] {
output.push(newResult);
}
return output;
};
}

//custom string splice implementation
export function stringSplice(str: string, index: number, count: number, add?: string) {
Expand Down

0 comments on commit 7919781

Please sign in to comment.