node-sarif-builder
Advanced tools
Comparing version 1.0.3-beta202201112322.0 to 1.0.3-beta202201122125.0
340
.cspell.json
{ | ||
"ignorePaths": [ | ||
"**/node_modules/**", | ||
"**/vscode-extension/**", | ||
"**/.git/**", | ||
".vscode", | ||
"megalinter", | ||
"package-lock.json", | ||
"report" | ||
], | ||
"language": "en", | ||
"version": "0.1", | ||
"words": [ | ||
"ALPHAID", | ||
"BETAID", | ||
"Builer", | ||
"Guids", | ||
"JSONLINT", | ||
"MARKDOWNLINT", | ||
"Multiformat", | ||
"Nooo", | ||
"SARIF", | ||
"SAST", | ||
"Sarif", | ||
"checkov", | ||
"checkstyle", | ||
"codecov", | ||
"codeql", | ||
"devskim", | ||
"gitleaks", | ||
"hadolint", | ||
"identifer", | ||
"ktlint", | ||
"lcov", | ||
"multiformat", | ||
"myfile", | ||
"npmrc", | ||
"nvuillam", | ||
"preid", | ||
"prepatch", | ||
"sarif", | ||
"semgrep", | ||
"stefanzweifel", | ||
"terrascan", | ||
"terrasform", | ||
"tflint", | ||
"trivy", | ||
"typedoc", | ||
"venv", | ||
"wesh" | ||
] | ||
} | ||
"ignorePaths": [ | ||
"**/node_modules/**", | ||
"**/vscode-extension/**", | ||
"**/.git/**", | ||
".vscode", | ||
"megalinter", | ||
"package-lock.json", | ||
"report" | ||
], | ||
"language": "en", | ||
"version": "0.1", | ||
"words": [ | ||
"ABAP", | ||
"ALPHAID", | ||
"AMPL", | ||
"ANTLR", | ||
"Agda", | ||
"Augeas", | ||
"BETAID", | ||
"Batchfile", | ||
"Befunge", | ||
"Bluespec", | ||
"Brightscript", | ||
"Builer", | ||
"Carto", | ||
"Cirru", | ||
"Cuda", | ||
"Cycript", | ||
"Cython", | ||
"Darcs", | ||
"Dogescript", | ||
"Ecere", | ||
"Eclass", | ||
"GLSL", | ||
"Genshi", | ||
"Gettext", | ||
"Golo", | ||
"Gosu", | ||
"Graphviz", | ||
"Groff", | ||
"Guids", | ||
"HLSL", | ||
"Haml", | ||
"Haxe", | ||
"Idris", | ||
"Inno", | ||
"Ioke", | ||
"JSONLD", | ||
"JSONLINT", | ||
"LOLCODE", | ||
"Linx", | ||
"Logtalk", | ||
"MARKDOWNLINT", | ||
"MTML", | ||
"Mathematica", | ||
"Mirah", | ||
"Modelica", | ||
"Moocode", | ||
"Multiformat", | ||
"Myghty", | ||
"NSIS", | ||
"Nemerle", | ||
"Nooo", | ||
"Omgrofl", | ||
"Oxygene", | ||
"PLSQL", | ||
"Pico", | ||
"RAML", | ||
"RHTML", | ||
"Ragel", | ||
"Rebol", | ||
"Redcode", | ||
"Ren'Py", | ||
"SARIF", | ||
"SAST", | ||
"SPARQL", | ||
"SQLPL", | ||
"STON", | ||
"Sarif", | ||
"Scaml", | ||
"Scilab", | ||
"Shen", | ||
"Smali", | ||
"Stata", | ||
"Tcsh", | ||
"VHDL", | ||
"Vala", | ||
"Verilog", | ||
"Xojo", | ||
"Zephir", | ||
"Zimpl", | ||
"abap", | ||
"adoc", | ||
"agda", | ||
"ahkl", | ||
"ampl", | ||
"apacheconf", | ||
"applescript", | ||
"arpa", | ||
"asax", | ||
"ashx", | ||
"asmx", | ||
"befunge", | ||
"capnp", | ||
"ccxml", | ||
"checkov", | ||
"checkstyle", | ||
"chpl", | ||
"cirru", | ||
"cjsx", | ||
"clixml", | ||
"cljc", | ||
"cljscm", | ||
"cmake", | ||
"codecov", | ||
"codeql", | ||
"cppobjdump", | ||
"cproject", | ||
"darcspatch", | ||
"dats", | ||
"devskim", | ||
"ditaval", | ||
"dotsettings", | ||
"dpatch", | ||
"druby", | ||
"duby", | ||
"dyalog", | ||
"eclass", | ||
"eclxml", | ||
"eliom", | ||
"eliomi", | ||
"emberscript", | ||
"escript", | ||
"fancypack", | ||
"fcgi", | ||
"fshader", | ||
"gcode", | ||
"gitleaks", | ||
"glsl", | ||
"glslv", | ||
"golo", | ||
"grxml", | ||
"gshader", | ||
"gtpl", | ||
"hadolint", | ||
"haml", | ||
"hlean", | ||
"hlsl", | ||
"hlsli", | ||
"hxsl", | ||
"identifer", | ||
"ihlp", | ||
"ipynb", | ||
"irbrc", | ||
"irclog", | ||
"jbuilder", | ||
"jflex", | ||
"jscad", | ||
"jsfl", | ||
"jsonld", | ||
"jsproj", | ||
"kicad", | ||
"ktlint", | ||
"lagda", | ||
"lcov", | ||
"lidr", | ||
"logtalk", | ||
"lookml", | ||
"lslp", | ||
"lvproj", | ||
"mata", | ||
"matah", | ||
"mathematica", | ||
"mawk", | ||
"maxhelp", | ||
"maxpat", | ||
"maxproj", | ||
"mdpolicy", | ||
"minid", | ||
"mirah", | ||
"mkdn", | ||
"mkdown", | ||
"mkfile", | ||
"mkii", | ||
"mkiv", | ||
"mkvi", | ||
"mousemap", | ||
"mspec", | ||
"mtml", | ||
"multiformat", | ||
"mupad", | ||
"myfile", | ||
"nasm", | ||
"nawk", | ||
"nginxconf", | ||
"nlogo", | ||
"npmrc", | ||
"nproj", | ||
"numpy", | ||
"numpyw", | ||
"numsc", | ||
"nvuillam", | ||
"objdump", | ||
"omgrofl", | ||
"opencl", | ||
"oxygene", | ||
"pasm", | ||
"phps", | ||
"phpt", | ||
"plsql", | ||
"pluginspec", | ||
"pmod", | ||
"podsl", | ||
"podspec", | ||
"prefs", | ||
"preid", | ||
"prepatch", | ||
"purs", | ||
"pyde", | ||
"pytb", | ||
"rabl", | ||
"raml", | ||
"rbbas", | ||
"rbfrm", | ||
"rbmnu", | ||
"rbres", | ||
"rbtbar", | ||
"rbuild", | ||
"rbuistate", | ||
"rbxs", | ||
"rdoc", | ||
"rebol", | ||
"rhtml", | ||
"rktd", | ||
"rktl", | ||
"roff", | ||
"rviz", | ||
"sagews", | ||
"sarif", | ||
"sats", | ||
"scaml", | ||
"scpt", | ||
"scrbl", | ||
"scxml", | ||
"semgrep", | ||
"sexp", | ||
"shen", | ||
"smali", | ||
"sparql", | ||
"srdf", | ||
"ssjs", | ||
"stefanzweifel", | ||
"sthlp", | ||
"ston", | ||
"styl", | ||
"tcsh", | ||
"terrascan", | ||
"terrasform", | ||
"tflint", | ||
"topojson", | ||
"traceback", | ||
"trivy", | ||
"typedoc", | ||
"urdf", | ||
"vala", | ||
"vapi", | ||
"vark", | ||
"vbhtml", | ||
"venv", | ||
"vhdl", | ||
"vshader", | ||
"vssettings", | ||
"vxml", | ||
"webidl", | ||
"weechatlog", | ||
"wesh", | ||
"wlua", | ||
"wsgi", | ||
"xacro", | ||
"xojo", | ||
"xproc", | ||
"xproj", | ||
"xsjs", | ||
"xsjslib", | ||
"zcml", | ||
"zimpl", | ||
"zmpl" | ||
] | ||
} |
@@ -10,11 +10,4 @@ { | ||
}, | ||
"ignorePatterns": [ | ||
"node_modules", | ||
"dist", | ||
"coverage" | ||
], | ||
"plugins": [ | ||
"import", | ||
"eslint-comments" | ||
], | ||
"ignorePatterns": ["node_modules", "dist", "coverage"], | ||
"plugins": ["import", "eslint-comments"], | ||
"extends": [ | ||
@@ -60,2 +53,2 @@ "eslint:recommended", | ||
} | ||
} | ||
} |
@@ -6,4 +6,4 @@ { | ||
"eamodio.gitlens", | ||
"streetsidesoftware.code-spell-checker", | ||
"streetsidesoftware.code-spell-checker" | ||
] | ||
} |
@@ -28,3 +28,4 @@ { | ||
// "smartStep": true | ||
}] | ||
} | ||
] | ||
} |
@@ -7,4 +7,14 @@ # Changelog | ||
## [2.0.0] 2022-01-12 | ||
- Mandatory properties `toolDriverName` and `toolDriverVersion` for SarifRunBuilder | ||
- Change default schema version to <https://www.schemastore.org/schemas/json/sarif-2.1.0-rtm.5.json> | ||
- When possible, automatically populate SARIF properties: | ||
- `artifact.sourceLanguage` | ||
- `result.locations.location.physicalLocation.artifactLocation.index` | ||
- `result.ruleIndex` | ||
- Fix bug when initSimple is called without region properties | ||
## [1.0.0] 2022-01-11 | ||
- Initial version |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SarifBuilder = void 0; | ||
const path = require("path"); | ||
const fs = require("fs-extra"); | ||
const languages_1 = require("./languages"); | ||
const utils_1 = require("./utils"); | ||
@@ -12,5 +14,5 @@ // SARIF Builder | ||
this.log = { | ||
$schema: 'http://json.schemastore.org/sarif-2.1.0-rtm.4', | ||
$schema: 'https://www.schemastore.org/schemas/json/sarif-2.1.0-rtm.5.json', | ||
version: '2.1.0', | ||
runs: [], | ||
runs: [] | ||
}; | ||
@@ -54,4 +56,6 @@ (0, utils_1.setOptionValues)(options, this.log); | ||
run.artifacts.filter(artifact => { var _a; return ((_a = artifact === null || artifact === void 0 ? void 0 : artifact.location) === null || _a === void 0 ? void 0 : _a.uri) === location.physicalLocation.artifactLocation.uri; }).length === 0) { | ||
// Add result to driver artifact only if not existing | ||
run.artifacts.push({ location: { uri: location.physicalLocation.artifactLocation.uri } }); | ||
// Add result to driver artifact only if not existing | ||
const ext = path.extname(location.physicalLocation.artifactLocation.uri).replace('.', ''); | ||
const language = languages_1.EXTENSIONS_LANGUAGES[ext] || 'unknown'; | ||
run.artifacts.push({ sourceLanguage: language, location: { uri: location.physicalLocation.artifactLocation.uri } }); | ||
} | ||
@@ -72,4 +76,4 @@ } | ||
// Set rule index in results | ||
if (rulesIndexes[result.ruleId]) { | ||
result.ruleIndex = rulesIndexes[result.ruleId]; | ||
if (rulesIndexes.indexOf(result.ruleId) > -1) { | ||
result.ruleIndex = rulesIndexes.indexOf(result.ruleId); | ||
} | ||
@@ -81,4 +85,4 @@ // Set artifact index in results | ||
const uri = (_b = (_a = location === null || location === void 0 ? void 0 : location.physicalLocation) === null || _a === void 0 ? void 0 : _a.artifactLocation) === null || _b === void 0 ? void 0 : _b.uri; | ||
if (uri && artifactIndexes[uri] !== undefined && artifactIndexes[uri] !== null) { | ||
location.physicalLocation.artifactLocation.index = artifactIndexes[uri]; | ||
if (uri && artifactIndexes.indexOf(uri) > -1) { | ||
location.physicalLocation.artifactLocation.index = artifactIndexes.indexOf(uri); | ||
} | ||
@@ -85,0 +89,0 @@ return location; |
@@ -17,3 +17,3 @@ "use strict"; | ||
const sarifBuilder = new sarif_builder_1.SarifBuilder({ | ||
$schema: 'http://json.schemastore.org/sarif-2.1.0-rtm.3', | ||
$schema: 'http://json.schemastore.org/sarif-2.1.0-rtm.3' | ||
}); | ||
@@ -85,3 +85,3 @@ t.is(sarifBuilder.log.$schema, 'http://json.schemastore.org/sarif-2.1.0-rtm.3'); | ||
const sarifRunBuilder = new sarif_run_builder_1.SarifRunBuilder(); | ||
sarifRunBuilder.initSimple({ name: 'MegaLinter' }); | ||
sarifRunBuilder.initSimple({ toolDriverName: 'MegaLinter', toolDriverVersion: '5.5.0' }); | ||
return sarifRunBuilder; | ||
@@ -96,3 +96,3 @@ } | ||
fileUri: 'src/urf/wesh.js', | ||
startLine: 8, | ||
startLine: 8 | ||
}); | ||
@@ -108,3 +108,3 @@ return sarifResultBuilder; | ||
fileUri: 'src/urf/wesh.js', | ||
startLine: 8, | ||
startLine: 8 | ||
}); | ||
@@ -120,3 +120,3 @@ return sarifResultBuilder; | ||
fileUri: 'src/urf/wesh.js', | ||
startLine: 0, | ||
startLine: 0 | ||
}); | ||
@@ -123,0 +123,0 @@ return sarifResultBuilder; |
@@ -1,3 +0,3 @@ | ||
import { ArtifactLocation, Region, Result } from "sarif"; | ||
import { SarifResultOptions } from "../types/node-sarif-builder"; | ||
import { ArtifactLocation, Region, Result } from 'sarif'; | ||
import { SarifResultOptions } from '../types/node-sarif-builder'; | ||
export declare class SarifResultBuilder { | ||
@@ -4,0 +4,0 @@ result: Result; |
@@ -12,3 +12,3 @@ "use strict"; | ||
message: {}, | ||
ruleId: 'SARIF_BUILDER_INVALID: Please send the rule Id ruleId property, or call setRuleId(ruleId)', | ||
ruleId: 'SARIF_BUILDER_INVALID: Please send the rule Id ruleId property, or call setRuleId(ruleId)' | ||
}; | ||
@@ -24,3 +24,3 @@ (0, utils_1.setOptionValues)(options, this.result); | ||
} | ||
if (options.startLine !== null) { | ||
if (options.startLine !== null && options.startLine !== undefined) { | ||
// Initialize Region with default values with necessary | ||
@@ -31,7 +31,7 @@ const region = { | ||
endLine: options.endLine || options.startLine, | ||
endColumn: options.endColumn || 1, | ||
endColumn: options.endColumn || 1 | ||
}; | ||
// Check for invalid region values | ||
if (options.startLine === 0 || options.startColumn === 0 || options.endLine === 0 || options.endColumn === 0) { | ||
throw new Error("Region limit can not be 0 (minimum line 1 or column 1) in " + JSON.stringify(options)); | ||
throw new Error('Region limit can not be 0 (minimum line 1 or column 1) in ' + JSON.stringify(options)); | ||
} | ||
@@ -38,0 +38,0 @@ this.setLocationRegion(region); |
@@ -1,3 +0,3 @@ | ||
import { ReportingDescriptor } from "sarif"; | ||
import { SarifRuleOptions } from "../types/node-sarif-builder"; | ||
import { ReportingDescriptor } from 'sarif'; | ||
import { SarifRuleOptions } from '../types/node-sarif-builder'; | ||
export declare class SarifRuleBuilder { | ||
@@ -4,0 +4,0 @@ rule: ReportingDescriptor; |
@@ -14,3 +14,3 @@ "use strict"; | ||
shortDescription: { | ||
text: "SARIF_BUILDER_INVALID: Please send the rule text in shortDescription.text property, or call setShortDescriptionText(text)" | ||
text: 'SARIF_BUILDER_INVALID: Please send the rule text in shortDescription.text property, or call setShortDescriptionText(text)' | ||
} | ||
@@ -40,3 +40,3 @@ }; | ||
setFullDescriptionText(fullDescriptionText) { | ||
this.rule.fullDescription = this.rule.fullDescription || { text: "" }; | ||
this.rule.fullDescription = this.rule.fullDescription || { text: '' }; | ||
this.rule.fullDescription.text = fullDescriptionText; | ||
@@ -43,0 +43,0 @@ } |
@@ -1,5 +0,5 @@ | ||
import { Run } from "sarif"; | ||
import { SarifRuleBuilder } from ".."; | ||
import { SarifRunOptions } from "../types/node-sarif-builder"; | ||
import { SarifResultBuilder } from "./sarif-result-builder"; | ||
import { Run } from 'sarif'; | ||
import { SarifRuleBuilder } from '..'; | ||
import { SarifRunOptions } from '../types/node-sarif-builder'; | ||
import { SarifResultBuilder } from './sarif-result-builder'; | ||
export declare class SarifRunBuilder { | ||
@@ -9,3 +9,4 @@ run: Run; | ||
initSimple(options: { | ||
name: string; | ||
toolDriverName: string; | ||
toolDriverVersion: string; | ||
url?: string; | ||
@@ -16,3 +17,4 @@ }): this; | ||
setToolDriverName(name: string): void; | ||
setToolDriverVersion(version: string): void; | ||
setToolDriverUri(url: string): void; | ||
} |
@@ -15,6 +15,6 @@ "use strict"; | ||
'SARIF_BUILDER_INVALID: Please send the tool name in tool.driver.name property, or call setToolName(name)', | ||
rules: [], | ||
}, | ||
rules: [] | ||
} | ||
}, | ||
results: [], | ||
results: [] | ||
}; | ||
@@ -24,3 +24,4 @@ (0, utils_1.setOptionValues)(options, this.run); | ||
initSimple(options) { | ||
this.setToolDriverName(options.name); | ||
this.setToolDriverName(options.toolDriverName); | ||
this.setToolDriverVersion(options.toolDriverVersion); | ||
if (options.url) { | ||
@@ -40,2 +41,5 @@ this.setToolDriverUri(options.url); | ||
} | ||
setToolDriverVersion(version) { | ||
this.run.tool.driver.version = version; | ||
} | ||
setToolDriverUri(url) { | ||
@@ -42,0 +46,0 @@ this.run.tool.driver.informationUri = url; |
{ | ||
"name": "node-sarif-builder", | ||
"version": "1.0.3-beta202201112322.0", | ||
"version": "1.0.3-beta202201122125.0", | ||
"description": "Module to help building SARIF log files", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -46,4 +46,7 @@ # node-sarif-builder | ||
If you are a **maintainer** of any **javascript/typescript based** SAST tool, but also IaC tool, or **any type of tool that can return a list of errors with a level of severity**, you can either read the whole [OASIS Specification](https://docs.oasis-open.org/sarif/sarif/v2.1.0/csprd01/sarif-v2.1.0-csprd01.html), or **simply use this library** to add SARIF as additional output format, so your tool will be natively compliant with any of SARIF-compliant tools ! | ||
If you are a **maintainer** of any **javascript/typescript based** SAST tool, but also IaC tool, or **any type of tool that can return a list of errors with a level of severity**, you can either: | ||
- read the whole [OASIS Specification](https://docs.oasis-open.org/sarif/sarif/v2.1.0/csprd01/sarif-v2.1.0-csprd01.html) and implement it | ||
- **simply use this library** to add SARIF as additional output format, so your tool will be natively compliant with any of SARIF-compliant tools ! | ||
## Installation | ||
@@ -75,3 +78,3 @@ | ||
____ | ||
___ | ||
@@ -85,8 +88,9 @@ - Create and init **SarifBuilder** and **SarifRunBuilder** objects | ||
const sarifRunBuilder = new SarifRunBuilder().initSimple({ | ||
name: "npm-groovy-lint", // Name of your analyzer tool | ||
url: "https://nvuillam.github.io/npm-groovy-lint/" // Url of your analyzer tool | ||
toolDriverName: "npm-groovy-lint", // Name of your analyzer tool | ||
toolDriverVersion: "9.0.5", // Version of your analyzer tool | ||
url: "https://nvuillam.github.io/npm-groovy-lint/" // Url of your analyzer tool | ||
}); | ||
``` | ||
____ | ||
___ | ||
@@ -107,3 +111,3 @@ - Add all rules that can be found in your results (recommended but optional) | ||
____ | ||
___ | ||
@@ -139,3 +143,3 @@ - For each found issue, create a SarifResultBuilder and add it to the SarifRunBuilder object | ||
____ | ||
___ | ||
@@ -153,3 +157,3 @@ - Add run to sarifBuilder then generate JSON SARIF output file | ||
- Working in [npm-groovy-lint]() | ||
- Working in [npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint) | ||
@@ -162,3 +166,4 @@ ```javascript | ||
const sarifRunBuilder = new SarifRunBuilder().initSimple({ | ||
name: "npm-groovy-lint", | ||
toolDriverName: "npm-groovy-lint", | ||
toolDriverVersion: "9.0.5", | ||
url: "https://nvuillam.github.io/npm-groovy-lint/" | ||
@@ -217,1 +222,5 @@ }); | ||
``` | ||
## Test | ||
You can confirm that your generated SARIF logs are valid on <https://sarifweb.azurewebsites.net/Validation> |
@@ -1,6 +0,6 @@ | ||
import { SarifBuilder } from './lib/sarif-builder'; | ||
import { SarifResultBuilder } from './lib/sarif-result-builder'; | ||
import { SarifRuleBuilder } from './lib/sarif-rule-builder'; | ||
import { SarifRunBuilder } from './lib/sarif-run-builder'; | ||
import { SarifBuilder } from './lib/sarif-builder' | ||
import { SarifResultBuilder } from './lib/sarif-result-builder' | ||
import { SarifRuleBuilder } from './lib/sarif-rule-builder' | ||
import { SarifRunBuilder } from './lib/sarif-run-builder' | ||
export { SarifBuilder, SarifRunBuilder, SarifRuleBuilder, SarifResultBuilder }; | ||
export { SarifBuilder, SarifRunBuilder, SarifRuleBuilder, SarifResultBuilder } |
@@ -1,56 +0,56 @@ | ||
import * as os from 'os'; | ||
import * as path from 'path'; | ||
import * as os from 'os' | ||
import * as path from 'path' | ||
import test from 'ava'; | ||
import * as fs from 'fs-extra'; | ||
import { Log } from 'sarif'; | ||
import test from 'ava' | ||
import * as fs from 'fs-extra' | ||
import { Log } from 'sarif' | ||
import { SarifBuilder, } from './sarif-builder'; | ||
import { SarifResultBuilder } from './sarif-result-builder'; | ||
import { SarifRuleBuilder } from './sarif-rule-builder'; | ||
import { SarifRunBuilder } from './sarif-run-builder'; | ||
import { SarifBuilder } from './sarif-builder' | ||
import { SarifResultBuilder } from './sarif-result-builder' | ||
import { SarifRuleBuilder } from './sarif-rule-builder' | ||
import { SarifRunBuilder } from './sarif-run-builder' | ||
test('Create SarifBuilder', (t) => { | ||
const sarifBuilder = new SarifBuilder(); | ||
t.assert(sarifBuilder !== null, 'SarifBuilder has been created'); | ||
}); | ||
const sarifBuilder = new SarifBuilder() | ||
t.assert(sarifBuilder !== null, 'SarifBuilder has been created') | ||
}) | ||
test('Create SarifBuilder with args', (t) => { | ||
const sarifBuilder = new SarifBuilder({ | ||
$schema: 'http://json.schemastore.org/sarif-2.1.0-rtm.3', | ||
}); | ||
$schema: 'http://json.schemastore.org/sarif-2.1.0-rtm.3' | ||
}) | ||
t.is( | ||
sarifBuilder.log.$schema, | ||
'http://json.schemastore.org/sarif-2.1.0-rtm.3' | ||
); | ||
}); | ||
) | ||
}) | ||
test('Create SarifRunBuilder', (t) => { | ||
const sarifBuilder = new SarifRunBuilder(); | ||
t.assert(sarifBuilder != null, 'SarifRunBuilder has been created'); | ||
}); | ||
const sarifBuilder = new SarifRunBuilder() | ||
t.assert(sarifBuilder != null, 'SarifRunBuilder has been created') | ||
}) | ||
test('Create SarifRunBuilder and use initSimple', (t) => { | ||
const sarifRunBuilder = createInitSarifRunBuilder(); | ||
t.assert(sarifRunBuilder != null, 'SarifRunBuilder has been created'); | ||
t.is(sarifRunBuilder.run.tool.driver.name, 'MegaLinter'); | ||
}); | ||
const sarifRunBuilder = createInitSarifRunBuilder() | ||
t.assert(sarifRunBuilder != null, 'SarifRunBuilder has been created') | ||
t.is(sarifRunBuilder.run.tool.driver.name, 'MegaLinter') | ||
}) | ||
test('Create SarifResultBuilder', (t) => { | ||
const sarifResultBuilder = new SarifResultBuilder(); | ||
t.assert(sarifResultBuilder != null, 'SarifResultBuilder has been created'); | ||
}); | ||
const sarifResultBuilder = new SarifResultBuilder() | ||
t.assert(sarifResultBuilder != null, 'SarifResultBuilder has been created') | ||
}) | ||
test('Create SarifResultBuilder and set message', (t) => { | ||
const sarifResultBuilder = new SarifResultBuilder(); | ||
sarifResultBuilder.setMessageText('MegaLinter message'); | ||
t.assert(sarifResultBuilder != null, 'SarifResultBuilder has been created'); | ||
t.is(sarifResultBuilder.result.message.text, 'MegaLinter message'); | ||
}); | ||
const sarifResultBuilder = new SarifResultBuilder() | ||
sarifResultBuilder.setMessageText('MegaLinter message') | ||
t.assert(sarifResultBuilder != null, 'SarifResultBuilder has been created') | ||
t.is(sarifResultBuilder.result.message.text, 'MegaLinter message') | ||
}) | ||
test('Create SarifResultBuilder and use initSimple', (t) => { | ||
const sarifResultBuilder = createInitSarifResultBuilder(); | ||
t.assert(sarifResultBuilder != null, 'SarifResultBuilder has been created'); | ||
t.is(sarifResultBuilder.result.message.text, 'An assignment operator (=) was used in a conditional test. This is usually a typo, and the comparison operator (==) was intended.'); | ||
t.is(sarifResultBuilder.result.ruleId, 'AssignmentInConditional'); | ||
const sarifResultBuilder = createInitSarifResultBuilder() | ||
t.assert(sarifResultBuilder != null, 'SarifResultBuilder has been created') | ||
t.is(sarifResultBuilder.result.message.text, 'An assignment operator (=) was used in a conditional test. This is usually a typo, and the comparison operator (==) was intended.') | ||
t.is(sarifResultBuilder.result.ruleId, 'AssignmentInConditional') | ||
t.is( | ||
@@ -60,68 +60,68 @@ sarifResultBuilder.result.locations[0].physicalLocation.artifactLocation | ||
'src/urf/wesh.js' | ||
); | ||
) | ||
t.is( | ||
sarifResultBuilder.result.locations[0].physicalLocation.region.startLine, | ||
8 | ||
); | ||
) | ||
t.is( | ||
sarifResultBuilder.result.locations[0].physicalLocation.region.startColumn, | ||
1 | ||
); | ||
) | ||
t.is( | ||
sarifResultBuilder.result.locations[0].physicalLocation.region.endLine, | ||
8 | ||
); | ||
) | ||
t.is( | ||
sarifResultBuilder.result.locations[0].physicalLocation.region.endColumn, | ||
1 | ||
); | ||
}); | ||
) | ||
}) | ||
test('Create SarifResultBuilder and generate file', (t) => { | ||
const sarifBuilder = new SarifBuilder(); | ||
const sarifRunBuilder = createInitSarifRunBuilder(); | ||
sarifRunBuilder.addRule(createInitSarifRuleBuilder()); | ||
sarifRunBuilder.addRule(createInitSarifRuleBuilder2()); | ||
sarifRunBuilder.addResult(createInitSarifResultBuilder()); | ||
sarifRunBuilder.addResult(createInitSarifResultBuilder2()); | ||
sarifBuilder.addRun(sarifRunBuilder); | ||
const sarifBuilder = new SarifBuilder() | ||
const sarifRunBuilder = createInitSarifRunBuilder() | ||
sarifRunBuilder.addRule(createInitSarifRuleBuilder()) | ||
sarifRunBuilder.addRule(createInitSarifRuleBuilder2()) | ||
sarifRunBuilder.addResult(createInitSarifResultBuilder()) | ||
sarifRunBuilder.addResult(createInitSarifResultBuilder2()) | ||
sarifBuilder.addRun(sarifRunBuilder) | ||
const outputFile = path.join( | ||
os.tmpdir(), | ||
'testSarifBuilder-' + Math.random() + '.sarif' | ||
); | ||
sarifBuilder.generateSarifFileSync(outputFile); | ||
t.assert(fs.existsSync(outputFile), 'Output SARIF file not found'); | ||
const outputSarifObj: Log = JSON.parse(fs.readFileSync(outputFile, 'utf8')); | ||
) | ||
sarifBuilder.generateSarifFileSync(outputFile) | ||
t.assert(fs.existsSync(outputFile), 'Output SARIF file not found') | ||
const outputSarifObj: Log = JSON.parse(fs.readFileSync(outputFile, 'utf8')) | ||
t.assert( | ||
outputSarifObj?.runs?.length > 0, | ||
'No runs found in generated SARIF log' | ||
); | ||
) | ||
t.assert( | ||
outputSarifObj?.runs[0].tool?.driver?.rules?.length > 1, | ||
'No rules found in generated SARIF log' | ||
); | ||
) | ||
t.assert( | ||
outputSarifObj?.runs[0].artifacts.length > 0, | ||
'No artifacts found in generated SARIF log' | ||
); | ||
) | ||
t.assert( | ||
outputSarifObj?.runs[0].results?.length > 1, | ||
'No results found in generated SARIF log' | ||
); | ||
) | ||
t.assert( | ||
outputSarifObj?.runs[0].results[0].ruleIndex !== null, | ||
'Result rule index should be set' | ||
); | ||
) | ||
t.assert( | ||
outputSarifObj?.runs[0].results[0]?.locations[0]?.physicalLocation?.artifactLocation?.index !== null, | ||
'Result artifact index should be set' | ||
); | ||
}); | ||
) | ||
}) | ||
test('Create SarifResultBuilder with error', (t) => { | ||
let error = false; | ||
let error = false | ||
try { | ||
createInitSarifWrongResultBuilder(); | ||
createInitSarifWrongResultBuilder() | ||
} catch (e) { | ||
error = true; | ||
error = true | ||
} | ||
@@ -131,13 +131,13 @@ t.assert( | ||
'Error should have been triggered' | ||
); | ||
}); | ||
) | ||
}) | ||
function createInitSarifRunBuilder() { | ||
const sarifRunBuilder = new SarifRunBuilder(); | ||
sarifRunBuilder.initSimple({ name: 'MegaLinter' }); | ||
return sarifRunBuilder; | ||
function createInitSarifRunBuilder () { | ||
const sarifRunBuilder = new SarifRunBuilder() | ||
sarifRunBuilder.initSimple({ toolDriverName: 'MegaLinter', toolDriverVersion: '5.5.0' }) | ||
return sarifRunBuilder | ||
} | ||
function createInitSarifResultBuilder() { | ||
const sarifResultBuilder = new SarifResultBuilder(); | ||
function createInitSarifResultBuilder () { | ||
const sarifResultBuilder = new SarifResultBuilder() | ||
sarifResultBuilder.initSimple({ | ||
@@ -148,9 +148,9 @@ level: 'warning', | ||
fileUri: 'src/urf/wesh.js', | ||
startLine: 8, | ||
}); | ||
return sarifResultBuilder; | ||
startLine: 8 | ||
}) | ||
return sarifResultBuilder | ||
} | ||
function createInitSarifResultBuilder2() { | ||
const sarifResultBuilder = new SarifResultBuilder(); | ||
function createInitSarifResultBuilder2 () { | ||
const sarifResultBuilder = new SarifResultBuilder() | ||
sarifResultBuilder.initSimple({ | ||
@@ -161,9 +161,9 @@ level: 'warning', | ||
fileUri: 'src/urf/wesh.js', | ||
startLine: 8, | ||
}); | ||
return sarifResultBuilder; | ||
startLine: 8 | ||
}) | ||
return sarifResultBuilder | ||
} | ||
function createInitSarifWrongResultBuilder() { | ||
const sarifResultBuilder = new SarifResultBuilder(); | ||
function createInitSarifWrongResultBuilder () { | ||
const sarifResultBuilder = new SarifResultBuilder() | ||
sarifResultBuilder.initSimple({ | ||
@@ -174,9 +174,9 @@ level: 'warning', | ||
fileUri: 'src/urf/wesh.js', | ||
startLine: 0, | ||
}); | ||
return sarifResultBuilder; | ||
startLine: 0 | ||
}) | ||
return sarifResultBuilder | ||
} | ||
function createInitSarifRuleBuilder() { | ||
const sarifRuleBuilder = new SarifRuleBuilder(); | ||
function createInitSarifRuleBuilder () { | ||
const sarifRuleBuilder = new SarifRuleBuilder() | ||
sarifRuleBuilder.initSimple({ | ||
@@ -187,8 +187,8 @@ ruleId: 'AssignmentInConditional', | ||
helpUri: 'https://codenarc.org/codenarc-rules-basic.html#AssignmentInConditional' | ||
}); | ||
return sarifRuleBuilder; | ||
}) | ||
return sarifRuleBuilder | ||
} | ||
function createInitSarifRuleBuilder2() { | ||
const sarifRuleBuilder = new SarifRuleBuilder(); | ||
function createInitSarifRuleBuilder2 () { | ||
const sarifRuleBuilder = new SarifRuleBuilder() | ||
sarifRuleBuilder.initSimple({ | ||
@@ -198,4 +198,4 @@ ruleId: 'NoAny', | ||
helpUri: 'https://codenarc.org/codenarc-rules-basic.html#NoAny' | ||
}); | ||
return sarifRuleBuilder; | ||
} | ||
}) | ||
return sarifRuleBuilder | ||
} |
@@ -1,9 +0,12 @@ | ||
import * as fs from 'fs-extra'; | ||
import { Log, Run } from 'sarif'; | ||
import * as path from 'path' | ||
import { LogOptions } from '../types/node-sarif-builder'; | ||
import * as fs from 'fs-extra' | ||
import { Log, Run } from 'sarif' | ||
import { SarifRunBuilder } from './sarif-run-builder'; | ||
import { setOptionValues } from './utils'; | ||
import { LogOptions } from '../types/node-sarif-builder' | ||
import { EXTENSIONS_LANGUAGES } from './languages' | ||
import { SarifRunBuilder } from './sarif-run-builder' | ||
import { setOptionValues } from './utils' | ||
// SARIF Builder | ||
@@ -13,49 +16,49 @@ export class SarifBuilder { | ||
log: Log = { | ||
$schema: 'http://json.schemastore.org/sarif-2.1.0-rtm.4', | ||
$schema: 'https://www.schemastore.org/schemas/json/sarif-2.1.0-rtm.5.json', | ||
version: '2.1.0', | ||
runs: [], | ||
runs: [] | ||
}; | ||
// Initialize SARIF Log builder | ||
constructor(options: LogOptions = {}) { | ||
setOptionValues(options, this.log); | ||
constructor (options: LogOptions = {}) { | ||
setOptionValues(options, this.log) | ||
} | ||
addRun(sarifRunBuilder: SarifRunBuilder) { | ||
this.log.runs.push(sarifRunBuilder.run); | ||
addRun (sarifRunBuilder: SarifRunBuilder) { | ||
this.log.runs.push(sarifRunBuilder.run) | ||
} | ||
generateSarifFileSync(file: string) { | ||
const sarifJsonString = this.buildSarifJsonString(); | ||
fs.writeFileSync(file, sarifJsonString, 'utf8'); | ||
generateSarifFileSync (file: string) { | ||
const sarifJsonString = this.buildSarifJsonString() | ||
fs.writeFileSync(file, sarifJsonString, 'utf8') | ||
} | ||
async generateSarifFile(file: string) { | ||
const sarifJsonString = this.buildSarifJsonString(); | ||
await fs.writeFile(file, sarifJsonString, 'utf8'); | ||
async generateSarifFile (file: string) { | ||
const sarifJsonString = this.buildSarifJsonString() | ||
await fs.writeFile(file, sarifJsonString, 'utf8') | ||
} | ||
buildSarifOutput() { | ||
buildSarifOutput () { | ||
// Complete runs | ||
this.log.runs = this.log.runs.map(run => this.completeRunFields(run)); | ||
return this.log; | ||
this.log.runs = this.log.runs.map(run => this.completeRunFields(run)) | ||
return this.log | ||
} | ||
// Build final sarif json, complete when possible | ||
buildSarifJsonString(options = { indent: false }) { | ||
this.buildSarifOutput(); | ||
buildSarifJsonString (options = { indent: false }) { | ||
this.buildSarifOutput() | ||
const sarifJson = options.indent | ||
? JSON.stringify(this.log, null, 2) | ||
: JSON.stringify(this.log); | ||
: JSON.stringify(this.log) | ||
if (sarifJson.includes('SARIF_BUILDER_INVALID')) { | ||
throw new Error( | ||
'Your SARIF log is invalid, please solve SARIF_BUILDER_INVALID messages' | ||
); | ||
) | ||
} | ||
return sarifJson; | ||
return sarifJson | ||
} | ||
completeRunFields(run: Run): Run { | ||
completeRunFields (run: Run): Run { | ||
// Collect all missing artifacts from results | ||
run.artifacts = run.artifacts || []; | ||
run.artifacts = run.artifacts || [] | ||
for (const result of run.results) { | ||
@@ -65,4 +68,6 @@ for (const location of result.locations || []) { | ||
run.artifacts.filter(artifact => artifact?.location?.uri === location.physicalLocation.artifactLocation.uri).length === 0) { | ||
// Add result to driver artifact only if not existing | ||
run.artifacts.push({ location: { uri: location.physicalLocation.artifactLocation.uri } }); | ||
// Add result to driver artifact only if not existing | ||
const ext = path.extname(location.physicalLocation.artifactLocation.uri).replace('.', '') | ||
const language = EXTENSIONS_LANGUAGES[ext] || 'unknown' | ||
run.artifacts.push({ sourceLanguage: language, location: { uri: location.physicalLocation.artifactLocation.uri } }) | ||
} | ||
@@ -73,8 +78,9 @@ } | ||
const artifactIndexes = run.artifacts.map((artifact) => { | ||
return artifact?.location?.uri; | ||
}); | ||
return artifact?.location?.uri | ||
}) | ||
// Build rules indexes | ||
const rulesIndexes = (run?.tool?.driver?.rules || []).map((rule) => { | ||
return rule.id; | ||
}); | ||
return rule.id | ||
}) | ||
@@ -84,4 +90,4 @@ // Update index in results with computed values | ||
// Set rule index in results | ||
if (rulesIndexes[result.ruleId]) { | ||
result.ruleIndex = rulesIndexes[result.ruleId] | ||
if (rulesIndexes.indexOf(result.ruleId) > -1) { | ||
result.ruleIndex = rulesIndexes.indexOf(result.ruleId) | ||
} | ||
@@ -91,18 +97,14 @@ // Set artifact index in results | ||
result.locations = result.locations.map(location => { | ||
const uri = location?.physicalLocation?.artifactLocation?.uri; | ||
if (uri && artifactIndexes[uri] !== undefined && artifactIndexes[uri] !== null) { | ||
location.physicalLocation.artifactLocation.index = artifactIndexes[uri]; | ||
const uri = location?.physicalLocation?.artifactLocation?.uri | ||
if (uri && artifactIndexes.indexOf(uri) > -1) { | ||
location.physicalLocation.artifactLocation.index = artifactIndexes.indexOf(uri) | ||
} | ||
return location; | ||
}); | ||
return location | ||
}) | ||
} | ||
return result; | ||
return result | ||
}) | ||
return run; | ||
return run | ||
} | ||
} | ||
@@ -1,6 +0,6 @@ | ||
import { ArtifactLocation, Region, Result } from "sarif"; | ||
import { ArtifactLocation, Region, Result } from 'sarif' | ||
import { SarifResultOptions } from "../types/node-sarif-builder"; | ||
import { SarifResultOptions } from '../types/node-sarif-builder' | ||
import { setOptionValues } from "./utils"; | ||
import { setOptionValues } from './utils' | ||
@@ -10,14 +10,14 @@ export class SarifResultBuilder { | ||
result: Result = { | ||
level: 'error', | ||
message: {}, | ||
ruleId: | ||
'SARIF_BUILDER_INVALID: Please send the rule Id ruleId property, or call setRuleId(ruleId)', | ||
level: 'error', | ||
message: {}, | ||
ruleId: | ||
'SARIF_BUILDER_INVALID: Please send the rule Id ruleId property, or call setRuleId(ruleId)' | ||
}; | ||
// Initialize SARIF Result builder | ||
constructor(options: SarifResultOptions = {}) { | ||
setOptionValues(options, this.result); | ||
constructor (options: SarifResultOptions = {}) { | ||
setOptionValues(options, this.result) | ||
} | ||
initSimple(options: { | ||
initSimple (options: { | ||
level: Result.level; | ||
@@ -32,62 +32,62 @@ messageText: string; | ||
}) { | ||
this.setLevel(options.level); | ||
this.setMessageText(options.messageText); | ||
this.setRuleId(options.ruleId); | ||
if (options.fileUri) { | ||
this.setLocationArtifactUri({ uri: options.fileUri }); | ||
this.setLevel(options.level) | ||
this.setMessageText(options.messageText) | ||
this.setRuleId(options.ruleId) | ||
if (options.fileUri) { | ||
this.setLocationArtifactUri({ uri: options.fileUri }) | ||
} | ||
if (options.startLine !== null && options.startLine !== undefined) { | ||
// Initialize Region with default values with necessary | ||
const region: Region = { | ||
startLine: options.startLine, | ||
startColumn: options.startColumn || 1, | ||
endLine: options.endLine || options.startLine, | ||
endColumn: options.endColumn || 1 | ||
} | ||
if (options.startLine !== null) { | ||
// Initialize Region with default values with necessary | ||
const region: Region = { | ||
startLine: options.startLine, | ||
startColumn: options.startColumn || 1, | ||
endLine: options.endLine || options.startLine, | ||
endColumn: options.endColumn || 1, | ||
}; | ||
// Check for invalid region values | ||
if (options.startLine === 0 || options.startColumn === 0 || options.endLine === 0 || options.endColumn === 0) { | ||
throw new Error("Region limit can not be 0 (minimum line 1 or column 1) in " + JSON.stringify(options)); | ||
} | ||
this.setLocationRegion(region); | ||
// Check for invalid region values | ||
if (options.startLine === 0 || options.startColumn === 0 || options.endLine === 0 || options.endColumn === 0) { | ||
throw new Error('Region limit can not be 0 (minimum line 1 or column 1) in ' + JSON.stringify(options)) | ||
} | ||
return this; | ||
this.setLocationRegion(region) | ||
} | ||
return this | ||
} | ||
setLevel(level: Result.level) { | ||
this.result.level = level; | ||
setLevel (level: Result.level) { | ||
this.result.level = level | ||
} | ||
setMessageText(message: string) { | ||
this.result.message.text = message; | ||
setMessageText (message: string) { | ||
this.result.message.text = message | ||
} | ||
setRuleId(ruleId: string) { | ||
this.result.ruleId = ruleId; | ||
setRuleId (ruleId: string) { | ||
this.result.ruleId = ruleId | ||
} | ||
setLocationRegion(region: Region) { | ||
this.manageInitPhysicalLocation(); | ||
this.result.locations[0].physicalLocation.region = region; | ||
setLocationRegion (region: Region) { | ||
this.manageInitPhysicalLocation() | ||
this.result.locations[0].physicalLocation.region = region | ||
} | ||
setLocationArtifactUri(artifactLocation: ArtifactLocation) { | ||
this.manageInitPhysicalLocation(); | ||
this.result.locations[0].physicalLocation.artifactLocation = | ||
artifactLocation; | ||
setLocationArtifactUri (artifactLocation: ArtifactLocation) { | ||
this.manageInitPhysicalLocation() | ||
this.result.locations[0].physicalLocation.artifactLocation = | ||
artifactLocation | ||
} | ||
private manageInitLocation() { | ||
if (this.result?.locations?.length) { | ||
return; | ||
} | ||
this.result.locations = [{}]; | ||
private manageInitLocation () { | ||
if (this.result?.locations?.length) { | ||
return | ||
} | ||
this.result.locations = [{}] | ||
} | ||
private manageInitPhysicalLocation() { | ||
this.manageInitLocation(); | ||
if (this.result?.locations[0].physicalLocation) { | ||
return; | ||
} | ||
this.result.locations[0].physicalLocation = {}; | ||
private manageInitPhysicalLocation () { | ||
this.manageInitLocation() | ||
if (this.result?.locations[0].physicalLocation) { | ||
return | ||
} | ||
this.result.locations[0].physicalLocation = {} | ||
} | ||
} | ||
} |
@@ -1,6 +0,6 @@ | ||
import { ReportingDescriptor } from "sarif"; | ||
import { ReportingDescriptor } from 'sarif' | ||
import { SarifRuleOptions } from "../types/node-sarif-builder"; | ||
import { SarifRuleOptions } from '../types/node-sarif-builder' | ||
import { setOptionValues } from "./utils"; | ||
import { setOptionValues } from './utils' | ||
@@ -12,14 +12,14 @@ /* | ||
rule: ReportingDescriptor = { | ||
id: 'SARIF_BUILDER_INVALID: Please send the rule identifier in id property, or call setRuleId(ruleId)', | ||
shortDescription: { | ||
text: "SARIF_BUILDER_INVALID: Please send the rule text in shortDescription.text property, or call setShortDescriptionText(text)" | ||
} | ||
id: 'SARIF_BUILDER_INVALID: Please send the rule identifier in id property, or call setRuleId(ruleId)', | ||
shortDescription: { | ||
text: 'SARIF_BUILDER_INVALID: Please send the rule text in shortDescription.text property, or call setShortDescriptionText(text)' | ||
} | ||
}; | ||
// Initialize SARIF Run builder | ||
constructor(options: SarifRuleOptions = {}) { | ||
setOptionValues(options, this.rule); | ||
constructor (options: SarifRuleOptions = {}) { | ||
setOptionValues(options, this.rule) | ||
} | ||
initSimple(options: { | ||
initSimple (options: { | ||
ruleId: string; | ||
@@ -30,31 +30,31 @@ shortDescriptionText: string; | ||
}) { | ||
this.setRuleId(options.ruleId); | ||
if (options.shortDescriptionText) { | ||
this.setShortDescriptionText(options.shortDescriptionText); | ||
} | ||
if (options.fullDescriptionText) { | ||
this.setFullDescriptionText(options.fullDescriptionText); | ||
} | ||
if (options.helpUri) { | ||
this.setHelpUri(options.helpUri); | ||
} | ||
return this; | ||
this.setRuleId(options.ruleId) | ||
if (options.shortDescriptionText) { | ||
this.setShortDescriptionText(options.shortDescriptionText) | ||
} | ||
if (options.fullDescriptionText) { | ||
this.setFullDescriptionText(options.fullDescriptionText) | ||
} | ||
if (options.helpUri) { | ||
this.setHelpUri(options.helpUri) | ||
} | ||
return this | ||
} | ||
setRuleId(ruleId: string) { | ||
this.rule.id = ruleId; | ||
setRuleId (ruleId: string) { | ||
this.rule.id = ruleId | ||
} | ||
setShortDescriptionText(shortDescriptionText: string) { | ||
this.rule.shortDescription.text = shortDescriptionText; | ||
setShortDescriptionText (shortDescriptionText: string) { | ||
this.rule.shortDescription.text = shortDescriptionText | ||
} | ||
setFullDescriptionText(fullDescriptionText: string) { | ||
this.rule.fullDescription = this.rule.fullDescription || { text: "" }; | ||
this.rule.fullDescription.text = fullDescriptionText; | ||
setFullDescriptionText (fullDescriptionText: string) { | ||
this.rule.fullDescription = this.rule.fullDescription || { text: '' } | ||
this.rule.fullDescription.text = fullDescriptionText | ||
} | ||
setHelpUri(url: string) { | ||
this.rule.helpUri = url; | ||
setHelpUri (url: string) { | ||
this.rule.helpUri = url | ||
} | ||
} | ||
} |
@@ -1,8 +0,8 @@ | ||
import { Run } from "sarif"; | ||
import { Run } from 'sarif' | ||
import { SarifRuleBuilder } from ".."; | ||
import { SarifRunOptions } from "../types/node-sarif-builder"; | ||
import { SarifRuleBuilder } from '..' | ||
import { SarifRunOptions } from '../types/node-sarif-builder' | ||
import { SarifResultBuilder } from "./sarif-result-builder"; | ||
import { setOptionValues } from "./utils"; | ||
import { SarifResultBuilder } from './sarif-result-builder' | ||
import { setOptionValues } from './utils' | ||
@@ -13,41 +13,46 @@ // SARIF Run builder | ||
run: Run = { | ||
tool: { | ||
driver: { | ||
name: | ||
tool: { | ||
driver: { | ||
name: | ||
process.env.npm_package_name || | ||
'SARIF_BUILDER_INVALID: Please send the tool name in tool.driver.name property, or call setToolName(name)', | ||
rules: [], | ||
}, | ||
}, | ||
results: [], | ||
rules: [] | ||
} | ||
}, | ||
results: [] | ||
}; | ||
// Initialize SARIF Run builder | ||
constructor(options: SarifRunOptions = {}) { | ||
setOptionValues(options, this.run); | ||
constructor (options: SarifRunOptions = {}) { | ||
setOptionValues(options, this.run) | ||
} | ||
initSimple(options: { name: string; url?: string }) { | ||
this.setToolDriverName(options.name); | ||
if (options.url) { | ||
this.setToolDriverUri(options.url); | ||
} | ||
return this; | ||
initSimple (options: { toolDriverName: string; toolDriverVersion: string, url?: string }) { | ||
this.setToolDriverName(options.toolDriverName) | ||
this.setToolDriverVersion(options.toolDriverVersion) | ||
if (options.url) { | ||
this.setToolDriverUri(options.url) | ||
} | ||
return this | ||
} | ||
addRule(sarifRuleBuilder: SarifRuleBuilder) { | ||
this.run.tool.driver.rules.push(sarifRuleBuilder.rule); | ||
addRule (sarifRuleBuilder: SarifRuleBuilder) { | ||
this.run.tool.driver.rules.push(sarifRuleBuilder.rule) | ||
} | ||
addResult(sarifResultBuilder: SarifResultBuilder) { | ||
this.run.results.push(sarifResultBuilder.result); | ||
addResult (sarifResultBuilder: SarifResultBuilder) { | ||
this.run.results.push(sarifResultBuilder.result) | ||
} | ||
setToolDriverName(name: string) { | ||
this.run.tool.driver.name = name; | ||
setToolDriverName (name: string) { | ||
this.run.tool.driver.name = name | ||
} | ||
setToolDriverUri(url: string) { | ||
this.run.tool.driver.informationUri = url; | ||
setToolDriverVersion (version: string) { | ||
this.run.tool.driver.version = version | ||
} | ||
} | ||
setToolDriverUri (url: string) { | ||
this.run.tool.driver.informationUri = url | ||
} | ||
} |
@@ -1,8 +0,8 @@ | ||
export function setOptionValues(options, object: any) { | ||
for (const key of Object.keys(object)) { | ||
if (options[key] !== undefined) { | ||
object[key] = options[key]; | ||
} | ||
export function setOptionValues (options, object: any) { | ||
for (const key of Object.keys(object)) { | ||
if (options[key] !== undefined) { | ||
object[key] = options[key] | ||
} | ||
return object; | ||
} | ||
return object | ||
} |
@@ -35,4 +35,4 @@ import { | ||
WebRequest, | ||
WebResponse, | ||
} from 'sarif'; | ||
WebResponse | ||
} from 'sarif' | ||
@@ -301,3 +301,2 @@ export interface LogOptions { | ||
export interface SarifResultOptions { | ||
@@ -304,0 +303,0 @@ /** |
@@ -13,2 +13,2 @@ { | ||
"typeRoots": ["node_modules/@types", "src/types"] | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
339739
51
4809
218
1