|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | var postcss = require('postcss'); |
| 4 | +var bemLinter = require('postcss-bem-linter'); |
4 | 5 | var logWarnings = require('..'); |
5 | 6 | var fs = require('fs'); |
6 | 7 |
|
7 | | -var rejectColors = postcss.plugin('reject-colors', function() { |
8 | | - return function(css, result) { |
9 | | - css.eachDecl(function(decl) { |
10 | | - if (decl.prop === 'color') { |
11 | | - result.warn('no colors allowed', { node: decl }); |
12 | | - } |
13 | | - }); |
14 | | - }; |
15 | | -}); |
16 | | - |
17 | | -var rejectBackgrounds = postcss.plugin('reject-backgrounds', function() { |
18 | | - return function(css, result) { |
19 | | - css.eachDecl(function(decl) { |
20 | | - if (decl.prop === 'background') { |
21 | | - result.warn('no backgrounds allowed', { node: decl }); |
22 | | - } |
23 | | - }); |
24 | | - }; |
25 | | -}); |
26 | | - |
27 | | -fs.readFile('test/forVisual.css', { encoding: 'utf8' }, function(err, data) { |
28 | | - if (err) throw err; |
| 8 | +fs.readFile('test/forVisual.css', { encoding: 'utf8' }, function(readErr, data) { |
| 9 | + if (readErr) throw readErr; |
29 | 10 | postcss() |
30 | | - .use(rejectColors()) |
31 | | - .use(rejectBackgrounds()) |
| 11 | + .use(bemLinter()) |
32 | 12 | .use(logWarnings({ throwError: true })) |
33 | 13 | .process(data, { from: 'test/forVisual.css' }) |
34 | 14 | .then(function() { |
| 15 | + console.error('`throwError: true` failed!'); |
| 16 | + }) |
| 17 | + .catch(function(ourErr) { |
| 18 | + console.log(ourErr); |
35 | 19 | console.log('There\'s your visual confirmation that it works.'); |
36 | 20 | }); |
37 | 21 | }); |
0 commit comments