Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What good is JSLint if jQuery fails the validation [closed]

So I have been exploring different methods to clean up and test my JavaScript. I figured just like any other language one way to get better is to read good code. jQuery is very popular so it must have a certain degree of good coding.

So why when I run jQuery through JSLint's validation it gives me this message:

Error:

Problem at line 18 character 5: Expected an identifier and instead saw 'undefined' (a reserved word).

undefined,

Problem at line 24 character 27: Missing semicolon.

jQuery = window.jQuery = window.$ = function( selector, context ) {

Problem at line 24 character 28: Expected an identifier and instead saw '='.

jQuery = window.jQuery = window.$ = function( selector, context ) {

Problem at line 24 character 28: Stopping, unable to continue. (0% scanned).

This was done using JSLint and jquery-1.3.1.js

like image 533
Bobby Borszich Avatar asked Feb 02 '09 22:02

Bobby Borszich


People also ask

What is JSLint used for?

JSLint is a static code analysis tool used in software development for checking if JavaScript source code complies with coding rules. It is provided primarily as a browser-based web application accessible through the domain jslint.com, but there are also command-line adaptations.

Should I use JSLint?

Use JSLint if you're looking for a very high standard for yourself or your team, but bear in mind that it's not necessarily the standard, only a standard, some of which comes to us dogmatically from Doug Crockford.

What is the jQuery validate feature?

The jQuery Validate is a feature provided by jQuery that makes it easier for the creator to validate the user or visitor’s input data while keeping your code free of all the mesh of validation rules from javaScript code.

Is jQuery validate a “must-have” plugin?

Let us see how this Plugin easy-fy your form Validation and prove to be a “must-have” Plugin? The jQuery Validate is a feature provided by jQuery that makes it easier for the creator to validate the user or visitor’s input data while keeping your code free of all the mesh of validation rules from javaScript code.

How to simplify client-side validation with jQuery?

So to simplifying client-side validations and making them more easy for the creator, jQuery provides a simple solution, yet again. jQuery provides a plugin, bundled up with rules, that you do not have to re-define for your form elements and events and simplify your validation purpose.

How to change the src attribute in jQuery validate?

SRC attribute can be changed according to your preference or location of JS file --> When we click on the ‘Register’ button, it shows the validation for all the errors the user made, displaying your defined rules (if any) This is a guide to jQuery Validate.


1 Answers

JSLint tests one particular person's (Douglas Crockford) opinions regarding what makes good JavaScript code. Crockford is very good, but some of his opinions are anal retentive at best, like the underscore rule, or the use of the increment/decrement operators.

Many of the issues being tagged by JSLint in the above output are issues that Crockford feels leads to difficult to maintain code, or they are things that he feels has led him to doing 'clever' things in the past that can be hard to maintain.

There are some things Crockford identifies as errors that I agree with though, like the missing semicolons thing. Dropping semicolons forces the browser to guess where to insert the end-of-statement token, and that can sometimes be dangerous (it's always slower). And several of those errors are related to JSLint not expecting or supporting multiple assignments like jQuery does on line 24.

If you've got a question about a JSLint error, e-mail Crockford, he's really good about replying, and with his reply, you'll at least know why JSLint was implemented that way.

Oh, and just because a library is popular doesn't mean it's code is any good. JQuery is popular because it's a relatively fast, easy to use library. That it's well implemented is rather inconsequential to it's popularity among many. However, you should certainly be reading more code, we all should.

JSLint can be very helpful in identifying problems with the code, even if JQuery doesn't pass the standards it desires.

like image 107
foxxtrot Avatar answered Nov 07 '22 07:11

foxxtrot