Git Product home page Git Product logo

Comments (3)

dsheiko avatar dsheiko commented on May 18, 2024

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.

from jscodesniffer.

viskenxp avatar viskenxp commented on May 18, 2024

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.

from jscodesniffer.

dsheiko avatar dsheiko commented on May 18, 2024

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

from jscodesniffer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.