Git Product home page Git Product logo

Comments (5)

dsheiko avatar dsheiko commented on May 21, 2024

ver. 2.1.2 resleased. Here working example for your style:

/*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 = "arr = [ 1,1 ]",

    modifiers = {
        "Indentation": false,
        "QuoteConventions": false,
        "ParametersSpacing": {
            "allowParamPrecedingWhitespaces": 0,
            "allowParamTrailingWhitespaces": 0
        },

        "ArrayLiteralSpacing": {
            "allowElementPrecedingWhitespaces": 0,
            "allowElementTrailingWhitespaces": 0,
            "exceptions": {
                "singleArg": {
                    "for": [ "Literal" ],
                    "allowElementPrecedingWhitespaces": 0,
                    "allowElementTrailingWhitespaces": 0
                },
                "firstArg": {
                    "for": [ "Literal" ],
                    "allowElementPrecedingWhitespaces": 1
                },
                "lastArg": {
                    "for": [ "Literal" ],
                    "allowElementTrailingWhitespaces": 1
                }
            }
        }
    };
    logger = sniffer.getTestResults( code, OPTIONS, modifiers );
    //console.log(logger.getMessages());
        logger.getMessages().length.should.not.be.ok;
  });
});

from jscodesniffer.

viskenxp avatar viskenxp commented on May 21, 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 = "var a = [1, 2, 3];",

    modifiers = {
      "Indentation": false,
      "QuoteConventions": false,
      "ArrayLiteralSpacing": {
        "allowElementPrecedingWhitespaces": 1,
        "allowElementTrailingWhitespaces": 0,
        "exceptions": {
          "singleArg" : {
            "for": [ "Literal" ],
            "allowArgPrecedingWhitespaces": 0,
            "allowArgTrailingWhitespaces": 0
          },
          "firstArg": {
            "for": [ "Literal" ],
            "allowArgPrecedingWhitespaces": 0
          },
          "lastArg": {
            "for": [ "Literal" ],
            "allowArgTrailingWhitespaces": 0
          }
        }
      },
    };

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

    console.log(logger.getMessages());
    logger.getMessages().length.should.not.be.ok;
  });
});

It seems like the modifiers are ok, but the test fails.

from jscodesniffer.

dsheiko avatar dsheiko commented on May 21, 2024

The correct configuration:

it(" must accept ArrayLiteralSpacing exceptions", function () {
        var code = "var arr = [ 1,2,3 ]",
            modifiers = {
                "ArrayLiteralSpacing": {
                    "allowElementPrecedingWhitespaces": 0,
                    "allowElementTrailingWhitespaces": 0,
                    "exceptions": {
                        "singleElement": {
                            "for": [ "Literal" ],
                            "allowElementPrecedingWhitespaces": 0,
                            "allowElementTrailingWhitespaces": 0
                        },
                        "firstElement": {
                            "for": [ "Literal" ],
                            "allowElementPrecedingWhitespaces": 1
                        },
                        "lastElement": {
                            "for": [ "Literal" ],
                            "allowElementTrailingWhitespaces": 1
                        }
                    }
                }
            };
    logger = sniffer.getTestResults( code, OPTIONS, modifiers );
        logger.getMessages().length.should.not.be.ok;
  });

from jscodesniffer.

viskenxp avatar viskenxp commented on May 21, 2024

Your code style is not the same as mine in your correct configuration.

// Our way of styling arrays.
var arr = [1, 2, 3];

// The way you did in your configuration.
var arr = [ 1,2,3 ];

from jscodesniffer.

dsheiko avatar dsheiko commented on May 21, 2024

Well, no probllem - I have this passing:

it(" must accept ArrayLiteralSpacing exceptions", function () {
        var code = "var arr = [1, 2, 3]",
            modifiers = {
                "ArrayLiteralSpacing": {
                    "allowElementPrecedingWhitespaces": 1,
                    "allowElementTrailingWhitespaces": 1,
                    "exceptions": {
                        "singleElement": {
                            "for": [ "Literal" ],
                            "allowElementPrecedingWhitespaces": 0,
                            "allowElementTrailingWhitespaces": 0
                        },
                        "firstElement": {
                            "for": [ "Literal" ],
                            "allowElementPrecedingWhitespaces": 0
                        },
                        "lastElement": {
                            "for": [ "Literal" ],
                            "allowElementTrailingWhitespaces": 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.