Skip to content

Commit eb93219

Browse files
committed
Merge pull request #80 from bem/lint
Added lints
2 parents e306c37 + b999c42 commit eb93219

14 files changed

Lines changed: 188 additions & 104 deletions

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ insert_final_newline = true
1111

1212
[*.md]
1313
trim_trailing_whitespace = false
14+
15+
[package.json]
16+
indent_size = 2

.jscs.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module.exports = {
2+
excludeFiles: [
3+
'node_modules/**',
4+
'coverage/**'
5+
],
6+
requireSpaceAfterKeywords: ['if', 'else', 'for', 'while', 'do', 'switch', 'return', 'try', 'catch'],
7+
requireSpaceBeforeBlockStatements: true,
8+
requireSpacesInConditionalExpression: true,
9+
requireSpacesInFunction: {
10+
beforeOpeningCurlyBrace: true
11+
},
12+
requireSpacesInAnonymousFunctionExpression: {
13+
beforeOpeningRoundBrace: true
14+
},
15+
disallowSpacesInNamedFunctionExpression: {
16+
beforeOpeningRoundBrace: true
17+
},
18+
requireMultipleVarDecl: true,
19+
requireBlocksOnNewline: 1,
20+
disallowPaddingNewlinesInBlocks: true,
21+
disallowSpacesInsideArrayBrackets: 'nested',
22+
disallowSpacesInsideParentheses: true,
23+
requireSpacesInsideObjectBrackets: 'all',
24+
disallowQuotedKeysInObjects: 'allButReserved',
25+
disallowDanglingUnderscores: true,
26+
disallowSpaceAfterObjectKeys: true,
27+
requireCommaBeforeLineBreak: true,
28+
requireOperatorBeforeLineBreak: true,
29+
disallowSpaceAfterPrefixUnaryOperators: true,
30+
disallowSpaceBeforePostfixUnaryOperators: true,
31+
requireSpaceBeforeBinaryOperators: true,
32+
requireSpaceAfterBinaryOperators: true,
33+
requireCamelCaseOrUpperCaseIdentifiers: true,
34+
disallowKeywords: ['with'],
35+
disallowMultipleLineStrings: true,
36+
disallowMultipleLineBreaks: true,
37+
validateLineBreaks: 'LF',
38+
validateQuoteMarks: {
39+
mark: '\'',
40+
escape: true
41+
},
42+
validateIndentation: 4,
43+
disallowMixedSpacesAndTabs: true,
44+
disallowTrailingWhitespace: true,
45+
disallowKeywordsOnNewLine: ['else', 'catch'],
46+
requireLineFeedAtFileEnd: true,
47+
maximumLineLength: 120,
48+
requireCapitalizedConstructors: true,
49+
safeContextKeyword: ['_this'],
50+
disallowYodaConditions: true,
51+
validateJSDoc: {
52+
checkParamNames: true,
53+
checkRedundantParams: true,
54+
requireParamTypes: true
55+
},
56+
requireSpaceAfterLineComment: true,
57+
disallowNewlineBeforeBlockStatements: true
58+
};

.jshintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
coverage

.jshintrc

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
{
2-
"node": true,
3-
"esnext": true,
42
"bitwise": true,
5-
"camelcase": true,
63
"curly": true,
74
"eqeqeq": true,
5+
"es3": true,
6+
"forin": true,
7+
"freeze": true,
88
"immed": true,
9-
"indent": 4,
109
"latedef": true,
11-
"newcap": true,
1210
"noarg": true,
13-
"quotmark": "single",
14-
"regexp": true,
11+
"noempty": true,
12+
"nonbsp": true,
13+
"nonew": true,
1514
"undef": true,
1615
"unused": true,
17-
"strict": true,
18-
"trailing": true,
19-
"smarttabs": true,
20-
"white": true
16+
17+
"browser": true,
18+
"node": true,
19+
20+
"globals": {
21+
"modules": false
22+
},
23+
24+
"expr": true,
25+
"sub": true
2126
}

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ language: node_js
22

33
node_js:
44
- "0.10"
5-
- "0.8"
65

76
env:
87
global:

