Skip to content

Commit e0f36d2

Browse files
committed
Crank up jshint strictness
1 parent 8b76b9b commit e0f36d2

File tree

9 files changed

+113
-102
lines changed

9 files changed

+113
-102
lines changed

.jshintrc

100755100644
+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
{
2+
"bitwise": true,
23
"browser": true,
4+
"camelcase": true,
5+
"curly": true,
6+
"eqeqeq": true,
7+
"forin": true,
8+
"immed": true,
39
"indent": 2,
4-
"undef": true
10+
"latedef": true,
11+
"newcap": true,
12+
"noarg": true,
13+
"noempty": true,
14+
"nonew": true,
15+
"plusplus": true,
16+
"quotmark": "single",
17+
"trailing": true,
18+
"undef": true,
19+
"unused": true
520
}

extras/bookmarklet.js

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
1-
/* global _, jQuery, $, console, CSS */
1+
/* global _, jQuery, console, CSS */
22

33
(function () {
4-
"use strict";
4+
'use strict';
55

66
function onScriptsLoaded() {
7-
var $ = jQuery.noConflict(), iframe_src = $('<iframe />'),
8-
iframe_dst = $('<iframe>Computing new style...</iframe>');
7+
var $ = jQuery.noConflict(), iframeSrc = $('<iframe />'),
8+
iframeDst = $('<iframe>Computing new style...</iframe>');
99

10-
console.log("WARNING: this bookmarklet is deprecated.");
11-
console.log("To use the the full features of Ratiocinator, try either of these options.");
12-
console.log("1. Use the web interface: http://www.csstrashman.com");
13-
console.log("2. Run the command-line version: " +
14-
"https://github.com/begriffs/css-ratiocinator#usage");
10+
console.log('WARNING: this bookmarklet is deprecated.');
11+
console.log('To use the the full features of Ratiocinator, try either of these options.');
12+
console.log('1. Use the web interface: http://www.csstrashman.com');
13+
console.log('2. Run the command-line version: ' +
14+
'https://github.com/begriffs/css-ratiocinator#usage');
1515

16-
iframe_src.attr('id', 'ratio_src');
17-
iframe_src.attr(
16+
iframeSrc.attr('id', 'ratio_src');
17+
iframeSrc.attr(
1818
'style',
1919
'position: absolute; top: 0; left: 0; height: 100%; ' +
2020
'width: 50%; border-right: 1px solid black;'
2121
);
22-
iframe_src.load(function () {
22+
iframeSrc.load(function () {
2323
var styles = CSS.simplerStyle(
24-
$(window.frames.ratio_src.document.getElementsByTagName('html')[0])
24+
$(window.frames.ratioSrc.document.getElementsByTagName('html')[0])
2525
),
26-
style_tag = $('<style type="text/css" media="all" />'),
26+
styleTag = $('<style type="text/css" media="all" />'),
2727
css = '';
28-
window.frames.ratio_dst.document.body.innerHTML =
29-
window.frames.ratio_src.document.body.innerHTML;
28+
window.frames.ratioDst.document.body.innerHTML =
29+
window.frames.ratioSrc.document.body.innerHTML;
3030

3131
_.each(_.pairs(styles), function (pair) {
3232
css += CSS.renderStyle(pair[0], pair[1]);
3333
});
34-
style_tag.html(css);
35-
$('head', window.frames.ratio_dst.document).append(style_tag);
34+
styleTag.html(css);
35+
$('head', window.frames.ratioDst.document).append(styleTag);
3636
});
37-
iframe_src.attr('src', window.location.href);
37+
iframeSrc.attr('src', window.location.href);
3838

39-
iframe_dst.attr('style', 'position: absolute; top: 0; right: 0; height: 100%; width: 50%;');
40-
iframe_dst.attr('id', 'ratio_dst');
39+
iframeDst.attr('style', 'position: absolute; top: 0; right: 0; height: 100%; width: 50%;');
40+
iframeDst.attr('id', 'ratio_dst');
4141

4242
$('body').empty();
43-
$('body').append(iframe_src);
44-
$('body').append(iframe_dst);
43+
$('body').append(iframeSrc);
44+
$('body').append(iframeDst);
4545
}
4646

47-
var script = document.createElement("script");
48-
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js";
47+
var script = document.createElement('script');
48+
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js';
4949
script.onload = function () {
5050
jQuery.getScript(
5151
'https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js',
@@ -62,5 +62,5 @@
6262
}
6363
);
6464
};
65-
document.getElementsByTagName("head")[0].appendChild(script);
65+
document.getElementsByTagName('head')[0].appendChild(script);
6666
}());

lib/async.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/* global _, require, exports */
1+
/* global require, exports */
22

33
(function () {
4-
"use strict";
4+
'use strict';
55

66
var _ = require('../vendor/underscore-1.4.2.js');
77

lib/css.js

+47-46
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
/* global exports, _, jQuery, OBJ, console, CSSFontFaceRule */
1+
/* global exports, _, jQuery, OBJ, CSSFontFaceRule */
2+
/* exported CSS */
23

34
var CSS = (function () {
4-
"use strict";
5+
'use strict';
56
var my = {},
67
$ = jQuery.noConflict();
78

@@ -275,9 +276,9 @@ var CSS = (function () {
275276
'overflow': 'visible',
276277
'overflow-x': 'visible',
277278
'overflow-y': 'visible',
278-
'padding': node.prop("tagName").match(/[UO]L/) ? '' : '0px',
279+
'padding': node.prop('tagName').match(/[UO]L/) ? '' : '0px',
279280
'padding-bottom': '0px',
280-
'padding-left': node.prop("tagName").match(/[UO]L/) ? '40px' : '0px',
281+
'padding-left': node.prop('tagName').match(/[UO]L/) ? '40px' : '0px',
281282
'padding-right': '0px',
282283
'padding-top': '0px',
283284
'page-break-after': 'auto',
@@ -321,7 +322,7 @@ var CSS = (function () {
321322
};
322323

323324
if (node.data('style')) {
324-
if (defaultDisplayForTag(node.prop("tagName")) === node.data('style').display) {
325+
if (defaultDisplayForTag(node.prop('tagName')) === node.data('style').display) {
325326
delete node.data('style').display;
326327
}
327328
_.each(_.keys(defaults), function (def) {
@@ -339,7 +340,7 @@ var CSS = (function () {
339340
function stripIrrelevantStyles(node) {
340341
var style = node.data('style');
341342
if (style) {
342-
if (node.prop("tagName") !== 'UL' && node.prop("tagName") !== 'OL') {
343+
if (node.prop('tagName') !== 'UL' && node.prop('tagName') !== 'OL') {
343344
delete style['list-style-type'];
344345
}
345346

@@ -364,77 +365,63 @@ var CSS = (function () {
364365
root.data('style', OBJ.difference(root.data('style'), defaults));
365366
}
366367

367-
function selectorsUsed(node, so_far) {
368-
var tag = node.prop("tagName").toLowerCase();
368+
function selectorsUsed(node, soFar) {
369+
var tag = node.prop('tagName').toLowerCase();
369370
if (tag === 'head' || tag === 'script') {
370371
return {};
371372
}
372-
so_far = so_far || {};
373-
so_far[tag] = true;
373+
soFar = soFar || {};
374+
soFar[tag] = true;
374375
if (tag !== 'html') { // disregard classes on root element
375376
if (node.attr('class')) {
376377
_.each(node.attr('class').split(/\s+/), function (klass) {
377378
if (klass) {
378-
so_far['.' + klass] = true;
379-
so_far[node.prop("tagName").toLowerCase() + '.' + klass] = true;
379+
soFar['.' + klass] = true;
380+
soFar[node.prop('tagName').toLowerCase() + '.' + klass] = true;
380381
}
381382
});
382383
}
383384
if (node.attr('id')) {
384-
so_far['#' + node.attr('id')] = true;
385+
soFar['#' + node.attr('id')] = true;
385386
}
386387
}
387388
node.children().each(function () {
388-
selectorsUsed($(this), so_far);
389+
selectorsUsed($(this), soFar);
389390
});
390-
return so_far;
391+
return soFar;
391392
}
392393

393-
function fontsUsed(node, so_far) {
394-
var fonts = node.data('style')['font-family'];
395-
so_far = so_far || {};
396-
if (fonts) {
397-
_.each(fonts.split(', '), function (font) {
398-
so_far[font] = true;
399-
});
400-
}
401-
node.children().each(function () {
402-
fontsUsed($(this), so_far);
403-
});
404-
return so_far;
405-
}
406-
407-
function originatingSelectors(node, max_depth) {
408-
var escape_selector = function (sel) { return sel.replace(/(:)/g, '\\$1'); },
409-
selectors = _.map(_.keys(selectorsUsed(node)), escape_selector),
410-
not_id = function (selector) { return selector[0] !== '#'; },
411-
sub_selectors = _.filter(selectors, not_id),
412-
build_selector = function (tuple) { return tuple.join(' '); },
413-
add_if_matches = function (selector) {
394+
function originatingSelectors(node, maxDepth) {
395+
var escapeSelector = function (sel) { return sel.replace(/(:)/g, '\\$1'); },
396+
selectors = _.map(_.keys(selectorsUsed(node)), escapeSelector),
397+
notId = function (selector) { return selector[0] !== '#'; },
398+
subSelectors = _.filter(selectors, notId),
399+
buildSelector = function (tuple) { return tuple.join(' '); },
400+
addIfMatches = function (selector) {
414401
if (node.find(selector).length) {
415402
selectors.push(selector);
416403
}
417404
};
418405

419-
while (max_depth > 1) {
406+
while (maxDepth > 1) {
420407
_.each(
421408
_.map(
422-
OBJ.cartesianProduct(selectors, sub_selectors),
423-
build_selector
409+
OBJ.cartesianProduct(selectors, subSelectors),
410+
buildSelector
424411
),
425-
add_if_matches
412+
addIfMatches
426413
);
427-
max_depth -= 1;
414+
maxDepth -= 1;
428415
}
429416
return selectors;
430417
}
431418

432419
function importance(root, choice) {
433420
var number = root.andSelf().find(choice.selector).length,
434421
size = _.keys(choice.style).length,
435-
selector_length = (choice.selector.match(/ /) || [1]).length,
422+
selectorLength = (choice.selector.match(/ /) || [1]).length,
436423
result = -(number * number * size);
437-
if (selector_length > 1) {
424+
if (selectorLength > 1) {
438425
result += 1; // favor shallow selectors
439426
}
440427
return result;
@@ -490,6 +477,20 @@ var CSS = (function () {
490477
return style;
491478
}
492479

480+
my.fontsUsed = function (node, soFar) {
481+
var fonts = node.data('style')['font-family'];
482+
soFar = soFar || {};
483+
if (fonts) {
484+
_.each(fonts.split(', '), function (font) {
485+
soFar[font] = true;
486+
});
487+
}
488+
node.children().each(function () {
489+
my.fontsUsed($(this), soFar);
490+
});
491+
return soFar;
492+
};
493+
493494
my.fontDeclarations = function () {
494495
$('html').find('*').andSelf().each(function (i, elt) {
495496
$(elt).data('style', abbreviate(computedCssProperties(elt)));
@@ -555,11 +556,11 @@ var CSS = (function () {
555556
my.renderStyle = function (selector, properties) {
556557
var css = '';
557558
if (!_.isEmpty(properties)) {
558-
css += (selector + " {\n");
559+
css += (selector + ' {\n');
559560
_.each(properties, function (val, key) {
560-
css += ("\t" + key + ': ' + val + ";\n");
561+
css += ('\t' + key + ': ' + val + ';\n');
561562
});
562-
css += "}\n";
563+
css += '}\n';
563564
}
564565
return css;
565566
};

lib/obj.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* global _, exports */
2+
/* exported OBJ */
23

34
var OBJ = (function () {
4-
"use strict";
5+
'use strict';
56
var my = {};
67

78
my.intersection = function (array) {
@@ -41,10 +42,6 @@ var OBJ = (function () {
4142
}, [[]]);
4243
};
4344

44-
my.toRealArray = function (array_like) {
45-
return Array.prototype.slice.call(array_like);
46-
};
47-
4845
if (typeof exports !== 'undefined') {
4946
_.extend(exports, my);
5047
}

lib/resource.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* global phantom, exports, require, console */
22

33
(function () {
4-
"use strict";
4+
'use strict';
55

66
exports.resolveUrl = function (url, verbose) {
77
var fs = require('fs');
@@ -29,8 +29,8 @@
2929
console.log('Failed to load "' + url + '"');
3030
phantom.exit();
3131
} else {
32-
page.injectJs("vendor/jquery-1.8.2.js");
33-
page.injectJs("vendor/underscore-1.4.2.js");
32+
page.injectJs('vendor/jquery-1.8.2.js');
33+
page.injectJs('vendor/underscore-1.4.2.js');
3434
page.injectJs('lib/obj.js');
3535
page.injectJs('lib/css.js');
3636

originalcss.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
/* global phantom, require, console, _, jQuery, CSSImportRule */
22
(function () {
3-
"use strict";
3+
'use strict';
44

5-
var system = require('system'),
6-
resource = require('./lib/resource.js'),
7-
async = require('./lib/async.js'),
8-
args = require('system').args.slice(1),
9-
page = require('webpage').create(),
10-
url = resource.resolveUrl(args[0], false);
5+
var resource = require('./lib/resource.js'),
6+
async = require('./lib/async.js'),
7+
args = require('system').args.slice(1),
8+
url = resource.resolveUrl(args[0], false);
119

1210
resource.loadWithLibs(url, false, function (page) {
1311
var externalCSSUrls, internalCSS;
@@ -29,21 +27,21 @@
2927
function (text) {
3028
return !text.match(/@import/);
3129
}
32-
).join("\n");
30+
).join('\n');
3331
});
3432
console.log(internalCSS);
3533

3634
async.mapAndThen(
3735
externalCSSUrls,
3836
function (url, continuation) {
39-
page.evaluate(function (url, continuation) {
37+
page.evaluate(function (url) {
4038
var $ = jQuery.noConflict();
4139
console.log($.ajax({
4240
url: url,
4341
dataType: 'html',
4442
async: false
4543
}).responseText);
46-
}, url, continuation);
44+
}, url);
4745
continuation(url);
4846
},
4947
phantom.exit

0 commit comments

Comments
 (0)