gulp-scss-lint = function (options) { options = options || {}; options.format = 'JSON'; if (options.reporterOutputFormat === 'Checkstyle') { options.format = 'Checkstyle'; options.require = 'scss_lint_reporter_checkstyle'; } if (options.exclude) { throw new gutil.PluginError(PLUGIN_NAME, "You must use gulp src to exclude"); } var lint = function(stream, files) { scssLint(stream, files, options) .then(function() { if (!options.endless) { stream.emit('end'); } }, function(e) { var err = new gutil.PluginError(PLUGIN_NAME, e); stream.emit('error', err); stream.emit('end'); }) .done(function(e) {}); }; var getStream = function() { var files = []; var writeStream = function(currentFile){ if (options.endless) { lint(stream, [currentFile]); } else { files.push(currentFile); } }; var endStream = function() { if (options.endless) { return; } if (!files.length) { stream.emit('end'); return; } lint(stream, files); }; var stream = es.through(writeStream, endStream); return stream; }; var getNewStream = function() { var stream = new Readable({objectMode: true}); stream._read = function () {}; lint(stream, [options.src]); return stream; }; if (options.src) { return getNewStream(); } return getStream(); }
n/a
defaultReporter = function (file) { if (!file.scsslint.success) { gutil.log(colors.cyan(file.scsslint.issues.length) + ' issues found in ' + colors.magenta(file.path)); file.scsslint.issues.forEach(function (issue) { var severity = issue.severity === 'warning' ? colors.yellow(' [W] ') : colors.red(' [E] '); var linter = issue.linter ? (issue.linter + ': ') : ''; var logMsg = colors.cyan(file.relative) + ':' + colors.magenta(issue.line) + severity + colors.green(linter) + issue.reason; gutil.log(logMsg); }); } }
...
}
files[i].scsslint = lintResult;
if (options.customReport) {
options.customReport(files[i], stream);
} else {
reporters.defaultReporter(files[i]);
}
if (!options.filePipeOutput) {
if (options.src) {
stream.push(files[i]);
} else {
stream.emit('data', files[i]);
...
failReporter = function (severity) { return es.map(function(file, cb) { var error; if (!file.scsslint.success) { if (!severity || severity === 'E' && file.scsslint.errors > 0) { error = new gutil.PluginError('gulp-scss-lint', { message: 'ScssLint failed for: ' + file.relative, showStack: false }); } } cb(error, file); }); }
...
```js
var scsslint = require('gulp-scss-lint');
gulp.task('scss-lint', function() {
return gulp.src('/scss/*.scss')
.pipe(scsslint())
.pipe(scsslint.failReporter())
});
```
if you just want `failReporter` to fail just with errors pass the 'E' string
```js
var scsslint = require('gulp-scss-lint');
...
toJSON = function (report, cb) { var obj = {}; var xmlReport = pd.xml(report); var error = []; xml2js(xmlReport, function(err, report) { report.checkstyle.file = report.checkstyle.file || []; report.checkstyle.file.forEach(function(file) { obj[file.$.name] = []; file.error.forEach(function(error) { error.$.linter = error.$.source; error.$.reason = error.$.message; obj[file.$.name].push(error.$); }); }); cb([obj, xmlReport]); }); }
...
}
} else if (error && error.code === 1 && report.length === 0) {
reject('Error code ' + error.code + '\n' + error);
} else {
if (options.format === 'JSON'){
resolve([JSON.parse(report)]);
} else {
checkstyle.toJSON(report, resolve);
}
}
});
});
}
module.exports = function(filePaths, options) {
...
defaultReporter = function (file) { if (!file.scsslint.success) { gutil.log(colors.cyan(file.scsslint.issues.length) + ' issues found in ' + colors.magenta(file.path)); file.scsslint.issues.forEach(function (issue) { var severity = issue.severity === 'warning' ? colors.yellow(' [W] ') : colors.red(' [E] '); var linter = issue.linter ? (issue.linter + ': ') : ''; var logMsg = colors.cyan(file.relative) + ':' + colors.magenta(issue.line) + severity + colors.green(linter) + issue.reason; gutil.log(logMsg); }); } }
...
}
files[i].scsslint = lintResult;
if (options.customReport) {
options.customReport(files[i], stream);
} else {
reporters.defaultReporter(files[i]);
}
if (!options.filePipeOutput) {
if (options.src) {
stream.push(files[i]);
} else {
stream.emit('data', files[i]);
...
failReporter = function (severity) { return es.map(function(file, cb) { var error; if (!file.scsslint.success) { if (!severity || severity === 'E' && file.scsslint.errors > 0) { error = new gutil.PluginError('gulp-scss-lint', { message: 'ScssLint failed for: ' + file.relative, showStack: false }); } } cb(error, file); }); }
...
```js
var scsslint = require('gulp-scss-lint');
gulp.task('scss-lint', function() {
return gulp.src('/scss/*.scss')
.pipe(scsslint())
.pipe(scsslint.failReporter())
});
```
if you just want `failReporter` to fail just with errors pass the 'E' string
```js
var scsslint = require('gulp-scss-lint');
...