dsheiko / jscodesniffer

⛔️ [DEPRECATED] Tool to ensure that your JavaScript code does not violate the specified coding standard (Idiomatic Style Manifesto or JQuery Core Style Guidelines)
http://dsheiko.github.io/jscodesniffer/
42 stars 8 forks source link

ArrayLiteralSpacing > Exceptions > firstElement > allowElementPrecedingWhitespaces fails. #11

Closed viskenxp closed 10 years ago

viskenxp commented 10 years ago

Consider this test:

/*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 = "ok.push([ok[1]]);",

    modifiers = {
      "LineLength": false,
      "Indentation": false,
      "QuoteConventions": false,
      "ArgumentsSpacing": false,
      "ParametersSpacing": false,
      "ObjectLiteralSpacing": false,
      "ArrayLiteralSpacing": {
            "allowElementPrecedingWhitespaces": 1,
            "allowElementTrailingWhitespaces": 0,
            "exceptions": {
                "singleElement": {
                    "for": [ "FunctionExpression", , "ArrayExpression", "ObjectExpression", "Literal" ],
                    "allowElementPrecedingWhitespaces": 0,
                    "allowElementTrailingWhitespaces": 0
                },
                "firstElement": {
                    "for": [ "FunctionExpression", , "ArrayExpression", "ObjectExpression", "Literal" ],
                    "allowElementPrecedingWhitespaces": 0
                },
                "lastElement": {
                    "for": [ "FunctionExpression", , "ArrayExpression", "ObjectExpression", "Literal" ],
                    "allowElementTrailingWhitespaces": 0
                }
            }
        }
    };

    logger = sniffer.getTestResults( code, OPTIONS, modifiers );

    console.log(logger.getMessages());

    logger.getMessages().length.should.equal(0);
  });
});

The test fails for the array within an array, but it should allow this or is my configuration wrong?

dsheiko commented 10 years ago

ok[1] is no ArrayExpression, but a MemberExpression (1 is property of ok object). It is a member expression within an array. And singleElement rule for list doesn't contain MemberExpression

viskenxp commented 10 years ago

Thx, and for

ticks.push([ticksWindow * i, ticksWindow * i]);

What would be the proper configuration?