Skip to content

Commit 6be3f85

Browse files
authored
Merge pull request #40 from suitcss/beforelint-refactor
Remove beforeLint
2 parents 7b8526d + bea8ff1 commit 6be3f85

File tree

8 files changed

+29
-137
lines changed

8 files changed

+29
-137
lines changed

.eslintrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
"comma-dangle": [2, "never"],
77
"max-len": 0,
88
"func-names": 0,
9-
"one-var": [2, { uninitialized: "always", initialized: "never" }],
9+
"one-var": [2, { "uninitialized": "always", "initialized": "never" }],
1010
"no-param-reassign": [0],
1111
"no-use-before-define": [2, "nofunc"],
1212
"space-before-function-paren": 0,
13-
"object-curly-spacing": 0
13+
"object-curly-spacing": 0,
14+
"global-require": 0
1415
}
1516
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### HEAD
22

3+
* Remove `beforeLint` feature
34
* Add default browsers list for autoprefixer
45
* Use `stylelint-config-suitcss` from within the preprocessor. No longer needs
56
to be installed locally by the consumer.

README.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,24 +126,6 @@ locally in your package.
126126

127127
If set to `true` then the output is minified by [`cssnano`](http://cssnano.co/).
128128

129-
##### `beforeLint`
130-
131-
* Type: `Function`
132-
* Default: `undefined`
133-
134-
Called with the imported CSS before it's passed to `postcss-bem-linter`. This allows you to transform the CSS first and it must return the css string.
135-
136-
Third paramater is the options object containing any PostCSS configuration you may need.
137-
138-
```js
139-
{
140-
beforeLint(css, filename, options) {
141-
// Do something to the imported css
142-
return css;
143-
}
144-
}
145-
```
146-
147129
##### `postcss`
148130

149131
* Type: `Object`
@@ -157,7 +139,6 @@ Options that are passed directly to `postcss`, as per [the documentation](https:
157139
}
158140
```
159141

160-
161142
##### `use`
162143

163144
* Type: `Array`

lib/index.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/**
2-
* Module dependencies
3-
*/
41
var assign = require('object-assign-deep');
52
var isEmpty = require('lodash.isempty');
63
var difference = require('lodash.difference');
@@ -11,10 +8,6 @@ var reporter = require('postcss-reporter');
118
var stylelint = require('stylelint');
129
var stylelintConfigSuit = require('stylelint-config-suitcss');
1310

14-
/**
15-
* Module export
16-
*/
17-
1811
module.exports = preprocessor;
1912

2013
/**
@@ -92,34 +85,27 @@ function preprocessor(css, options) {
9285

9386
function mergeOptions(options) {
9487
options = options || {};
95-
96-
var merged = assign({}, defaults, options);
88+
var mergedOpts = assign({}, defaults, options);
9789

9890
// Set some core options
99-
if (merged.root) {
100-
merged['postcss-easy-import'].root = merged.root;
91+
if (mergedOpts.root) {
92+
mergedOpts['postcss-easy-import'].root = mergedOpts.root;
10193
}
10294

103-
// Call beforeLint function and pass processed css to bem-linter
104-
var beforeLint = merged.beforeLint;
105-
merged['postcss-easy-import'].transform = function(css, filename) {
106-
if (typeof beforeLint === 'function') {
107-
css = beforeLint(css, filename, merged);
108-
}
109-
110-
return lintImportedFiles(merged, css, filename).then(function(result) {
95+
mergedOpts['postcss-easy-import'].transform = function(css, filename) {
96+
return lintImportedFiles(mergedOpts, css, filename).then(function(result) {
11197
return result.css;
11298
});
11399
};
114100

115101
// Allow additional plugins to be merged with the defaults
116102
// but remove any duplicates so that it respects the new order
117103
if (!isEmpty(options.use)) {
118-
var plugins = difference(merged.use, options.use);
119-
merged.use = plugins.concat(options.use);
104+
var plugins = difference(mergedOpts.use, options.use);
105+
mergedOpts.use = plugins.concat(options.use);
120106
}
121107

122-
return merged;
108+
return mergedOpts;
123109
}
124110

125111
/**

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
"devDependencies": {
3636
"chai": "^3.4.1",
3737
"chai-as-promised": "^5.2.0",
38-
"eslint": "^1.10.3",
39-
"eslint-config-airbnb": "^5.0.0",
38+
"eslint": "^3.5.0",
39+
"eslint-config-airbnb": "^11.1.0",
4040
"mocha": "^2.3.4",
4141
"postcss-property-lookup": "^1.1.4",
4242
"rewire": "^2.5.1",
@@ -45,9 +45,10 @@
4545
"sinon-chai": "^2.8.0"
4646
},
4747
"scripts": {
48-
"test": "npm run lint && mocha --reporter spec --slow 400 --timeout 8000",
48+
"test": "npm run mocha && npm run lint",
49+
"mocha": "mocha --reporter spec --slow 400 --timeout 8000",
4950
"lint": "eslint lib/index.js test/test.js bin/suitcss",
50-
"watch": "mocha --watch --reporter spec --slow 400"
51+
"watch": "npm run mocha -- --watch"
5152
},
5253
"keywords": [
5354
"css",

test/.eslintrc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"extends": "../.eslintrc",
3-
"globals": {
4-
"it": true,
5-
"describe": true,
6-
"afterEach": true,
7-
"beforeEach": true
3+
"env": {
4+
"mocha": true
85
},
96
"rules": {
10-
"no-unused-expressions": 0
7+
"no-unused-expressions": 0,
8+
"no-underscore-dangle": 0,
9+
"consistent-return": 0,
10+
"one-var-declaration-per-line": 0
1111
}
1212
}

test/test.config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
module.exports = {
2-
beforeLint: function (css) {
3-
console.log('beforeLint ran');
4-
return css;
5-
},
62
use: [
73
"postcss-property-lookup"
84
],

test/test.js

Lines changed: 6 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ describe('suitcss', function() {
2727
});
2828

2929
it('should handle invalid input', function() {
30-
expect(function() {suitcss(null);}).to.throw(TypeError);
30+
expect(function() {
31+
suitcss(null);
32+
}).to.throw(TypeError);
3133
});
3234

3335
describe('using options', function() {
@@ -197,77 +199,6 @@ describe('suitcss', function() {
197199
).to.be.rejectedWith(Error, 'postcss-reporter: warnings or errors were found');
198200
});
199201
});
200-
201-
describe('transforming css before linting', function() {
202-
describe('ensuring functions are called correctly', function() {
203-
var lintImportedFilesStub, beforeLintStub, revert;
204-
205-
beforeEach(function() {
206-
var postcssPromise = sinon.stub().resolves('/*linting done*/')();
207-
lintImportedFilesStub = sinon.stub().returns(postcssPromise);
208-
beforeLintStub = sinon.stub().returns('/*before lint*/');
209-
revert = suitcss.__set__('lintImportedFiles', lintImportedFilesStub);
210-
});
211-
212-
afterEach(function() {
213-
revert();
214-
});
215-
216-
it('should call `beforeLint` function before linting', function(done) {
217-
suitcss(read('fixtures/component'), {
218-
root: 'test/fixtures',
219-
beforeLint: beforeLintStub
220-
})
221-
.then(function() {
222-
expect(beforeLintStub).to.be.calledOnce;
223-
expect(lintImportedFilesStub).to.be.calledOnce;
224-
expect(beforeLintStub).to.have.been.calledBefore(lintImportedFilesStub);
225-
done();
226-
})
227-
.catch(done);
228-
});
229-
230-
it('should pass the result of `beforeLint` to `lintImportedFiles`', function(done) {
231-
suitcss(read('fixtures/component'), {
232-
root: 'test/fixtures',
233-
beforeLint: beforeLintStub
234-
})
235-
.then(function() {
236-
expect(lintImportedFilesStub.args[0][1]).to.equal('/*before lint*/');
237-
done();
238-
})
239-
.catch(done);
240-
});
241-
242-
it('should pass the options object to the beforeLint function as the third parameter', function(done) {
243-
suitcss(read('fixtures/component'), {
244-
root: 'test/fixtures',
245-
beforeLint: beforeLintStub
246-
})
247-
.then(function() {
248-
expect(beforeLintStub.args[0][2]).to.contain({root: 'test/fixtures'});
249-
done();
250-
})
251-
.catch(done);
252-
});
253-
});
254-
255-
describe('outputting transformed css', function() {
256-
it('should use the CSS returned from beforeLint', function(done) {
257-
suitcss(read('fixtures/import'), {
258-
root: 'test/fixtures',
259-
beforeLint: function() {
260-
return 'body {}';
261-
}
262-
})
263-
.then(function(result) {
264-
expect(result.css).to.equal('body {}\n');
265-
done();
266-
})
267-
.catch(done);
268-
});
269-
});
270-
});
271202
});
272203
});
273204

@@ -338,7 +269,6 @@ describe('cli', function() {
338269
var testChild = exec('node bin/suitcss -c test/noautoprefixer.config.js', function(err, stdout) {
339270
if (err) return done(err);
340271
expect(stdout).to.equal(output);
341-
expect(stdout).to.not.contain('beforeLint ran');
342272
done();
343273
});
344274

@@ -350,18 +280,16 @@ describe('cli', function() {
350280
exec('node bin/suitcss -v -c test/noautoprefixer.config.js test/fixtures/cli/input.css test/fixtures/cli/output.css', function(err, stdout) {
351281
if (err) return done(err);
352282
expect(stdout).to.contain('write');
353-
expect(stdout).to.not.contain('beforeLint ran');
354283
done();
355284
});
356285
});
357286

358287
it('should allow configurable import root', function(done) {
359-
exec('node bin/suitcss -i test/fixtures -c test/noautoprefixer.config.js test/fixtures/import.css test/fixtures/cli/output.css', function(err, stdout) {
288+
exec('node bin/suitcss -i test/fixtures -c test/noautoprefixer.config.js test/fixtures/import.css test/fixtures/cli/output.css', function(err) {
360289
if (err) return done(err);
361290
var res = read('fixtures/cli/output');
362291
var expected = read('fixtures/component.out');
363292
expect(res).to.equal(expected);
364-
expect(stdout).to.not.contain('beforeLint ran');
365293
done();
366294
});
367295
});
@@ -375,22 +303,20 @@ describe('cli', function() {
375303
});
376304

377305
it('should minify the output', function(done) {
378-
exec('node bin/suitcss -i test/fixtures -c test/noautoprefixer.config.js test/fixtures/import.css test/fixtures/cli/output.css -m', function(err, stdout) {
306+
exec('node bin/suitcss -i test/fixtures -c test/noautoprefixer.config.js test/fixtures/import.css test/fixtures/cli/output.css -m', function(err) {
379307
if (err) return done(err);
380308
var res = read('fixtures/cli/output');
381309
var expected = read('fixtures/minify.out');
382-
expect(stdout).to.not.contain('beforeLint ran');
383310
expect(res).to.equal(expected);
384311
done();
385312
});
386313
});
387314

388315
it('should allow a config file to be passed', function(done) {
389-
exec('node bin/suitcss -i test/fixtures -c test/test.config.js test/fixtures/config.css test/fixtures/cli/output.css', function(err, stdout) {
316+
exec('node bin/suitcss -i test/fixtures -c test/test.config.js test/fixtures/config.css test/fixtures/cli/output.css', function(err) {
390317
if (err) return done(err);
391318
var res = read('fixtures/cli/output');
392319
var expected = read('fixtures/config.out');
393-
expect(stdout).to.contain('beforeLint ran');
394320
expect(res).to.equal(expected);
395321
done();
396322
});

0 commit comments

Comments
 (0)