Skip to content

Commit

Permalink
Lint code with ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Mar 14, 2015
1 parent 22416cb commit 709200a
Show file tree
Hide file tree
Showing 50 changed files with 970 additions and 937 deletions.
26 changes: 26 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"ecmaFeatures": {
"modules": true,
"module": true
},
"rules": {
"no-unused-expressions": [0],
"no-underscore-dangle": [0],
"no-reserved-keys": [2],
"no-multi-spaces": [0],
"no-extra-parens": [2],
"no-unused-vars": [1],
"no-loop-func": [0],
"key-spacing": [0],
"max-len": [2],
"strict": [0],
"indent": [2],
"quotes": [2, "single", "avoid-escape"],
"curly": [0]
},
"env": {
"mocha": true,
"node": true,
"es6": true
}
}
5 changes: 3 additions & 2 deletions benchmark/parser.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
var fs = require('fs');
var path = require('path');
var fs = require('fs');

var tokenizer = require('../build/lib/tokenize');
var Parser = require('../build/lib/parser');
var Input = require('../build/lib/input');

var css = fs.readFileSync(__dirname + '/test.css');
var css = fs.readFileSync(path.join(__dirname, 'test.css'));
var input = new Input(css);
var tokens = tokenizer(input);

Expand Down
13 changes: 8 additions & 5 deletions benchmark/parsers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
var fs = require('fs');
var css = fs.readFileSync(__dirname + '/cache/bootstrap.css').toString();
var path = require('path');
var fs = require('fs');

var example = path.join(__dirname, 'cache', 'bootstrap.css');
var css = fs.readFileSync(example).toString();

var CSSOM = require('cssom');
var rework = require('rework');
Expand All @@ -22,7 +25,7 @@ module.exports = {
{
name: 'PostCSS',
fn: function () {
postcss.parse(css).toResult().css;
postcss().parse(css, { from: example }).toResult();
}
},
{
Expand All @@ -32,7 +35,7 @@ module.exports = {
}
},
{
name: "Mensch",
name: 'Mensch',
fn: function () {
mensch.stringify( mensch.parse(css) );
}
Expand All @@ -45,7 +48,7 @@ module.exports = {
},
{
name: 'Gonzales PE',
fn: function (done) {
fn: function () {
gonzalesPe.parse(css).toString();
}
},
Expand Down
25 changes: 15 additions & 10 deletions benchmark/processors.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
var fs = require('fs');
var exec = require('child_process').exec;
var path = require('path');
var fs = require('fs');

var path = __dirname + '/cache/bootstrap.css';
var css = fs.readFileSync(path).toString();
var example = path.join(__dirname, 'cache', 'bootstrap.css');
var css = fs.readFileSync(example).toString();

css = css.replace(/\s+filter:[^;\}]+;?/g, '');
css = css.replace('/*# sourceMappingURL=bootstrap.css.map */', '');
var scss = __dirname + '/cache/bootstrap.scss';
var scss = path.join(__dirname, 'cache', 'bootstrap.scss');
fs.writeFileSync(scss, css);

var postcss = require('../build');
Expand All @@ -21,15 +22,18 @@ module.exports = {
tests: [
{
name: 'PostCSS',
defer: true,
fn: function (done) {
postcss(cssnext).process(css, { map: false }).css;
postcss(cssnext).process(css, { map: false }).then(function () {
done.resolve();
});
}
},
{
name: 'Stylus',
defer: true,
fn: function (done) {
stylus.render(css, { filename: path }, function (err, css) {
stylus.render(css, { filename: example }, function (err) {
if ( err ) throw err;
done.resolve();
});
Expand All @@ -39,7 +43,7 @@ module.exports = {
name: 'Less',
defer: true,
fn: function (done) {
less.render(css, function (err, css) {
less.render(css, function (err) {
if ( err ) throw err;
done.resolve();
});
Expand All @@ -56,11 +60,12 @@ module.exports = {
defer: true,
fn: function (done) {
var command = 'sass -C --sourcemap=none ' + scss;
exec('cd ' + __dirname + '; bundle exec ' + command,
function (error, stdout, stderr) {
var dir = __dirname;
exec('cd ' + dir + '; bundle exec ' + command,
function (error, stdout, stderr) {
if ( error ) throw stderr;
done.resolve();
});
});
}
}
]
Expand Down
5 changes: 3 additions & 2 deletions benchmark/tokenizer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
var fs = require('fs');
var path = require('path');
var fs = require('fs');

var tokenizer = require('../build/lib/tokenize');
var Input = require('../build/lib/input');

var css = fs.readFileSync(__dirname + '/test.css');
var css = fs.readFileSync(path.join(__dirname, 'test.css'));
var input = new Input(css);

module.exports = {
Expand Down
9 changes: 5 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,19 @@ gulp.task('standalone', ['build'], function (done) {
// Lint

gulp.task('lint', function () {
var jshint = require('gulp-jshint');
var eslint = require('gulp-eslint');

return gulp.src(['*.js',
'lib/*.js',
'test/*.js',
'tasks/*.js',
'benchmark/**/*.js'])
.pipe(jshint({ esnext: true, expr: true }))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});


// Benchmark

gulp.task('bench:clean', function (done) {
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var path = require('path');

var escape = function (str) {
return str.replace(/[\[\]\/{}()*+?.\\^$|-]/g, "\\$&");
return str.replace(/[\[\]\/{}()*+?.\\^$|-]/g, '\\$&');
};

var regexp = ['lib', 'test'].map(function (i) {
Expand Down
10 changes: 5 additions & 5 deletions lib/at-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export default class AtRule extends Container {
}

stringify(builder, semicolon) {
var name = '@' + this.name;
var params = this.params ? this.stringifyRaw('params') : '';
let name = '@' + this.name;
let params = this.params ? this.stringifyRaw('params') : '';

if ( typeof(this.afterName) != 'undefined' ) {
if ( typeof this.afterName !== 'undefined' ) {
name += this.afterName;
} else if ( params ) {
name += ' ';
Expand All @@ -20,9 +20,9 @@ export default class AtRule extends Container {
this.stringifyBlock(builder, name + params);

} else {
var before = this.style('before');
let before = this.style('before');
if ( before ) builder(before);
var end = (this.between || '') + (semicolon ? ';' : '');
let end = (this.between || '') + (semicolon ? ';' : '');
builder(name + params + end, this);
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export default class Comment extends Node {
}

stringify(builder) {
var before = this.style('before');
let before = this.style('before');
if ( before ) builder(before);
var left = this.style('left', 'commentLeft');
var right = this.style('right', 'commentRight');
let left = this.style('left', 'commentLeft');
let right = this.style('right', 'commentRight');
builder('/*' + left + this.text + right + '*/', this);
}
}
Loading

0 comments on commit 709200a

Please sign in to comment.