sonar-web-frontend-reporters
Version:
sreporter is a Command-Line Interface to generate Front-End linters reporters for the SonarQube plugin
128 lines (103 loc) • 5.25 kB
JavaScript
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
var glob = require('glob-all'),
CLIEngine = require('eslint').CLIEngine,
ReporterType = require('../reporter.enum'),
Reporter = require('../reporter');
module.exports =
/*#__PURE__*/
function (_Reporter) {
_inherits(ESLintAngularReporter, _Reporter);
function ESLintAngularReporter(options, projectName) {
var _this;
_classCallCheck(this, ESLintAngularReporter);
_this = _possibleConstructorReturn(this, _getPrototypeOf(ESLintAngularReporter).call(this, options, projectName));
_this.linterName = 'ESLint Angular';
return _this;
}
_createClass(ESLintAngularReporter, [{
key: "launch",
value: function launch(done) {
var _this2 = this;
this.linter = new CLIEngine({
configFile: this.options.rulesFile,
ignorePath: this.options.ignorePath
});
glob(this.options.src, function (err, files) {
_this2.processFiles(files, _this2.options);
_this2.closeReporter(_this2.options.report);
if (typeof done === 'function') {
done();
}
});
}
}, {
key: "processFiles",
value: function processFiles(fileArray, options) {
var _this3 = this;
this.openReporter(options.report);
var linterResult = this.linter.executeOnFiles(fileArray);
linterResult.results.forEach(function (fileResult) {
_this3.processFileResult(fileResult);
});
}
}, {
key: "processFileResult",
value: function processFileResult(file) {
var severity;
this.openFileIssues(file.filePath, null, /^(\s+)?\n$/gm);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = file.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var message = _step.value;
switch (message.severity) {
case 2:
severity = this.MAJOR;
break;
case 1:
severity = this.MINOR;
break;
default:
severity = this.INFO;
break;
}
this.addIssue(message.line ? message.line : null, message.message, '', "ng_".concat(message.ruleId.replace('angular/', '').replace(/-/g, '_')), severity, ReporterType.ESLINTANGULAR);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
_iterator["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
}], [{
key: "defaultOptions",
value: function defaultOptions() {
return {
src: 'src/**/*.js',
report: 'reports/sonar/eslint-angular.json',
rulesFile: '.eslintrc',
ignorePath: '.eslintignore'
};
}
}]);
return ESLintAngularReporter;
}(Reporter);
;