Skip to content

Commit b40772d

Browse files
author
Vitaly Puzrin
committed
coding style & eslint settings update
1 parent 30b25de commit b40772d

21 files changed

+46
-45
lines changed

.eslintrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ rules:
3333
no-lonely-if: 2
3434
no-multi-spaces: 0
3535
no-process-exit: 0
36+
no-path-concat: 2
3637
no-trailing-spaces: 2
3738
no-underscore-dangle: 0
3839
quotes: [ 2, single, avoid-escape ]
3940
radix: 2
4041
space-after-keywords: [ 2, always ] # Fixed in master
4142
space-in-brackets: [ 2, always, { propertyName: false } ]
43+
yoda: 2
4244

4345
# temporary
44-
yoda: 0
45-
no-path-concat: 0
4646
consistent-return: 0
4747

4848
#

bin/mincer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ if (args.output) {
113113
}
114114

115115

116-
if (1 === filenames.length) {
116+
if (filenames.length === 1) {
117117
var asset = environment.findAsset(filenames[0]);
118118

119119
if (!asset) {

examples/manifest.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
var Mincer = require('..');
11+
var path = require('path');
1112

1213

1314
//
@@ -23,7 +24,7 @@ var environment = require('./environment');
2324
//
2425

2526

26-
var manifest = new Mincer.Manifest(environment, __dirname + '/public/assets');
27+
var manifest = new Mincer.Manifest(environment, path.join(__dirname, 'public', 'assets'));
2728

2829

2930
try {

examples/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ app.use('/assets/', Mincer.createServer(environment));
4848
var view;
4949

5050
try {
51-
view = fs.readFileSync(__dirname + '/views/layout.jade', 'utf8');
51+
view = fs.readFileSync(path.join(__dirname, 'views', 'layout.jade'), 'utf8');
5252
view = jade.compile(view);
5353
} catch (err) {
5454
console.error('Failed compile view: ' + (err.message || err.toString()));

lib/mincer/asset_attributes.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ getter(AssetAttributes.prototype, 'searchPaths', function () {
5151
}, this.pathname);
5252

5353
// optimization: bower.json can only be nested one level deep
54-
if (-1 === path_without_extensions.indexOf(path.sep)) {
54+
if (path_without_extensions.indexOf(path.sep) === -1) {
5555
paths.push(path.join(path_without_extensions, 'bower.json'));
5656
}
5757

58-
if ('index' !== path.basename(this.pathname, exts)) {
58+
if (path.basename(this.pathname, exts) !== 'index') {
5959
paths.push(path.join(path_without_extensions, 'index' + exts));
6060
}
6161

@@ -165,7 +165,7 @@ getter(AssetAttributes.prototype, 'engineExtensions', function () {
165165
exts = this.extensions,
166166
offset = exts.indexOf(this.formatExtension);
167167

168-
if (0 <= offset) {
168+
if (offset >= 0) {
169169
exts = exts.slice(offset + 1);
170170
}
171171

lib/mincer/assets/asset.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function typeToClass(type) {
4545
var Asset = module.exports = function Asset(environment, logicalPath, pathname) {
4646
var mtime;
4747

48-
if ('' === path.extname(logicalPath)) {
48+
if (path.extname(logicalPath) === '') {
4949
throw new Error('Asset logical path has no extension: ' + logicalPath);
5050
}
5151

@@ -267,7 +267,7 @@ Asset.fromHash = function (environment, hash) {
267267

268268
return asset;
269269
} catch (e) {
270-
if ('unserialize_error' === e.code) {
270+
if (e.code === 'unserialize_error') {
271271
// do nothing
272272
return;
273273
}

lib/mincer/assets/processed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function buildRequiredAssets(self, context) {
7272
assets = resolveDependencies(self, paths),
7373
stubs = resolveDependencies(self, context.__stubbedAssets__);
7474

75-
if (0 < stubs.length) {
75+
if (stubs.length > 0) {
7676
// exclude stubbed assets if any
7777
assets = _.filter(assets, function (path) {
7878
return -1 === stubs.indexOf(path);

lib/mincer/base.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ Base.prototype.resolve = function (logicalPath, options, fn) {
224224
while (bower.main.length) {
225225
mainfile = bower.main[0];
226226

227-
if ('' === extname || extname === path.extname(mainfile)) {
227+
if (extname === '' || extname === path.extname(mainfile)) {
228228
return fn(path.join(path.dirname(pathname), mainfile));
229229
}
230230
}
@@ -334,12 +334,12 @@ Base.prototype.findAsset = function (pathname, options) {
334334
try {
335335
pathname = this.resolve(logical_path);
336336

337-
if ('' === path.extname(logical_path)) {
337+
if (path.extname(logical_path) === '') {
338338
expanded_path = this.attributesFor(pathname).logicalPath;
339339
logical_path += path.extname(expanded_path);
340340
}
341341
} catch (err) {
342-
if ('FileNotFound' === err.code) {
342+
if (err.code === 'FileNotFound') {
343343
return null;
344344
}
345345

@@ -414,7 +414,7 @@ Base.prototype.eachFile = function (iterator) {
414414

415415
// Returns true if there were no filters, or `filename` matches at least one
416416
function matches_filter(filters, logicalPath, filename) {
417-
if (0 === filters.length) {
417+
if (filters.length === 0) {
418418
return true;
419419
}
420420

@@ -430,15 +430,15 @@ function matches_filter(filters, logicalPath, filename) {
430430
// prepare string to become RegExp.
431431
// mimics shell's globbing
432432
filter = filter.toString().replace(/\*\*|\*|\?|\\.|\./g, function (m) {
433-
if ('*' === m[0]) {
434-
return '**' === m ? '.+?' : '[^/]+?';
433+
if (m[0] === '*') {
434+
return m === '**' ? '.+?' : '[^/]+?';
435435
}
436436

437-
if ('?' === m[0]) {
437+
if (m[0] === '?') {
438438
return '[^/]?';
439439
}
440440

441-
if ('.' === m[0]) {
441+
if (m[0] === '.') {
442442
return '\\.';
443443
}
444444

@@ -462,7 +462,7 @@ function logical_path_for_filename(self, filename, filters) {
462462
}
463463

464464
// If filename is an index file, retest with alias
465-
if ('index' === path.basename(filename).split('.').shift()) {
465+
if (path.basename(filename).split('.').shift() === 'index') {
466466
logical_path = logical_path.replace(/\/index\./, '.');
467467
if (matches_filter(filters, logical_path, filename)) {
468468
return logical_path;
@@ -501,11 +501,11 @@ var circular_calls = null;
501501

502502

503503
function circular_call_protection(pathname, callback) {
504-
var reset = (null === circular_calls),
504+
var reset = (circular_calls === null),
505505
calls = circular_calls || (circular_calls = []);
506506

507507
try {
508-
if (0 <= calls.indexOf(pathname)) {
508+
if (calls.indexOf(pathname) >= 0) {
509509
throw new Error('Circular dependency detected: ' + pathname +
510510
' has already been required');
511511
}
@@ -529,7 +529,7 @@ Base.prototype.buildAsset = function (logicalPath, pathname, options) {
529529
// If there are any processors to run on the pathname, use
530530
// `BundledAsset`. Otherwise use `StaticAsset` and treat is as binary.
531531

532-
if (0 === this.attributesFor(pathname).processors.length) {
532+
if (this.attributesFor(pathname).processors.length === 0) {
533533
return new StaticAsset(this.index, logicalPath, pathname);
534534
}
535535

lib/mincer/common.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ module.exports.normalizeExtension = function (extension) {
4747

4848
// Dummy alternative to Ruby's Pathname#is_absolute
4949
module.exports.isAbsolute = function (pathname) {
50-
if ('/' === path.sep) {
50+
if (path.sep === '/') {
5151
// unix
52-
return '/' === pathname[0];
52+
return pathname[0] === '/';
5353
}
5454

5555
// win
56-
return 0 <= pathname.indexOf(':');
56+
return pathname.indexOf(':') >= 0;
5757
};
5858

5959

lib/mincer/context.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ Context.prototype.resolve = function (pathname, options, fn) {
259259
content_type = options.contentType;
260260

261261
if (content_type) {
262-
if ('~self~' === content_type) {
262+
if (content_type === '~self~') {
263263
content_type = self.contentType;
264264
}
265265

@@ -434,7 +434,7 @@ Context.prototype.evaluate = function (pathname, options) {
434434
_.forEach(this.__helpers__, function (payload, name) {
435435
var helper = payload.helper;
436436

437-
if ('function' === typeof helper && 'stylus' !== payload.options.type) {
437+
if (typeof helper === 'function' && payload.options.type !== 'stylus') {
438438
helper = helper.bind(self);
439439
}
440440

lib/mincer/engines/coffee_engine.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ CoffeeEngine.prototype.evaluate = function (context/*, locals*/) {
7070
var loc, compileOpts, result;
7171

7272
compileOpts = _.extend({}, options, {
73-
literate: '.litcoffee' === extname(this.file)
73+
literate: extname(this.file) === '.litcoffee'
7474
});
7575

7676
try {

lib/mincer/engines/ejs_engine.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ require('util').inherits(EjsEngine, Template);
4242

4343
// Render data
4444
EjsEngine.prototype.evaluate = function (context, locals) {
45-
if (this.nextProcessor && 'JstEngine' === this.nextProcessor.name) {
45+
if (this.nextProcessor && this.nextProcessor.name === 'JstEngine') {
4646
this.data = ejs.compile(this.data, {
4747
filename: context.logicalPath,
4848
client: true

lib/mincer/engines/handlebars_engine.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ require('util').inherits(HandlebarsEngine, Template);
5353
HandlebarsEngine.prototype.evaluate = function (context, locals) {
5454
var data = this.data;
5555

56-
if (this.nextProcessor && 'JstEngine' === this.nextProcessor.name) {
56+
if (this.nextProcessor && this.nextProcessor.name === 'JstEngine') {
5757
data = Handlebars.precompile(data, _.clone(locals));
5858
this.data = 'Handlebars.template(' + data + ')';
5959
return;

lib/mincer/engines/jade_engine.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ JadeEngine.configure = function (opts) {
7474

7575
// Render data
7676
JadeEngine.prototype.evaluate = function (context, locals) {
77-
if (this.nextProcessor && 'JstEngine' === this.nextProcessor.name) {
77+
if (this.nextProcessor && this.nextProcessor.name === 'JstEngine') {
7878
// Use `compileClient` for Jade v1.0.0+, and `compile` for older versions
7979
var compile = Jade.compileClient || Jade.compile;
8080

lib/mincer/engines/stylus_engine.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ StylusEngine.prototype.evaluate = function (context, locals) {
7979

8080
// define helpers from the list of passed locals
8181
_.forEach(locals, function (helper, name) {
82-
if ('function' !== typeof helper) {
82+
if (typeof helper !== 'function') {
8383
// Provide object as a function helper
8484
style.define(name, function () {
8585
return helper;

lib/mincer/helpers/configuring.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function configuration(self, name) {
7575
* }
7676
**/
7777
module.exports.isEnabled = function (name) {
78-
return 'enabled' === configuration(this, name).state;
78+
return configuration(this, name).state === 'enabled';
7979
};
8080

8181

lib/mincer/manifest.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var Manifest = module.exports = function Manifest(environment, pathname) {
5252

5353
prop(this, 'environment', environment);
5454

55-
if ('' === path.extname(pathname)) {
55+
if (path.extname(pathname) === '') {
5656
prop(this, 'dir', path.resolve(pathname));
5757
prop(this, 'path', path.join(this.dir, 'manifest.json'));
5858
} else {
@@ -253,7 +253,7 @@ Manifest.prototype.compile = function (files, options) {
253253

254254
write(target, asset.mtime, buffer);
255255

256-
if ('bundled' === asset.type && options.compress) {
256+
if (asset.type === 'bundled' && options.compress) {
257257
write(target + '.gz', asset.mtime, gzip(buffer));
258258
}
259259

lib/mincer/processors/charset_normalizer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ CharsetNormalizer.prototype.evaluate = function (/*context, locals*/) {
5454
return '';
5555
});
5656

57-
if (null !== charset) {
57+
if (charset !== null) {
5858
this.data = charset + '\n' + this.data;
5959
}
6060
};

lib/mincer/processors/directive_processor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ DirectiveProcessor.prototype.processSource = function () {
323323

324324
// if our own body was not yet appended, and there are header comments,
325325
// prepend these coments first.
326-
if (!self.__hasWrittenBody__ && 0 < self.processedHeader.length) {
326+
if (!self.__hasWrittenBody__ && self.processedHeader.length > 0) {
327327
self.result += self.processedHeader;
328328
}
329329

lib/mincer/processors/safety_colons.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ require('util').inherits(SafetyColons, Template);
4242
SafetyColons.prototype.evaluate = function (/*context, locals*/) {
4343
var data = this.data.trimRight();
4444

45-
if (';' !== data[data.length - 1]) {
45+
if (data[data.length - 1] !== ';') {
4646
data = data + '\n;\n';
4747
}
4848

lib/mincer/server.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function get_fingerprint(pathname) {
8383
function end(res, code) {
8484
res.writeHead(code);
8585

86-
if (400 <= code) {
86+
if (code >= 400) {
8787
// write human-friendly error message
8888
res.end('[' + code + '] ' + http.STATUS_CODES[code]);
8989
return;
@@ -109,7 +109,7 @@ function is_etag_match(req, asset) {
109109
// Tells whenever browser accepts gzip at all
110110
function is_gzip_accepted(req) {
111111
var accept = req.headers['accept-encoding'] || '';
112-
return '*' === accept || 0 <= accept.indexOf('gzip');
112+
return accept === '*' || accept.indexOf('gzip') >= 0;
113113
}
114114

115115

@@ -170,7 +170,7 @@ function serve_asset(self, asset, req, res, timer) {
170170

171171
res.statusCode = 200;
172172

173-
if ('HEAD' === req.method) {
173+
if (req.method === 'HEAD') {
174174
res.end();
175175
return;
176176
}
@@ -204,7 +204,7 @@ function serve_source_map(self, asset, req, res, timer) {
204204
res.setHeader('Content-Length', length);
205205
}
206206

207-
if ('HEAD' === req.method) {
207+
if (req.method === 'HEAD') {
208208
res.end();
209209
return;
210210
}
@@ -354,14 +354,14 @@ Server.prototype.handle = function handle(req, res) {
354354
}
355355

356356
// forbid requests with `..` or NUL chars
357-
if (0 <= pathname.indexOf('..') || 0 <= pathname.indexOf('\u0000')) {
357+
if (pathname.indexOf('..') >= 0 || pathname.indexOf('\u0000') >= 0) {
358358
self.log('error', log_event(req, 403, 'URL contains unsafe chars', timer.stop()));
359359
end(res, 403);
360360
return;
361361
}
362362

363363
// ignore non-GET requests
364-
if ('GET' !== req.method && 'HEAD' !== req.method) {
364+
if (req.method !== 'GET' && req.method !== 'HEAD') {
365365
self.log('error', log_event(req, 403, 'HTTP method not allowed', timer.stop()));
366366
end(res, 403);
367367
return;

0 commit comments

Comments
 (0)