Questions tagged [jshint]

A community-driven tool to detect errors and potential problems in JavaScript code and to enforce coding conventions.

About

JSHint is a community-driven tool to detect errors and potential problems in JavaScript code and to enforce coding conventions.

JSHint is very flexible so you can easily adjust it to your particular coding guidelines and the environment you expect your code to execute in.

Interface

JSHint is available:

  • Via a web interface at http://jshint.com/
  • Via npm with npm install jshint or npm install -g jshint for global install
  • As plugins for many text editors and IDEs.

History

JSHint is a fork of JSLint, the tool written and maintained by Douglas Crockford.

The project originally started as an effort to make a more configurable version of JSLint - the one that doesn't enforce one particular coding style on its users — but it then transformed into a separate static analysis tool with its own goals and ideals.

Goals

JSHint's goal is to help JavaScript developers write complex programs without worrying about typos and language gotchas.

Its developers believe that static code analysis programs — as well as other code quality tools — are important and beneficial to the JavaScript community and, thus, should not alienate their users.

Resources

Related Tags

983 questions
66
votes
5 answers

Ignore camelcase variable in JSHint

Having a bit of an issue with JShint and the following line of code. $location.path('map-' + map.id + '/venue-' + map.attributes.default_venue.value); I'm getting the error, Identifier 'default_venue' is not in camel case. This wouldn't be a…
Sam Beckham
  • 1,218
  • 2
  • 12
  • 23
66
votes
3 answers

How to suppress "{variable} is better written in dot notation."

Is there an option to and/or how do I suppress errors like the following? 175,14:['tracker'] is better written in dot notation.
TomFuertes
  • 7,150
  • 5
  • 35
  • 49
64
votes
3 answers

JS Hint - don't make functions within a loop

I can not get around JSHint's error message. Here is the loop I am using: for (i = 0; i < Collection.length; i += 4) { data.push({ items : Collection.slice(i, i + 4).map(function(item) { return { id: item[0], …
myTD
  • 1,459
  • 4
  • 17
  • 30
63
votes
6 answers

Is it bad practice to use the same variable name in multiple for-loops?

I was just linting some JavaScript code using JSHint. In the code I have two for-loops both used like this: for (var i = 0; i < somevalue; i++) { ... } So both for-loops use the var i for iteration. Now JSHint shows me an error for the second…
TimG
  • 985
  • 3
  • 14
  • 24
59
votes
2 answers

jshint throws a"Expected a 'break' statement before 'case'"

Hi I am having a trouble when my framework is using jshint to validate my javascript code. I have used switch-case without a break statement intentionally, but this portion of code is captured as an error when jshint checks. My code is something…
sakthisundar
  • 3,278
  • 3
  • 16
  • 29
59
votes
3 answers

Why is Jshint saying "variable already defined" in this if statement?

I have this code: if ( something is true ) { var someVar = true; } else { var someVar = false; } JsHint is saying that "someVar was already defined" on the else statement part. Why is this and how do I fix it? Thanks
user2413333
  • 1,405
  • 4
  • 18
  • 22
56
votes
4 answers

Disabling warning about "require" function in JSHint

I'm writing some code for Node.js and I'm currently using JSHint to check over my code. However, when I use the require function to import modules, it says: 'require' is not defined. How can I suppress the warning? "use strict"; var express =…
somesh
  • 589
  • 1
  • 5
  • 11
53
votes
16 answers

How to remove global "use strict" added by babel

I'm using function form of "use strict" and don't want global form which Babel adds after transpilation. The problem is I'm using some libraries that aren't using "use strict" mode and it might throw error after scripts are concatenated
ani h
  • 531
  • 1
  • 4
  • 7
53
votes
3 answers

Javascript ENUM pattern naming convention

I am working on a javascript project which requires use of javascript "Enums" meaning Objects like: var WinnerEnum = { Player1: 1, Player2: 2, Draw: 0 }; This is working great for me, however, I have no idea what is the proper way…
Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
50
votes
6 answers

How can I check JavaScript code for syntax errors ONLY from the command line?

JavaScript programs can be checked for errors in IDEs or using online web apps but I'm looking for a way to detect syntax errors alone. I've tried JSLint and JSHint and looked at their options but I haven't been able to find a combination that would…
Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
49
votes
4 answers

Does JSHint support async/await?

I'm using JSHint for the JavaScript project (with the Visual Studio Code). And in this project I use async / await, which JSHint highlights as errors. I tried to set up jshint, but the it seems like the maxim version of "esversion" is 6. Does jshint…
Alena Gilevskaya
  • 535
  • 1
  • 4
  • 8
47
votes
6 answers

Prevent JSHint warning that 'functionName is defined but never used'

I have just started using JSHint (through the Sublime-Linter package for Sublime Text 2). I would like to suppress its warnings regarding functions that are used before they are defined, as I see no problem with using function definitions like this.…
Undistraction
  • 42,754
  • 56
  • 195
  • 331
46
votes
5 answers

Adobe Brackets disable jslint but allow jshint

My basic question: In the Adobe Brackets editor how do I use jshint while turning off or disabling jslint? My tl;dr: When linting javascript in the Adobe Brackets editor I find that I get results for both jslint and jshint. While I have jshint…
rg88
  • 20,742
  • 18
  • 76
  • 110
45
votes
5 answers

Why does JSHint argue against bitwise operators? How should I express this code?

I am using this bit of JavaScript to generate a UID: (original:) //If ID has not been defined then generate a new unique ID. if(!id){ id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v =…
Sean Anderson
  • 27,963
  • 30
  • 126
  • 237
44
votes
3 answers

How to configure Syntastic with JSHint?

How to use the Syntastic Vim plugin with JSHint to validate JavaScript code? Environment: Ubuntu 11.04 VIM - Vi IMproved 7.3 What I have installed, following the solution at VIM + JSLint?: Vundle node.js Node Package Manager jshint,…
Fernando Correia
  • 21,803
  • 13
  • 83
  • 116
1
2
3
65 66