-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ifNesting of argumentSpacing should accept the same configuration as its parent. #9
Comments
Again probably misleading option names. However it is described in README.md. In this context 'nesting' means function exp. call inside function exp. call:
For example sources of jQuery still styled mostly for the outdated styleguide - no spaces for the nesting calls
So this style ruleset modifier allows to describe such cases. In the given example |
Consider /*jshint -W068 */
/*jshint multistr: true */
var Sniffer = require( "../lib/Sniffer" );
require( "should" );
Array.prototype.hasErrorCode = function( errCode ) {
return !!this.filter(function( msg ){
return msg.errorCode === errCode;
}).length;
};
var OPTIONS = {
standard: "Jquery"
};
describe( " Custom checks ", function () {
var sniffer, logger = null;
beforeEach(function(){
sniffer = new Sniffer();
});
it(" must implement custom standard correctly", function () {
var code = "define('library/uielements/textinput', [\
'core'\
], function(require) {\
var core = require('core'),\
_textinput = {\
create: function(input, type, options) {\
switch(type) {\
case _self.TYPE_NORMAL:\
_self.normal(input, options);\
break;\
}\
}\
};\
});",
modifiers = {
"Indentation": false,
"QuoteConventions": false,
"ParametersSpacing": false,
"LineLength": false,
"ArrayLiteralSpacing": false,
"ObjectLiteralSpacing": false,
"CompoundStatementConventions": false,
"ArgumentsSpacing": {
"allowArgPrecedingWhitespaces": 1,
"allowArgTrailingWhitespaces": 0,
"exceptions": {
"singleArg" : {
"for": ["FunctionExpression", "ArrayExpression", "ObjectExpression", "Literal"],
"allowArgPrecedingWhitespaces": 0,
"allowArgTrailingWhitespaces": 0
},
"firstArg": {
"for": [ "FunctionExpression" , "ArrayExpression", "ObjectExpression", "Literal"],
"allowArgPrecedingWhitespaces": 0
},
"lastArg": {
"for": [ "FunctionExpression", , "ArrayExpression", "ObjectExpression", "Literal" ],
"allowArgTrailingWhitespaces": 0
}
},
"ifNesting": false
}
};
logger = sniffer.getTestResults( code, OPTIONS, modifiers );
console.log(logger.getMessages());
logger.getMessages().length.should.not.be.ok;
});
}); if I put ifNesting on false, it doesn't matter anymore how the arguments of _self.normal(input, options); are formatted. If I add the proposed options to ifNesting, I get a failing test whatever I choose and it fails on _self.normal. |
Following case shows the usage of ifNesting it(" must accept ArgumentsSpacing ifNesting modifiers", function () {
var code = "foo( 1, bar(1,1) )",
modifiers = {
"ArgumentsSpacing": {
"allowArgPrecedingWhitespaces": 1,
"allowArgTrailingWhitespaces": 1,
"ifNesting": {
"allowArgPrecedingWhitespaces": 0,
"allowArgTrailingWhitespaces": 0
}
}
};
logger = sniffer.getTestResults( code, OPTIONS, modifiers );
logger.getMessages().length.should.not.be.ok;
}); |
There is no way of configuring nested argumentSpacing options the same way as its parent. This gives us strange situations where I have to force employees to change their styling for nested function calls. Consider this piece of code:
The _self.normal() is seen as a nested function call but doesn't allow for that format in any way.
The text was updated successfully, but these errors were encountered: