Skip to content

Commit

Permalink
refactor: pull out errorMessage constant
Browse files Browse the repository at this point in the history
  • Loading branch information
JaKXz committed Jan 17, 2017
1 parent 4e47a5e commit d0635bb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

module.exports = {
defaultFilesGlob: '**/*.s?(c|a)ss'
defaultFilesGlob: '**/*.s?(c|a)ss',
errorMessage: 'Failed because of a stylelint error.\n'
};
5 changes: 3 additions & 2 deletions lib/run-compilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var chalk = require('chalk');
var linter = require('./linter');
var errorMessage = require('./constants').errorMessage;

/**
* Function bound to the plugin `apply` method to run the linter and report any
Expand Down Expand Up @@ -31,14 +32,14 @@ module.exports = function runCompilation (options, compiler, done) {
}

if (options.failOnError && errors.length) {
done(new Error('Failed because of a stylelint error.\n'));
done(new Error(errorMessage));
} else {
done();
}
})
.catch(done);

compiler.plugin('after-emit', function onCompilation (compilation, callback) {
compiler.plugin('after-emit', function afterEmit (compilation, callback) {
if (warnings.length) {
compilation.warnings.push(chalk.yellow(options.formatter(warnings)));
warnings = [];
Expand Down
3 changes: 2 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var webpack = require('./helpers/webpack');
var baseConfig = require('./helpers/base-config');

var configFilePath = getPath('./.stylelintrc');
var errorMessage = require('../lib/constants').errorMessage;

describe('stylelint-webpack-plugin', function () {
it('works with a simple file', function () {
Expand Down Expand Up @@ -52,7 +53,7 @@ describe('stylelint-webpack-plugin', function () {
return pack(assign({}, baseConfig, config))
.then(expect.fail)
.catch(function (err) {
expect(err.message).to.equal('Failed because of a stylelint error.\n');
expect(err.message).to.equal(errorMessage);
});
});

Expand Down

0 comments on commit d0635bb

Please sign in to comment.