Skip to content

Commit bcd36d5

Browse files
committed
Merge pull request #25 from suitcss/upgrade-stylelint
Upgrade stylelint
2 parents 01119df + 5111714 commit bcd36d5

File tree

4 files changed

+60
-41
lines changed

4 files changed

+60
-41
lines changed

lib/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ function mergeOptions(options) {
9191
var merged = assign({}, defaults, options);
9292

9393
// Set some core options
94-
merged['postcss-import'].root = merged.root;
94+
if (merged.root) {
95+
merged['postcss-import'].root = merged.root;
96+
}
9597

9698
// Call beforeLint function and pass processed css to bem-linter
9799
var beforeLint = merged.beforeLint;
@@ -130,5 +132,5 @@ function lintImportedFiles(options, css, filename) {
130132
.use(bemLinter(options['postcss-bem-linter']))
131133
.use(reporter(options['postcss-reporter']));
132134

133-
return processor.process(css, {from: filename}).css;
135+
return processor.process(css, {from: filename});
134136
}

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,32 @@
1717
"commander": "~2.9.0",
1818
"cssnano": "^3.3.2",
1919
"fs-extra": "^0.26.2",
20-
"lodash.difference": "^3.2.2",
21-
"lodash.isempty": "^3.0.4",
20+
"lodash.difference": "^4.0.2",
21+
"lodash.isempty": "^4.1.1",
2222
"object-assign-deep": "0.0.4",
2323
"pad-component": "0.0.1",
2424
"postcss": "^5.0.12",
2525
"postcss-bem-linter": "^2.3.0",
2626
"postcss-calc": "^5.0.0",
2727
"postcss-custom-media": "^5.0.0",
2828
"postcss-custom-properties": "^5.0.0",
29-
"postcss-import": "^7.1.3",
29+
"postcss-import": "^8.0.2",
3030
"postcss-reporter": "^1.3.0",
31-
"read-file-stdin": "0.2.0",
32-
"stylelint": "^2.3.5"
31+
"read-file-stdin": "^0.2.1",
32+
"stylelint": "^4.2.0"
3333
},
3434
"devDependencies": {
3535
"chai": "^3.4.1",
36+
"chai-as-promised": "^5.2.0",
3637
"eslint": "^1.10.3",
3738
"eslint-config-airbnb": "^5.0.0",
3839
"mocha": "^2.3.4",
3940
"postcss-property-lookup": "^1.1.4",
4041
"rewire": "^2.5.1",
4142
"sinon": "^1.17.2",
43+
"sinon-as-promised": "^4.0.0",
4244
"sinon-chai": "^2.8.0",
43-
"stylelint-config-suitcss": "^1.0.0"
45+
"stylelint-config-suitcss": "^3.0.0"
4446
},
4547
"scripts": {
4648
"test": "npm run lint && mocha --reporter spec --slow 400 --timeout 3000",

test/error.config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"postcss-reporter": {
3-
"throwError": true,
4-
"plugins": ["postcss-bem-linter"]
3+
"throwError": true
54
}
65
}

test/test.js

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ var rewire = require('rewire');
77
var suitcss = rewire('../lib');
88
var path = require('path');
99
var sinonChai = require('sinon-chai');
10+
var chaiAsPromised = require('chai-as-promised');
11+
require('sinon-as-promised');
1012

1113
chai.use(sinonChai);
14+
chai.use(chaiAsPromised);
1215
var expect = chai.expect;
1316

1417
/**
@@ -151,27 +154,37 @@ describe('suitcss', function() {
151154
});
152155

153156
describe('stylelint', function() {
154-
it('should check the input conforms to SUIT style rules', function(done) {
155-
suitcss('@import "./stylelint.css"', {
156-
lint: true,
157-
root: 'test/fixtures',
158-
'postcss-reporter': {
159-
throwError: true
160-
}
161-
}).then(function() {
162-
done(new Error('stylelint should have failed conformance'));
163-
}).catch(function(err) {
164-
expect(err.message).to.contain('postcss-reporter: warnings or errors were found');
165-
done();
166-
});
157+
it('should lint the component', function() {
158+
return expect(
159+
suitcss(read('fixtures/component'), {
160+
lint: true,
161+
root: 'test/fixtures',
162+
'postcss-reporter': {
163+
throwError: true
164+
}
165+
})
166+
).to.be.fulfilled;
167+
});
168+
169+
it('should throw an error if stylelint fails', function() {
170+
return expect(
171+
suitcss('@import "./stylelint.css"', {
172+
lint: true,
173+
root: 'test/fixtures',
174+
'postcss-reporter': {
175+
throwError: true
176+
}
177+
})
178+
).to.be.rejectedWith(Error, 'postcss-reporter: warnings or errors were found');
167179
});
168180
});
169181

170182
describe('transforming css before linting', function() {
171183
var lintImportedFilesStub, beforeLintStub, revert;
172184

173185
beforeEach(function() {
174-
lintImportedFilesStub = sinon.stub().returns('/*linting done*/');
186+
var postcssPromise = sinon.stub().resolves('/*linting done*/')();
187+
lintImportedFilesStub = sinon.stub().returns(postcssPromise);
175188
beforeLintStub = sinon.stub().returns('/*before lint*/');
176189
revert = suitcss.__set__('lintImportedFiles', lintImportedFilesStub);
177190
});
@@ -184,35 +197,38 @@ describe('suitcss', function() {
184197
suitcss(read('fixtures/component'), {
185198
root: 'test/fixtures',
186199
beforeLint: beforeLintStub
187-
}).catch(done);
188-
189-
expect(lintImportedFilesStub).to.be.calledOnce;
190-
expect(beforeLintStub).to.be.calledOnce;
191-
expect(beforeLintStub).to.have.been.calledBefore(lintImportedFilesStub);
192-
193-
done();
200+
})
201+
.then(function() {
202+
expect(beforeLintStub).to.be.calledOnce;
203+
expect(lintImportedFilesStub).to.be.calledOnce;
204+
expect(beforeLintStub).to.have.been.calledBefore(lintImportedFilesStub);
205+
done();
206+
})
207+
.catch(done);
194208
});
195209

196210
it('should pass the result of `beforeLint` to `lintImportedFiles`', function(done) {
197211
suitcss(read('fixtures/component'), {
198212
root: 'test/fixtures',
199213
beforeLint: beforeLintStub
200-
}).catch(done);
201-
202-
expect(lintImportedFilesStub.args[0][1]).to.equal('/*before lint*/');
203-
204-
done();
214+
})
215+
.then(function() {
216+
expect(lintImportedFilesStub.args[0][1]).to.equal('/*before lint*/');
217+
done();
218+
})
219+
.catch(done);
205220
});
206221

207222
it('should pass the options object to the beforeLint function as the third parameter', function(done) {
208223
suitcss(read('fixtures/component'), {
209224
root: 'test/fixtures',
210225
beforeLint: beforeLintStub
211-
}).catch(done);
212-
213-
expect(beforeLintStub.args[0][2]).to.contain({root: 'test/fixtures'});
214-
215-
done();
226+
})
227+
.then(function() {
228+
expect(beforeLintStub.args[0][2]).to.contain({root: 'test/fixtures'});
229+
done();
230+
})
231+
.catch(done);
216232
});
217233
});
218234
});

0 commit comments

Comments
 (0)