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
1890
votes
14 answers

Turning off eslint rule for a specific line

In order to turn off linting rule for a particular line in JSHint we use the following rule: /* jshint ignore:start*/ $scope.someVar = ConstructorFunction(); /* jshint ignore:end */ I have been trying to locate the equivalent of the above for…
runtimeZero
  • 26,466
  • 27
  • 73
  • 126
464
votes
8 answers

Should I use JSLint or JSHint JavaScript validation?

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…
amateur
  • 43,371
  • 65
  • 192
  • 320
391
votes
19 answers

Why does JSHint throw a warning if I am using const?

This is the error I get when using const: My code looks like this: const…
Andre Schlesinger
  • 3,925
  • 2
  • 12
  • 6
275
votes
3 answers

Is there a way to suppress JSHint warning for one given line?

I have a (single) case in my app were eval is used, and I would like to suppress JSHint warning only for this case. Is there a way to achieve that? Configuration, magic comment, ...?
Mike Aski
  • 9,180
  • 4
  • 46
  • 63
220
votes
9 answers

JSHint and jQuery: '$' is not defined

The following JS: (function() { "use strict"; $("#target").click(function(){ console.log("clicked"); }); }()); Yields: test.js: line 5, col 3, '$' is not defined. When linted using JSHint 0.5.5. Any ideas?
Allyl Isocyanate
  • 13,306
  • 17
  • 79
  • 130
131
votes
3 answers

Explanation of JSHint's Bad line breaking before '+' error

Can someone explain to me why JSHint complains about the following, window.location.href = String1 + '#' + Sting2 + '=' + String3; With the error, Bad line breaking before '+' error I understand that this error can be configured…
James McMahon
  • 48,506
  • 64
  • 207
  • 283
123
votes
4 answers

JavaScript function order: why does it matter?

Original Question: JSHint complains when my JavaScript calls a function that is defined further down the page than the call to it. However, my page is for a game, and no functions are called until the whole thing has downloaded. So why does the…
Chris Tolworthy
  • 2,066
  • 4
  • 20
  • 24
119
votes
6 answers

Gulp Error: Cannot find module 'jshint/src/cli'

So I've got a fresh install of El Capitan and I'm giving these task runners another go. I'm following sitepoint's An introduction to Gulp.js, but I'm stuck on step four, when I try to run gulp jshint I get "Error: Cannot find module…
lateralaus
  • 1,523
  • 3
  • 11
  • 11
109
votes
8 answers

How to disable the warning 'define' is not defined using JSHint and RequireJS

I uses RequireJS AMD in my project. When i run jshint on my project, it throws error like In AMD Scripts 'define' is not defined. In Mocha test cases 'describe' is not defined. 'it' is not defined. How to remove this warning in jshint?
Fizer Khan
  • 88,237
  • 28
  • 143
  • 153
101
votes
4 answers

Why is JSHINT complaining that this is a strict violation?

I think this may be a duplicate of Strict Violation using this keyword and revealing module pattern I have this code: function gotoPage(s){ if(s<=this.d&&s>0){this.g=s; this.page((s-1)*this.p.size);} } function pageChange(event, sorter) { …
Cheeso
  • 189,189
  • 101
  • 473
  • 713
88
votes
4 answers

Jshint.com requires "use strict". What does this mean?

Jshint.com is giving the error: Line 36: var signin_found; Missing "use strict" statement.
user656925
86
votes
3 answers

How to tell JSLint / JSHint what global variables are already defined

In my project we have some global variables that work as containers: MyProject.MyFreature.someFunction = function() { ... } So then I use that script across the site and JSLint / JSHint complains about that: 'MyProject' is not defined I know that…
Emiliano Zilocchi
  • 1,075
  • 1
  • 8
  • 12
80
votes
9 answers

ES6 in JShint - .jshintrc has esversion, but still getting warning (using atom)

I am using atom, and I've tried several different jshint packages and they all give a warning which says "template literal syntax' is only available in ES6 (use 'esversion: 6')" I created a top level .jshintrc file (at root), and added the…
Ron I
  • 4,090
  • 8
  • 33
  • 64
73
votes
4 answers

How to set .eslintrc to recognize 'require'?

I am new to ESLint, and I have successfully integrated ESLint with IntelliJ. Out of the box, my integration of ESLint did not recognize node, but basic review of documentation made clear that by creating the configuration file named .eslintrc at the…
Dan Nissenbaum
  • 13,558
  • 21
  • 105
  • 181
73
votes
5 answers

JSHint "Possible strict violation." when using `bind`

Consider this simple code: "use strict"; var obj = { f: function() { this.prop = 'value'; g.bind( this )(); } }; function g() { console.log( this.prop ); } If I try to validate this code, jshint gives me the error…
Florian Margaine
  • 58,730
  • 15
  • 91
  • 116
1
2 3
65 66