Skip to content
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

Closed
viskenxp opened this issue Jan 23, 2014 · 3 comments

Comments

@viskenxp
Copy link

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:

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;
          }
       }
     };
});

The _self.normal() is seen as a nested function call but doesn't allow for that format in any way.

@dsheiko
Copy link
Owner

dsheiko commented Jan 23, 2014

Again probably misleading option names. However it is described in README.md. In this context 'nesting' means function exp. call inside function exp. call:

foo( bar( 1,1 ) )

For example sources of jQuery still styled mostly for the outdated styleguide - no spaces for the nesting calls

foo( bar(1,1) )

So this style ruleset modifier allows to describe such cases. In the given example _self.normal(input, options); is within a closure, but has no inner function expression calls, so it is treated as high-level call.

@dsheiko dsheiko closed this as completed Jan 23, 2014
@viskenxp
Copy link
Author

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.

@dsheiko
Copy link
Owner

dsheiko commented Jan 24, 2014

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;
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants