JSLint: control comments (selective ignore)

后端 未结 9 1708
一生所求
一生所求 2020-12-01 06:16

Does JSLint have anything like JavaScript Lint\'s control comments (e.g. /*jsl:fallthru*/) to make it ignore certain passages?

相关标签:
9条回答
  • 2020-12-01 06:31

    This seems to work for me. (using the jslint embedded in zedapp - zedapp.org)

    /*jslint ignore:start*/
    require([],function(require, exports, module) {
      /*jslint ignore:end*/
      
      var api = {
        life: {
          universe: {
            everything: function() {
              this.everything = {answer : 42};
            }
          }
        }
      };
     api.life.universe.everything.bind(api.life.universe)();
     console.log(JSON.stringify(api));
    
      /*jslint ignore:start*/
      return api;
    });
    /*jslint ignore:end*/
    <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.js"></script>

    0 讨论(0)
  • 2020-12-01 06:38

    Nothing here has answered this question as far as I am able to tell. The following code still gives me validation errors and I can't get JSLint to accept that I don't have time to correct a working regular expression right now given ACTUAL PRIORITIES.

    The error I'm receiving regards an unescaped '{' and may result in my new, professional team rejecting JSLint as a feasible tool. There appears to be no way to shut it up regarding our efforts to develop more efficiently, which seems problematic.

    /*jslint browser: true, devel: true, todo: true, regexp: true */
    /*global $ */
    /*
        Abstract:
            + This module constitutes a layer of abstraction surrounding our bootstrap dependencies.
            + This module also contains some utility functions (so find a better place for them already!).
        Validation:
            + This module has been validated using JSLint (www.jslint.com).
    */
    var shoelaceModule = (function () {
        'use strict';
        return {
            showModal: function ($target) {
                $target.modal('show');
            },
    
            hideModal: function ($target) {
                $target.modal('hide');
            },
    
            /*jsl:ignore */
            /*ignore jslint start */
            stringFormat: function (format) {
                var args = Array.prototype.slice.call(arguments, 1);
                return format.replace(/{([^{}]*)}/g, function (match, number) {
                    return args[number] !== 'undefined' ? args[number] : match;
                });
            },
            /*ignore jslint end */
            /*jsl:end */
    
            init: function () {
                return this;
            }
        };
    }());
    
    0 讨论(0)
  • 2020-12-01 06:49

    Put

    /*ignore jslint start*/
    

    before and

    /*ignore jslint end*/ 
    

    after the code to be ignored. Ex:

    function ignore(){
        /*ignore jslint start*/
        var x; var y;
        /*ignore jslint end*/
    }
    

    Or export JsLint settings, define your IgnoreErrorStart/ IgnoreErrorEnd symbols and import.


    Edit
    Some folks may confuse this answer with JSHint. In that case, use these:

    /*jshint ignore:start*/
      <!-- code in here -->
    /*jshint ignore:end*/
    

    Taken from https://stackoverflow.com/a/26012357/313501

    0 讨论(0)
  • 2020-12-01 06:50

    Yes. From the documentation [note that this is from an older version of the docs, but it still applies]:

    The implementation of JSLint accepts an option object that allows you to determine the subset of JavaScript that is acceptable to you. It is also possible to set those options within the source of a script.

    An option specification can look like this:

    /*jslint nomen: true, debug: true,
      evil: false, vars: true */
    

    An option specification starts with /*jslint. Notice that there is no space before the j. The specification contains a sequence of name value pairs, where the names are JSLint options, and the values are true or false. An option specification takes precedence over the option object.

    The documentation doesn't specifically mention it, but you can enable and disable different checks throughout the code with multiple jslint comments (thanks Dominic Mitchell).

    There is a complete list of options in the documentation.

    0 讨论(0)
  • 2020-12-01 06:51

    Here is a code example to supplement Matthew Crumley's excellent answer:

    (function ($) {
      $.isValidEmail = function(email){
        /*jslint maxlen: 1000*/
        var EMAIL_REGEXP = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
        /*jslint maxlen: 200*/
        return EMAIL_REGEXP.test(email);
      };
    }(jQuery));
    
    0 讨论(0)
  • 2020-12-01 06:51

    It doesn't seem so. Some Googling finds several posts by others, and responses from JSLint people along the lines of "Fix your code instead of labeling it intentionally defective." Doesn't seem entirely friendly. Of course, maybe in this case you should just fix the code, but I leave that for you to answer.

    0 讨论(0)
提交回复
热议问题