Skip to content

Commit

Permalink
ESLint.Formatter - Add eslint version to run.tool.driver #2070
Browse files Browse the repository at this point in the history
  • Loading branch information
tosmolka committed Sep 15, 2020
1 parent 9870138 commit 0335691
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/ESLint.Formatter/sarif.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,28 @@ const lodash = require("lodash");
const fs = require("fs");
const utf8 = require("utf8");
const jschardet = require("jschardet");
const url = require('url')
const url = require('url');

//------------------------------------------------------------------------------
// Helper Functions
//------------------------------------------------------------------------------

/**
* Returns the version of used eslint package
* @returns {string} eslint version or undefined
* @private
*/
function getESLintVersion() {
try {
// Resolve ESLint relative to main entry script, not the formatter
const { ESLint } = require.main.require('eslint');
return ESLint.version;
} catch (err) {
// Formatter was not called from eslint, return undefined
return undefined;
}
}

/**
* Returns the severity of warning or error
* @param {Object} message message object to examine
Expand Down Expand Up @@ -52,6 +68,11 @@ module.exports = function (results, data) {
]
};

const eslintVersion = getESLintVersion();
if (typeof eslintVersion !== "undefined") {
sarifLog.runs[0].tool.driver.version = eslintVersion;
}

const sarifFiles = {};
const sarifArtifactIndices = {};
let nextArtifactIndex = 0;
Expand Down
1 change: 1 addition & 0 deletions src/ESLint.Formatter/test/sarif.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe("formatter:sarif", () => {

assert.strictEqual(log.runs[0].tool.driver.name, "ESLint");
assert.strictEqual(log.runs[0].tool.driver.informationUri, "https://eslint.org");
assert.strictEqual(log.runs[0].tool.driver.version, undefined);
})
});

Expand Down

0 comments on commit 0335691

Please sign in to comment.