Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use JSLint or JSHint JavaScript validation? [closed]

I am currently validating my JavaScript against JSLint and making progress on, it's assisting me to write better JavaScript - in particular in working with the Jquery library.

I have now come across JSHint, a fork of JSLint.
So I am wondering for web applications, which are very much JavaScript was driven, which is the better or most applicable validation tool to work against:

  • JSLint or JSHint?

I want to decide now on a validation mechanism and moving forward, use this for client side validation.

And Difference between jshint and jslint? Please explain in single javascript example.

Links:

  1. jshint- http://www.jshint.com/

  2. jslint- http://jslint.com/

like image 539
amateur Avatar asked Jul 23 '11 21:07

amateur


People also ask

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.

Is JSHint good?

JSHint is strong second choice. If you don't need the advanced features of ESLint, JSHint catches a good number of issues once properly configured.

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.

What is the difference between JSLint and ESLint?

ESLint: The fully pluggable JavaScript code quality tool. A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease; JSLint: A Code Quality Tool for Javascript.


1 Answers

TL;DR

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.

If you want to be a bit more flexible or have some old pros on your team that don't buy into JSLint's opinions or are going back and forth between JavaScript and other C-family languages regularly, try JSHint.

Full version

Two articles with the reasoning behind the fork explain why JSHint exists:

  1. JSHint: A Community-Driven Fork Of JSLint

  2. Why I forked JSLint to JSHint

The idea behind JSLint is that it's community-driven rather than Crockford-driven. JSHint is generally more lenient (or at least configurable or agnostic) on a few stylistic and minor syntactical opinions that JSLint is a stickler for.

For example, if you think both 1. and 2. below are fine, or if you want to write code with one or more of 1.'s aspects that aren't available in 2., JSHint is for you. If you think 2. is the only correct option, use JSLint. I'm sure there are other differences, but this highlights a few.

  1. Passes JSHint out of the box - fails JSLint

    (function() {   "use strict";   var x=0, y=2;   function add(val1, val2){     return val1 + val2;   }   var z;   for (var i=0; i<2; i++){     z = add(y, x+i);   } })(); 
  2. Passes Both JSHint and JSLint

    (function () {     "use strict";     var x = 0, y = 2, i, z;     function add(val1, val2) {        return val1 + val2;     }     for (i = 0; i < 2; i += 1) {         z = add(y, x + i);     } }()); 

I find the JSLint code more visually appealing. The only features of it that I disagree with are its hatred of more than one var declaration in a function and of for-loop var i = 0 declarations, and some of the whitespace enforcements for function declarations.

A few of the whitespace things that JSLint enforces are not necessarily bad but are just out of sync with some pretty standard whitespace conventions for other languages in the family (C, Java, Python, etc.) often followed as conventions in Javascript as well. Since I'm writing in various of these languages throughout the day and working with team members who don't like Lint-style whitespace in our code, I find JSHint to be a good balance. It catches legitimate bugs and very badly formed code, but doesn't bark at me like JSLint does (sometimes, in ways I can't disable) for the stylistic opinions or syntactic nitpicks that I don't care for.

A lot of good libraries aren't Lint'able, which to me demonstrates that there's some truth to the idea that some of JSLint is just about pushing one version of "good code" (which is, indeed, good code). But then again, the same libraries (or other good ones) probably aren't Hint'able either, so, touché.

like image 81
B Robster Avatar answered Sep 18 '22 03:09

B Robster