Skip to content

Commit ad2c4df

Browse files
committed
Merge pull request #19 from suitcss/eslint
Add ESLint
2 parents 078908e + 9e37773 commit ad2c4df

File tree

6 files changed

+77
-54
lines changed

6 files changed

+77
-54
lines changed

.eslintrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "airbnb/legacy",
3+
"rules": {
4+
"vars-on-top": 0,
5+
"no-console": 0,
6+
"comma-dangle": [2, "never"],
7+
"func-names": 0,
8+
"one-var": [2, { uninitialized: "always", initialized: "never" }],
9+
"no-param-reassign": [0],
10+
"no-use-before-define": [2, "nofunc"]
11+
}
12+
}

bin/suitcss

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ program
3030
* Examples.
3131
*/
3232

33-
program.on('--help', function () {
33+
program.on('--help', function() {
3434
console.log(' Examples:');
3535
console.log();
3636
console.log(' # pass an input and output file:');
@@ -103,23 +103,23 @@ if (regen) {
103103
/**
104104
* Run for the given input and output.
105105
*/
106-
function run () {
107-
read(input, function (err, buffer) {
106+
function run() {
107+
read(input, function(err, buffer) {
108108
if (err) logger.throw(err);
109109
var css = buffer.toString();
110110
var opts = assign({}, {
111-
minify: program.minify,
112-
root: program.importRoot,
113-
lint: program.lint
114-
}, config);
111+
minify: program.minify,
112+
root: program.importRoot,
113+
lint: program.lint
114+
}, config);
115115

116116
suitcss(css, opts).then(function(result) {
117117
if (output) {
118118
writeFileSync(output, result.css + '\n');
119119
} else {
120120
console.log(result.css);
121121
}
122-
if (verbose && output) logger.log('write', output);
122+
if (verbose && output) logger.log('write', output);
123123
}).catch(function(e) {
124124
logger.throw(e);
125125
});

lib/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
var assign = require('object-assign-deep');
55
var isEmpty = require('lodash.isempty');
66
var difference = require('lodash.difference');
7-
var autoprefixer = require('autoprefixer');
87
var bemLinter = require('postcss-bem-linter');
98
var postcss = require('postcss');
109
var cssnano = require('cssnano');
@@ -41,7 +40,7 @@ var defaults = {
4140
}
4241
},
4342
'postcss-reporter': {
44-
clearMessages: true
43+
clearMessages: true
4544
},
4645
// http://cssnano.co/optimisations/
4746
cssnano: {
@@ -63,9 +62,9 @@ var defaults = {
6362
function preprocessor(css, options) {
6463
options = mergeOptions(options);
6564

66-
var plugins = options.use.map(function (p) {
65+
var plugins = options.use.map(function(p) {
6766
var plugin = require(p);
68-
settings = options[p];
67+
var settings = options[p];
6968

7069
return settings ? plugin(settings) : plugin;
7170
});
@@ -135,4 +134,3 @@ function lintImportedFiles(options) {
135134
return processor.process(css, {from: filename}).css;
136135
};
137136
}
138-

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@
3434
},
3535
"devDependencies": {
3636
"chai": "^3.4.1",
37+
"eslint": "^1.10.2",
38+
"eslint-config-airbnb": "^1.0.2",
3739
"mocha": "^2.3.4",
3840
"postcss-property-lookup": "^1.1.4",
3941
"rewire": "^2.5.0",
4042
"sinon": "^1.17.2"
4143
},
4244
"scripts": {
43-
"test": "mocha --reporter spec --slow 400",
45+
"test": "npm run lint && mocha --reporter spec --slow 400",
46+
"lint": "eslint lib/index.js test/test.js bin/suitcss",
4447
"watch": "mocha --watch --reporter spec --slow 400"
4548
},
4649
"keywords": [

test/.eslintrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../.eslintrc",
3+
"globals": {
4+
"it": true,
5+
"describe": true,
6+
"afterEach": true,
7+
"beforeEach": true
8+
},
9+
"rules": {
10+
"no-unused-expressions": 0
11+
}
12+
}

test/test.js

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ var expect = require('chai').expect;
22
var sinon = require('sinon');
33
var child = require('child_process');
44
var exec = child.exec;
5-
var spawn = child.spawn;
65
var fs = require('fs');
76
var rewire = require('rewire');
87
var suitcss = rewire('../lib');
@@ -12,8 +11,8 @@ var path = require('path');
1211
* Node API tests.
1312
*/
1413

15-
describe('suitcss', function () {
16-
it('should return a css string', function (done) {
14+
describe('suitcss', function() {
15+
it('should return a css string', function(done) {
1716
suitcss('body {}').then(function(result) {
1817
expect(result.css).to.be.a('string');
1918
done();
@@ -119,13 +118,12 @@ describe('suitcss', function () {
119118
describe('stylelint', function() {
120119
it('should check the input conforms to SUIT style rules', function(done) {
121120
suitcss('@import ./stylelint.css', {
122-
lint: true,
123-
root: 'test/fixtures',
124-
'postcss-reporter': {
125-
throwError: true
126-
}
121+
lint: true,
122+
root: 'test/fixtures',
123+
'postcss-reporter': {
124+
throwError: true
127125
}
128-
).then(function(result) {
126+
}).then(function() {
129127
done(new Error('stylelint should have failed conformance'));
130128
}).catch(function(err) {
131129
expect(err.message).to.contain('postcss-reporter: warnings or errors were found');
@@ -150,7 +148,7 @@ describe('suitcss', function () {
150148
revert();
151149
});
152150

153-
it('should call user supplied function before linting', function (done) {
151+
it('should call user supplied function before linting', function(done) {
154152
suitcss(read('fixtures/component'), {
155153
root: 'test/fixtures',
156154
beforeLint: beforeLintStub
@@ -163,7 +161,7 @@ describe('suitcss', function () {
163161
done();
164162
});
165163

166-
it('should pass processed CSS to the linting transform function', function (done) {
164+
it('should pass processed CSS to the linting transform function', function(done) {
167165
suitcss(read('fixtures/component'), {
168166
root: 'test/fixtures',
169167
beforeLint: beforeLintStub
@@ -174,7 +172,7 @@ describe('suitcss', function () {
174172
done();
175173
});
176174

177-
it('should pass the merged options to the beforeLint function', function (done) {
175+
it('should pass the merged options to the beforeLint function', function(done) {
178176
suitcss(read('fixtures/component'), {
179177
root: 'test/fixtures',
180178
beforeLint: beforeLintStub
@@ -192,8 +190,8 @@ describe('suitcss', function () {
192190
* Feature tests.
193191
*/
194192

195-
describe('features', function () {
196-
it('should preprocess CSS correctly', function (done) {
193+
describe('features', function() {
194+
it('should preprocess CSS correctly', function(done) {
197195
var input = read('fixtures/component');
198196
var output = read('fixtures/component.out');
199197

@@ -208,54 +206,54 @@ describe('features', function () {
208206
* CLI tests.
209207
*/
210208

211-
describe('cli', function () {
209+
describe('cli', function() {
212210
var input = read('fixtures/cli/input');
213211
var output = read('fixtures/cli/input.out');
214212

215-
afterEach(function () {
213+
afterEach(function() {
216214
remove('fixtures/cli/output');
217215
});
218216

219-
it('should read from a file and write to a file', function (done) {
220-
exec('bin/suitcss test/fixtures/cli/input.css test/fixtures/cli/output.css', function (err, stdout) {
217+
it('should read from a file and write to a file', function(done) {
218+
exec('bin/suitcss test/fixtures/cli/input.css test/fixtures/cli/output.css', function(err) {
221219
if (err) return done(err);
222220
var res = read('fixtures/cli/output');
223221
expect(res).to.equal(output);
224222
done();
225223
});
226224
});
227225

228-
it('should read from a file and write to stdout', function (done) {
229-
exec('bin/suitcss test/fixtures/cli/input.css', function (err, stdout) {
226+
it('should read from a file and write to stdout', function(done) {
227+
exec('bin/suitcss test/fixtures/cli/input.css', function(err, stdout) {
230228
if (err) return done(err);
231229
expect(stdout).to.equal(output);
232230
done();
233231
});
234232
});
235233

236-
it('should read from stdin and write to stdout', function (done) {
237-
var child = exec('bin/suitcss', function (err, stdout) {
234+
it('should read from stdin and write to stdout', function(done) {
235+
var testChild = exec('bin/suitcss', function(err, stdout) {
238236
if (err) return done(err);
239237
expect(stdout).to.equal(output);
240238
expect(stdout).to.not.contain('beforeLint ran');
241239
done();
242240
});
243241

244-
child.stdin.write(new Buffer(input));
245-
child.stdin.end();
242+
testChild.stdin.write(new Buffer(input));
243+
testChild.stdin.end();
246244
});
247245

248-
it('should log on verbose', function (done) {
249-
exec('bin/suitcss -v test/fixtures/cli/input.css test/fixtures/cli/output.css', function (err, stdout) {
246+
it('should log on verbose', function(done) {
247+
exec('bin/suitcss -v test/fixtures/cli/input.css test/fixtures/cli/output.css', function(err, stdout) {
250248
if (err) return done(err);
251249
expect(stdout).to.contain('write');
252250
expect(stdout).to.not.contain('beforeLint ran');
253251
done();
254252
});
255253
});
256254

257-
it('should allow configurable import root', function (done) {
258-
exec('bin/suitcss -i test/fixtures test/fixtures/import.css test/fixtures/cli/output.css', function (err, stdout) {
255+
it('should allow configurable import root', function(done) {
256+
exec('bin/suitcss -i test/fixtures test/fixtures/import.css test/fixtures/cli/output.css', function(err, stdout) {
259257
if (err) return done(err);
260258
var res = read('fixtures/cli/output');
261259
var expected = read('fixtures/component.out');
@@ -265,16 +263,16 @@ describe('cli', function () {
265263
});
266264
});
267265

268-
it('should output stylelint warnings', function (done) {
269-
exec('bin/suitcss -i test/fixtures test/fixtures/stylelint-import.css test/fixtures/cli/output.css -l', function (err, stdout) {
266+
it('should output stylelint warnings', function(done) {
267+
exec('bin/suitcss -i test/fixtures test/fixtures/stylelint-import.css test/fixtures/cli/output.css -l', function(err, stdout) {
270268
if (err) return done(err);
271269
expect(stdout).to.contain('Expected property "box-sizing" to come before property "flex"');
272270
done();
273271
});
274272
});
275273

276-
it('should minify the output', function (done) {
277-
exec('bin/suitcss -i test/fixtures test/fixtures/import.css test/fixtures/cli/output.css -m', function (err, stdout) {
274+
it('should minify the output', function(done) {
275+
exec('bin/suitcss -i test/fixtures test/fixtures/import.css test/fixtures/cli/output.css -m', function(err, stdout) {
278276
if (err) return done(err);
279277
var res = read('fixtures/cli/output');
280278
var expected = read('fixtures/minify.out');
@@ -284,8 +282,8 @@ describe('cli', function () {
284282
});
285283
});
286284

287-
it('should allow a config file to be passed', function (done) {
288-
exec('bin/suitcss -i test/fixtures -c test/test.config.js test/fixtures/config.css test/fixtures/cli/output.css', function (err, stdout) {
285+
it('should allow a config file to be passed', function(done) {
286+
exec('bin/suitcss -i test/fixtures -c test/test.config.js test/fixtures/config.css test/fixtures/cli/output.css', function(err, stdout) {
289287
if (err) return done(err);
290288
var res = read('fixtures/cli/output');
291289
var expected = read('fixtures/config.out');
@@ -296,16 +294,16 @@ describe('cli', function () {
296294
});
297295

298296
it('should output an error to stderr on conformance failure when throwError is set', function(done) {
299-
exec('bin/suitcss -i test/fixtures -c test/error.config.json test/fixtures/import-error.css test/fixtures/cli/output.css', function (err, stdout, stderr) {
297+
exec('bin/suitcss -i test/fixtures -c test/error.config.json test/fixtures/import-error.css test/fixtures/cli/output.css', function(err, stdout, stderr) {
300298
expect(err).to.be.an('error');
301299
expect(err.code).to.equal(1);
302300
expect(stderr).to.contain('postcss-reporter: warnings or errors were found');
303301
done();
304302
});
305303
});
306304

307-
it('should log on non-existant file', function (done) {
308-
exec('bin/suitcss test/fixtures/cli/non-existant.css', function (err, stdout, stderr) {
305+
it('should log on non-existant file', function(done) {
306+
exec('bin/suitcss test/fixtures/cli/non-existant.css', function(err, stdout, stderr) {
309307
expect(err).to.be.an('error');
310308
expect(err.code).to.equal(1);
311309
expect(stderr).to.contain('not found');
@@ -321,7 +319,7 @@ describe('cli', function () {
321319
* @return {String}
322320
*/
323321

324-
function read (filename) {
322+
function read(filename) {
325323
var file = resolve(filename);
326324
return fs.readFileSync(file, 'utf8');
327325
}
@@ -332,7 +330,7 @@ function read (filename) {
332330
* @param {String} filename
333331
*/
334332

335-
function remove (filename) {
333+
function remove(filename) {
336334
var file = resolve(filename);
337335
if (!fs.existsSync(file)) return;
338336
fs.unlinkSync(file);
@@ -345,6 +343,6 @@ function remove (filename) {
345343
* @return {String}
346344
*/
347345

348-
function resolve (filename) {
346+
function resolve(filename) {
349347
return path.resolve(__dirname, filename + '.css');
350348
}

0 commit comments

Comments
 (0)