lib/cli.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ module.exports = require('coa').Cmd()
1212
.opt()
1313
.name('version')
1414
.title('Shows the version number')
15+
/*jshint -W024 */
1516
.short('v').long('version')
1617
.flag()
1718
.only()
18-
.act(function() {
19+
.act(function () {
1920
var p = require('../package.json');
2021
return p.name + ' ' + p.version;
2122
})
@@ -30,7 +31,8 @@ module.exports = require('coa').Cmd()
3031
.title('The number of characters around the diff (default: 40)')
3132
.long('chars-around-diff')
3233
.def(40)
33-
.val(function(val) {
34+
.val(function (val) {
35+
/*jshint es3:false */
3436
return parseInt(val);
3537
})
3638
.end()
@@ -44,21 +46,21 @@ module.exports = require('coa').Cmd()
4446
.title('Path to the 2-nd HTML file')
4547
.req()
4648
.end()
47-
.act(function(opts, args) {
49+
.act(function (opts, args) {
4850
return vow.all([
49-
vfs.read(path.resolve(args.path1), 'utf-8'),
50-
vfs.read(path.resolve(args.path2), 'utf-8'),
51-
opts.config ? vfs.read(path.resolve(opts.config)) : undefined
52-
]).spread(function (html1, html2, config) {
53-
config = config ? JSON.parse(config) : {};
51+
vfs.read(path.resolve(args.path1), 'utf-8'),
52+
vfs.read(path.resolve(args.path2), 'utf-8'),
53+
opts.config ? vfs.read(path.resolve(opts.config)) : undefined
54+
]).spread(function (html1, html2, config) {
55+
config = config ? JSON.parse(config) : {};
5456

55-
var options = utils.defaults(config),
56-
loggerOptions = {
57-
charsAroundDiff: opts.charsAroundDiff
58-
},
59-
htmlDiffer = new HtmlDiffer(options);
57+
var options = utils.defaults(config),
58+
loggerOptions = {
59+
charsAroundDiff: opts.charsAroundDiff
60+
},
61+
htmlDiffer = new HtmlDiffer(options);
6062

61-
diffLogger.log(htmlDiffer.diffHtml(html1, html2), loggerOptions);
62-
});
63+
diffLogger.log(htmlDiffer.diffHtml(html1, html2), loggerOptions);
64+
});
6365
})
6466
.run(process.argv.slice(2));

lib/diff-logger.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ function getDiffText(diff, options) {
2424
charsAroundDiff = 40;
2525
}
2626

27-
if (diff.length === 1 && !diff[0].added && !diff[0].removed) return output;
27+
if (diff.length === 1 && !diff[0].added && !diff[0].removed) { return output; }
2828

29-
diff.forEach(function(part) {
29+
diff.forEach(function (part) {
3030
var index = diff.indexOf(part),
3131
partValue = part.value,
3232
color = 'grey';
3333

34-
if (part.added) color = 'green';
35-
if (part.removed) color = 'red';
34+
if (part.added) { color = 'green'; }
35+
if (part.removed) { color = 'red'; }
3636

3737
if (color !== 'grey') {
3838
output += (!index ? '\n' : '') + partValue.inverse[color];

lib/index.js

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ var utils = require('./utils'),
88
/**
99
* Converts the HTML document to the AST Tree
1010
* @param {String} HTMLDoc
11-
* @param {Object} options
1211
* @returns {AST}
1312
*/
1413
function htmlToAST(HTMLDoc) {
1514
var parser,
1615
parserHandler;
1716

18-
parserHandler = new htmlParser.DomHandler(function(err) {
19-
if (err) console.log(err);
17+
parserHandler = new htmlParser.DomHandler(function (err) {
18+
if (err) { console.log(err); }
2019
});
2120

2221
parser = new htmlParser.Parser(parserHandler);
@@ -34,9 +33,8 @@ function htmlToAST(HTMLDoc) {
3433
function modifyASTTree(tree, options) {
3534
var delComments = [];
3635

37-
_.forEach(tree, function(node) {
36+
_.forEach(tree, function (node) {
3837
if (options.ignoreWhitespaces && node.type === 'text') {
39-
4038
node.data = node.data
4139
.replace(/(\n|\r|\t|\v|\f)+/g, '')
4240
.replace(/\s+/g, ' ')
@@ -52,31 +50,30 @@ function modifyASTTree(tree, options) {
5250
}
5351

5452
if (node.hasOwnProperty('attribs')) {
55-
var attrs = utils.sortObj(node['attribs']);
53+
var attrs = utils.sortObj(node.attribs);
5654

5755
if (attrs.hasOwnProperty('class')) {
5856
attrs['class'] = utils.sortCssClasses(attrs['class']);
5957
}
6058

61-
_.forEach(options.compareHtmlAttrsAsJSON, function(attr) {
59+
_.forEach(options.compareHtmlAttrsAsJSON, function (attr) {
6260
var attrValue,
6361
isFunction = (attr === 'onclick' || attr === 'ondblclick'); // @FIXME: should be configurable
6462

6563
if (attrs.hasOwnProperty(attr)) {
66-
6764
attrValue = utils.parseAttr(attrs[attr].replace(/"/g, '"'), isFunction);
6865
attrValue = utils.sortObj(attrValue);
6966
attrValue = JSON.stringify(attrValue);
7067

71-
attrs[attr] = (isFunction ? 'return ' : '') + attrValue.replace(/"/g, '"')
68+
attrs[attr] = (isFunction ? 'return ' : '') + attrValue.replace(/"/g, '"');
7269
}
7370
});
7471

75-
_.forEach(options.ignoreHtmlAttrs, function(attr) {
72+
_.forEach(options.ignoreHtmlAttrs, function (attr) {
7673
attrs.hasOwnProperty(attr) && (attrs[attr] = '');
7774
});
7875

79-
node['attribs'] = attrs;
76+
node.attribs = attrs;
8077
}
8178

8279
if (node.hasOwnProperty('children')) {
@@ -93,19 +90,18 @@ function modifyASTTree(tree, options) {
9390

9491
/**
9592
*
96-
* @param [options]
93+
* @param {Object} [options]
9794
* @param {String[]} [options.ignoreHtmlAttrs]
9895
* @param {String[]} [options.compareHtmlAttrsAsJSON]
9996
* @param {Boolean} [options.verbose]
10097
* @param {Boolean} [options.ignoreWhitespaces=true]
10198
* @param {Boolean} [options.bem=false]
10299
* @constructor
103100
*/
104-
var HtmlDiff = function(options) {
101+
var HtmlDiff = function (options) {
105102
this.options = utils.defaults(options);
106-
};
107-
108-
var Diff = diff.Diff;
103+
},
104+
Diff = diff.Diff;
109105

110106
HtmlDiff.prototype = Diff.prototype;
111107

@@ -114,7 +110,7 @@ HtmlDiff.prototype = Diff.prototype;
114110
* @param {String} value
115111
* @returns {Array}
116112
*/
117-
HtmlDiff.prototype.tokenize = function(value) {
113+
HtmlDiff.prototype.tokenize = function (value) {
118114
var options = this.options,
119115
ASTTree = htmlToAST(value, options);
120116

@@ -132,18 +128,18 @@ HtmlDiff.prototype.tokenize = function(value) {
132128

133129
/**
134130
*
135-
* @param [options]
131+
* @param {Object} [options]
136132
* @param {String[]} [options.ignoreHtmlAttrs]
137133
* @param {String[]} [options.compareHtmlAttrsAsJSON]
138134
* @param {Boolean} [options.verbose]
139135
* @param {Boolean} [options.ignoreWhitespaces=true]
140136
* @param {Boolean} [options.bem=false]
141137
* @constructor
142138
*/
143-
var HtmlDiffer = function(options) {
139+
var HtmlDiffer = function (options) {
144140
options = utils.defaults(options);
145141

146-
if (options['bem']) {
142+
if (options.bem) {
147143
options.ignoreHtmlAttrs = ['id', 'for'];
148144
options.compareHtmlAttrsAsJSON = ['data-bem', 'onclick', 'ondblclick'];
149145
}
@@ -158,7 +154,7 @@ var HtmlDiffer = function(options) {
158154
* @param {Object} [options]
159155
* @returns {Diff}
160156
*/
161-
HtmlDiffer.prototype.diffHtml = function(html1, html2, options) {
157+
HtmlDiffer.prototype.diffHtml = function (html1, html2, options) {
162158
if (options) {
163159
console.warn('WARNING! The third param of \'diffHtml\' method is deprecated!'.bold.red);
164160
}
@@ -177,7 +173,7 @@ HtmlDiffer.prototype.diffHtml = function(html1, html2, options) {
177173
* @param {Object} [options]
178174
* @returns {Boolean}
179175
*/
180-
HtmlDiffer.prototype.isEqual = function(html1, html2, options) {
176+
HtmlDiffer.prototype.isEqual = function (html1, html2, options) {
181177
if (options) {
182178
console.warn('WARNING! The third param of \'isEqual\' method is deprecated!'.bold.red);
183179
}
@@ -211,7 +207,6 @@ function bemDiff(html1, html2) {
211207
logger.log(htmlDiffer.diff(html1, html2), loggerOptions);
212208
}
213209

214-
215210
var htmlDiffer = new HtmlDiffer();
216211

217212
module.exports = {

0 commit comments

Comments
 (0)