Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Change from metric to rule
The SARIF that we are interpreting has moved away from using `metric`
to the more general term, `rule`. We need to adapt our baseline lines of
code counting to use `rule` as well.
Andrew Eisenberg committed May 4, 2021
1 parent 8e3540b commit a2312a0
Showing 6 changed files with 30 additions and 30 deletions.
14 changes: 7 additions & 7 deletions lib/analyze.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/analyze.js.map

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

14 changes: 7 additions & 7 deletions lib/analyze.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/analyze.test.js.map
14 changes: 7 additions & 7 deletions src/analyze.test.ts
@@ -44,23 +44,23 @@ test("status report fields and search path setting", async (t) => {
sarifFile,
JSON.stringify({
runs: [
// variant 1 uses metricId
// variant 1 uses ruleId
{
properties: {
metricResults: [
{
metricId: `${language}/summary/lines-of-code`,
ruleId: `${language}/summary/lines-of-code`,
value: 123,
},
],
},
},
// variant 2 uses metric.id
// variant 2 uses rule.id
{
properties: {
metricResults: [
{
metric: {
rule: {
id: `${language}/summary/lines-of-code`,
},
value: 123,
@@ -166,21 +166,21 @@ test("status report fields and search path setting", async (t) => {
const sarif = JSON.parse(fs.readFileSync(filePath, "utf8"));
t.deepEqual(sarif.runs[0].properties.metricResults, [
{
metricId: `${lang}/summary/lines-of-code`,
ruleId: `${lang}/summary/lines-of-code`,
value: 123,
baseline: lineCount,
},
]);
t.deepEqual(sarif.runs[1].properties.metricResults, [
{
metric: {
rule: {
id: `${lang}/summary/lines-of-code`,
},
value: 123,
baseline: lineCount,
},
]);
// when the metric doesn't exists, it should not be added
// when the rule doesn't exists, it should not be added
t.deepEqual(sarif.runs[2].properties.metricResults, []);
}
});
14 changes: 7 additions & 7 deletions src/analyze.ts
@@ -295,16 +295,16 @@ async function injectLinesOfCode(
const sarif = JSON.parse(fs.readFileSync(sarifFile, "utf8"));
if (Array.isArray(sarif.runs)) {
for (const run of sarif.runs) {
const metricId = `${language}/summary/lines-of-code`;
const ruleId = `${language}/summary/lines-of-code`;
run.properties = run.properties || {};
run.properties.metricResults = run.properties.metricResults || [];
const metric = run.properties.metricResults.find(
// the metric id can be in either of two places
(m) => m.metricId === metricId || m.metric?.id === metricId
const rule = run.properties.metricResults.find(
// the rule id can be in either of two places
(r) => r.ruleId === ruleId || r.rule?.id === ruleId
);
// only add the baseline value if the metric already exists
if (metric) {
metric.baseline = lineCounts[language];
// only add the baseline value if the rule already exists
if (rule) {
rule.baseline = lineCounts[language];
}
}
}

0 comments on commit a2312a0

Please sign in to comment.