Commit da78ae95 authored by Philipp Nowinski's avatar Philipp Nowinski

[FEATURE] unify linting output and get rid of misleading messages

parent e1bd89fa
'use strict';
const logger = require('./logger');
const chalk = require('chalk');
const path = require('path');
const logSymbols = require('log-symbols');
/**
* This module formats Linting results
*/
module.exports = class LintingFormatter {
static format(_error) {
let formattedMessage = '';
formattedMessage += logger.getTimestamp();
formattedMessage += ' ';
formattedMessage += logSymbols.warning;
formattedMessage += ' ';
formattedMessage += chalk.bgYellow(chalk.black(` ${path.relative(process.cwd(), _error.filePath)} `));
formattedMessage += '\n';
_error.messages.forEach((_message) => {
let position = `L ${_message.line}:${_message.column}`;
let positionLength = position.length;
for (let index = 10; index > positionLength; index--) {
position = ' ' + position;
}
formattedMessage += `${chalk.white(position)} ${chalk.yellow('')} ${_message.message}` +
`${chalk.white(` (Violated rule ${chalk.italic(_message.ruleId)})`)}`;
});
return formattedMessage;
}
};
......@@ -10,6 +10,7 @@ const util = require('util');
const chalk = require('chalk');
const stylelint = require('stylelint');
const reporter = require('postcss-reporter');
const LintingFormatter = require('../lintingFormatter');
const scss = require('postcss-scss');
const postcssClean = require('postcss-clean');
const globImporter = require('node-sass-glob-importer');
......@@ -213,8 +214,20 @@ module.exports = class Css extends Task {
configBasedir: `${process.cwd()}/sgc-core/`
}),
reporter({
clearReportedMessages: true,
throwError: true
formatter: (_input) => {
let error = {
filePath: _input.source,
messages: _input.messages.map((message) => {
return {
message: message.text.replace(` (${message.rule})`, ''),
line: message.line,
column: message.column,
ruleId: message.rule
}
})
};
return `\n${LintingFormatter.format(error)}\n`;
}
})
]).process(file, {
from: _input,
......@@ -222,7 +235,10 @@ module.exports = class Css extends Task {
}).then(() => {
resolve();
}).catch(error => {
this._logger.displayNotification('SGC css:qa task', 'You have some linting-errors in your CSS. Please fix them!');
this._logger.displayNotification(
'SGC css:qa task',
'You have some linting-errors in your CSS. Please fix them!'
);
resolve();
});
});
......
......@@ -8,7 +8,8 @@ const globby = require('globby');
const browserify = require('browserify');
const babelify = require('babelify');
const tinyify = require('tinyify');
const CLIEngine = require("eslint").CLIEngine;
const CLIEngine = require('eslint').CLIEngine;
const LintingFormatter = require('../lintingFormatter');
const exorcist = require('exorcist');
const browserSync = require('browser-sync');
......@@ -190,12 +191,22 @@ module.exports = class Js extends Task {
envs: ['browser'],
useEslintrc: true
});
let formatter = cli.getFormatter();
let report = cli.executeOnFiles(_files);
if (report.errorCount > 0) {
this._logger.displayNotification('SGC js:qa task', 'You have some linting-errors in your JavaScript. Please fix them!');
}
console.log(formatter(report.results));
let foundError = 0;
report.results.forEach((_error) => {
if (_error.errorCount > 0 || _error.warningCount > 0) {
foundError = true;
console.log();
console.log(LintingFormatter.format(_error));
}
});
if (foundError) {
console.log();
}
resolve();
});
}
......
{
"name": "sgc",
"version": "3.5.0",
"version": "3.5.9",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment