Skip to content

Commit 33f1686

Browse files
author
epavlenko
committed
Refactor a bit
1 parent d200f1d commit 33f1686

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

index.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@ var fs = require('fs');
22
var path = require('path');
33
var postcss = require('postcss');
44

5-
var message = 'Regexp matched with';
5+
var messageText = 'Regexp matched with';
66
var regexp;
77

8-
module.exports = postcss.plugin('postcss-regexp', function(options) {
8+
module.exports = postcss.plugin('postcss-regexp', function(options, t) {
99
return function(css, result) {
1010
if (!options.regexp) {
11-
result.messages.push({
12-
type: 'error',
13-
plugin: 'postcss-regexp',
14-
text:'No regexp provided'
15-
});
11+
throwOptionsError(result);
1612
return;
1713
}
18-
message = options.message ? options.message : message;
14+
messageText = options.message ? options.message : messageText;
1915
regexp = options.regexp;
2016

2117
css.eachDecl(function(decl) {
@@ -25,10 +21,20 @@ module.exports = postcss.plugin('postcss-regexp', function(options) {
2521
})
2622
}
2723
});
24+
function throwOptionsError(result){
25+
result.messages.push({
26+
type: 'error',
27+
plugin: 'postcss-regexp',
28+
text: 'No regexp provided'
29+
});
30+
}
2831

2932
function processDecl(decl, result) {
3033
var value = decl.value;
34+
3135
if (value.search(regexp) === 0) {
32-
result.warn(message +' ' + value + ' on line ' + decl.source.start.line);
36+
var message = messageText + ' ' + value
37+
+ ' on line ' + decl.source.start.line;
38+
result.warn(message);
3339
}
3440
}

0 commit comments

Comments
 (0)