UNPKG

sonar-web-frontend-reporters

Version:

sreporter is a Command-Line Interface to generate Front-End linters reporters for the SonarQube plugin

129 lines (104 loc) 5.21 kB
"use strict"; 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'), jshintcli = require('jshint/src/cli'), jshint = require('jshint').JSHINT, ReporterType = require('../reporter.enum'), Reporter = require('../reporter'); module.exports = /*#__PURE__*/ function (_Reporter) { _inherits(JSHintReporter, _Reporter); function JSHintReporter(options, projectName) { var _this; _classCallCheck(this, JSHintReporter); _this = _possibleConstructorReturn(this, _getPrototypeOf(JSHintReporter).call(this, options, projectName)); _this.linterName = 'JSHint'; return _this; } _createClass(JSHintReporter, [{ key: "launch", value: function launch(done) { var _this2 = this; this.options.jshint = jshintcli.loadConfig(this.options.rulesFile); delete this.options.jshint.dirname; this.options.globals = this.options.jshint.globals; delete this.options.jshint.globals; glob(this.options.src, function (er, 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(); fileArray.forEach(function (file) { _this3.processFile(file, options); }); } }, { key: "processFile", value: function processFile(file, options) { var input = this.readFile(file), severity; jshint(input, options.jshint, options.globals); this.openFileIssues(file, null, /^(\s+)?\n$/gm); var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = jshint.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var message = _step.value; switch (message.id) { case '(error)': severity = this.MAJOR; break; case undefined: severity = this.BLOCKER; break; default: severity = this.INFO; break; } this.addIssue(message.line ? message.line : null, message.reason, message.raw, message.code, severity, ReporterType.JSHINT); } } 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/jshint.json', rulesFile: '.jshintrc' }; } }]); return JSHintReporter; }(Reporter);