Skip to content

Commit e2f7035

Browse files
author
Alexej Yaroshevich
committed
sync code style rules with main repo and correct sources
1 parent f483fc8 commit e2f7035

11 files changed

Lines changed: 78 additions & 72 deletions

.jscsrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"preset": "google",
3+
"fileExtensions": [ ".js", "jscs" ],
34

45
"requireParenthesesAroundIIFE": true,
56
"maximumLineLength": 120,
@@ -8,9 +9,10 @@
89

910
"disallowKeywords": ["with"],
1011
"disallowSpacesInsideObjectBrackets": null,
11-
"disallowSpacesInFunctionExpression": null,
1212
"disallowImplicitTypeConversion": ["string"],
1313

14+
"safeContextKeyword": "_this",
15+
1416
"excludeFiles": [
1517
"test/data/**",
1618
"test/lib/rules/**"

lib/jsdoc-helpers.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function jsDocParseComments (comments) {
2323
if (jsdoc) {
2424
var comment = Array(jsdoc.loc.start.column + 1).join(' ') + '/*' + jsdoc.value + '*/';
2525
jsdoc.data = parseJsDoc(comment);
26-
jsdoc.lines = comment.split('\n').map(function (v) {
26+
jsdoc.lines = comment.split('\n').map(function(v) {
2727
return v.substr(jsdoc.loc.start.column);
2828
});
2929
jsdoc.invalid = !jsdoc.data.hasOwnProperty('line');
@@ -62,19 +62,19 @@ function jsDocParseComments (comments) {
6262
}
6363

6464
function jsDocTagValidator (validator) {
65-
return function (node, err) {
66-
var that = this;
65+
return function(node, err) {
66+
var _this = this;
6767
if (!node.jsDoc) {
6868
return;
6969
}
70-
node.jsDoc.forEachTag(function (tag, i) {
70+
node.jsDoc.forEachTag(function(tag, i) {
7171
// call line validator
72-
validator.call(that, node, tag, fixErrLocation(err, node, i));
72+
validator.call(_this, node, tag, fixErrLocation(err, node, i));
7373
});
7474
};
7575

7676
function fixErrLocation (err, node, tagN) {
77-
return function (text, line, column) {
77+
return function(text, line, column) {
7878
var tag = node.jsDoc.data.tags[tagN];
7979
line = line || tag.line;
8080
// buggy. multiline comment will resolved to 0
@@ -180,7 +180,11 @@ function jsDocSimplifyNode (node) {
180180
* @param {Object} argument - esprima source code node
181181
*/
182182
function jsDocMatchType (variants, argument) {
183-
var i, l, variant, type, result = null;
183+
var i;
184+
var l;
185+
var variant;
186+
var type;
187+
var result = null;
184188

185189
for (i = 0, l = variants.length; i < l; i += 1) {
186190
variant = variants[i][0] || variants[i];

lib/rules/validate-jsdoc.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = function() {};
77

88
module.exports.prototype = {
99

10-
configure: function (options) {
10+
configure: function(options) {
1111
assert(typeof options === 'object', 'jsDoc option requires object value');
1212

1313
this._options = options;
@@ -16,7 +16,7 @@ module.exports.prototype = {
1616

1717
assert(this._validators.length, 'jsDoc was not configured properly');
1818

19-
this._validators.forEach(function (v) {
19+
this._validators.forEach(function(v) {
2020
if (v.configure) {
2121
v.configure.call(this, options);
2222
}
@@ -26,11 +26,11 @@ module.exports.prototype = {
2626
}.bind(this));
2727
},
2828

29-
getOptionName: function () {
29+
getOptionName: function() {
3030
return 'jsDoc';
3131
},
3232

33-
check: function (file, errors) {
33+
check: function(file, errors) {
3434
var activeValidators = this._validators;
3535

3636
// skip if there is no validators
@@ -39,18 +39,18 @@ module.exports.prototype = {
3939
}
4040

4141
var jsDocs = jsDocHelpers.parseComments(file.getComments());
42-
var that = this;
42+
var _this = this;
4343

4444
file.iterateNodesByType([
4545
'FunctionDeclaration',
4646
'FunctionExpression'
4747

48-
], function (node) {
48+
], function(node) {
4949
node.jsDoc = jsDocs.forNode(node);
5050
var commentStart = (node.jsDoc || node).loc.start;
5151

5252
for (var j = 0, k = activeValidators.length; j < k; j += 1) {
53-
activeValidators[j].call(that, node, addError);
53+
activeValidators[j].call(_this, node, addError);
5454
}
5555

5656
function addError(text, relLine, relColumn) {

lib/rules/validate-jsdoc/check-redundant-access.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function checkRedundantAccess(node, err) {
1515
}
1616

1717
var access;
18-
node.jsDoc.data.tags.forEach(function (tag) {
18+
node.jsDoc.data.tags.forEach(function(tag) {
1919
if (['private', 'protected', 'public', 'access'].indexOf(tag.tag) === -1) {
2020
return;
2121
}

lib/rules/validate-jsdoc/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Object.defineProperty(validatorsByName, 'load', {
1616
return validators;
1717
}
1818

19-
Object.keys(validatorsByName).forEach(function (name) {
19+
Object.keys(validatorsByName).forEach(function(name) {
2020
var v = validatorsByName[name];
2121

2222
// skip unknown
@@ -41,7 +41,7 @@ Object.defineProperty(validatorsByName, 'load', {
4141

4242
Object.defineProperty(validatorsByName, 'checkOptions', {
4343
value: function checkOptions(validator, options) {
44-
Object.keys(validator.options).forEach(function (data, option) {
44+
Object.keys(validator.options).forEach(function(data, option) {
4545
if (!data.allowedValues) {
4646
return;
4747
}

lib/rules/validate-jsdoc/leading-underscore-access.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function validateLeadingUnderscoresAccess(node, err) {
3737
}
3838

3939
var access;
40-
node.jsDoc.data.tags.forEach(function (tag) {
40+
node.jsDoc.data.tags.forEach(function(tag) {
4141
if (!access && ['private', 'protected', 'public', 'access'].indexOf(tag.tag) !== -1) {
4242
access = (tag.tag === 'access' ? tag.name : tag.tag);
4343
}

lib/rules/validate-jsdoc/returns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function validateReturnsTag(node, tag, err) {
7070

7171
// try to check returns types
7272
if (options.checkReturnTypes && jsDocParsedType) {
73-
returnsArgumentStatements.forEach(function (argument) {
73+
returnsArgumentStatements.forEach(function(argument) {
7474
if (!jsDocHelpers.match(jsDocParsedType, argument)) {
7575
err('Wrong returns value', argument.loc.start);
7676
}

test/init.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ function fnBody(func) {
1919

2020
// strip preceding indentation
2121
var blockIndent = 0;
22-
out.match(/^([ \t]*)/gm).map(function (v) {
22+
out.match(/^([ \t]*)/gm).map(function(v) {
2323
if (!blockIndent || (v.length > 0 && v.length < blockIndent)) {
2424
blockIndent = v.length;
2525
}
2626
});
2727

2828
// rebuild block without inner indent
29-
out = !blockIndent ? out : out.split('\n').map(function (v) {
29+
out = !blockIndent ? out : out.split('\n').map(function(v) {
3030
return v.substr(blockIndent);
3131
}).join('\n');
3232

@@ -36,7 +36,7 @@ function fnBody(func) {
3636
function rulesChecker(opts) {
3737
var checker;
3838

39-
beforeEach(function () {
39+
beforeEach(function() {
4040
checker = new Checker();
4141
checker.registerDefaultRules();
4242
if (opts) {
@@ -45,16 +45,16 @@ function rulesChecker(opts) {
4545
});
4646

4747
return {
48-
rules: function (rules) {
49-
beforeEach(function () {
48+
rules: function(rules) {
49+
beforeEach(function() {
5050
checker.configure({jsDoc: rules});
5151
});
5252
},
53-
cases: function (items) {
53+
cases: function(items) {
5454
items = items || [];
55-
items.forEach(function (test) {
55+
items.forEach(function(test) {
5656

57-
(test.skip ? it.skip : it)(test.it, function () {
57+
(test.skip ? it.skip : it)(test.it, function() {
5858
if (test.rules) {
5959
checker.configure({ jsDoc: test.rules });
6060
}
@@ -86,13 +86,13 @@ function rulesChecker(opts) {
8686
};
8787
}
8888

89-
chai.use(function (chai, utils) {
89+
chai.use(function(chai, utils) {
9090
utils.addMethod(chai.Assertion.prototype, 'similar', method);
9191

9292
function method(expected) {
9393
var obj = utils.flag(this, 'object');
9494

95-
Object.keys(obj).forEach(function (k) {
95+
Object.keys(obj).forEach(function(k) {
9696
if (!expected.hasOwnProperty(k)) {
9797
expected[k] = obj[k];
9898
}

test/test.init.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
var expect = require('chai').expect;
22
var fnBody = global.fnBody;
33

4-
describe('test', function () {
5-
describe('fnBody', function () {
6-
it('should not fail', function () {
7-
expect(fnBody(function () {
4+
describe('test', function() {
5+
describe('fnBody', function() {
6+
it('should not fail', function() {
7+
expect(fnBody(function() {
88
/**
99
* yolo
1010
*/

test/test.validate-jsdoc-basic.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
var Checker = require('jscs/lib/checker');
22
var assert = require('assert');
33

4-
describe('rules/validate-jsdoc @param', function () {
4+
describe('rules/validate-jsdoc @param', function() {
55

66
var checker;
7-
beforeEach(function () {
7+
beforeEach(function() {
88
checker = new Checker();
99
checker.registerDefaultRules();
1010
checker.configure({ additionalRules: ['lib/rules/validate-jsdoc.js'] });
1111
});
1212

13-
describe('redudant-params', function () {
13+
describe('redudant-params', function() {
1414

15-
it('should report redundant jsdoc-param for function', function () {
15+
it('should report redundant jsdoc-param for function', function() {
1616
checker.configure({ jsDoc: { checkRedundantParams: true } });
1717
assert(
1818
checker.checkString(
@@ -26,7 +26,7 @@ describe('rules/validate-jsdoc @param', function () {
2626
).getErrorCount() === 1
2727
);
2828
});
29-
it('should report redundant jsdoc-param for method', function () {
29+
it('should report redundant jsdoc-param for method', function() {
3030
checker.configure({ jsDoc: { checkRedundantParams: true } });
3131
assert(
3232
checker.checkString(
@@ -41,7 +41,7 @@ describe('rules/validate-jsdoc @param', function () {
4141
).getErrorCount() === 1
4242
);
4343
});
44-
it('should not report redundant jsdoc-param for function', function () {
44+
it('should not report redundant jsdoc-param for function', function() {
4545
checker.configure({ jsDoc: { checkRedundantParams: true } });
4646
assert(
4747
checker.checkString(
@@ -55,7 +55,7 @@ describe('rules/validate-jsdoc @param', function () {
5555
).getErrorCount() === 0
5656
);
5757
});
58-
it('should not report valid jsdoc for method', function () {
58+
it('should not report valid jsdoc for method', function() {
5959
checker.configure({ jsDoc: { checkRedundantParams: true } });
6060
assert(
6161
checker.checkString(
@@ -69,7 +69,7 @@ describe('rules/validate-jsdoc @param', function () {
6969
).isEmpty()
7070
);
7171
});
72-
it('should not report valid jsdoc for function', function () {
72+
it('should not report valid jsdoc for function', function() {
7373
checker.configure({ jsDoc: { checkRedundantParams: true } });
7474
assert(
7575
checker.checkString(
@@ -87,9 +87,9 @@ describe('rules/validate-jsdoc @param', function () {
8787

8888
});
8989

90-
describe('require-param-types', function () {
90+
describe('require-param-types', function() {
9191

92-
it('should report missing jsdoc-param type for function', function () {
92+
it('should report missing jsdoc-param type for function', function() {
9393
checker.configure({ jsDoc: { requireParamTypes: true } });
9494
assert(
9595
checker.checkString(
@@ -103,7 +103,7 @@ describe('rules/validate-jsdoc @param', function () {
103103
).getErrorCount() === 1
104104
);
105105
});
106-
it('should report missing jsdoc-param type for method', function () {
106+
it('should report missing jsdoc-param type for method', function() {
107107
checker.configure({ jsDoc: { requireParamTypes: true } });
108108
assert(
109109
checker.checkString(
@@ -118,7 +118,7 @@ describe('rules/validate-jsdoc @param', function () {
118118
).getErrorCount() === 1
119119
);
120120
});
121-
it('should not report valid jsdoc for method', function () {
121+
it('should not report valid jsdoc for method', function() {
122122
checker.configure({ jsDoc: { requireParamTypes: true } });
123123
assert(
124124
checker.checkString(
@@ -132,7 +132,7 @@ describe('rules/validate-jsdoc @param', function () {
132132
).isEmpty()
133133
);
134134
});
135-
it('should not report valid jsdoc for function', function () {
135+
it('should not report valid jsdoc for function', function() {
136136
checker.configure({ jsDoc: { requireParamTypes: true } });
137137
assert(
138138
checker.checkString(
@@ -147,7 +147,7 @@ describe('rules/validate-jsdoc @param', function () {
147147
).isEmpty()
148148
);
149149
});
150-
it('should not report valid jsdoc with object type for method', function () {
150+
it('should not report valid jsdoc with object type for method', function() {
151151
checker.configure({ jsDoc: { requireParamTypes: true } });
152152
assert(
153153
checker.checkString(
@@ -161,7 +161,7 @@ describe('rules/validate-jsdoc @param', function () {
161161
).isEmpty()
162162
);
163163
});
164-
it('should not report valid jsdoc with object type for function', function () {
164+
it('should not report valid jsdoc with object type for function', function() {
165165
checker.configure({ jsDoc: { requireParamTypes: true } });
166166
assert(
167167
checker.checkString(

0 commit comments

Comments
 (0)