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
0
votes
2 answers

JsHint throwing error regarding "Identifier expected after token"

I have created one small chatting app using node.js and socket.io. It is working fine for me, but my editor's (Eclipse) plug-in JsHint showing me one error in my code as follows. io.sockets.in(room).emit(msgtype, data); Error: Syntax error on token…
Manish Sapkal
  • 5,591
  • 8
  • 45
  • 74
0
votes
1 answer

Warning JSHint with backbone : Expected an assignment or function call and instead saw an expression

On all my JS files, i have a warning of JSHint : Expected an assignment or function call and instead saw an expression. A example : /*global App, Backbone*/ App.Routers = App.Routers || {}; (function () { 'use strict'; …
Dossp
  • 29
  • 6
0
votes
2 answers

jshint expected an assignment error

// BAR CHART if (sparklineType == 'bar') { barColor = $this.data('sparkline-bar-color') || $this.css('color') || '#0000f0', sparklineHeight = $this.data('sparkline-height') || '26px', …
0
votes
1 answer

Why does using `this` within function give me a "Possible strict violation" in jshint?

Say I have a function that I would like reuse as a method on a couple objects in order to add data to those objects. function addToObject(data) { for (var d in data) { if (data.hasOwnProperty(d)) { this[d] = data[d]; } …
Trav McKinney
  • 988
  • 8
  • 24
0
votes
1 answer

'Modernizr' is not defined / 'Modernizr' was used before it was defined

I am using codekit to put together a few things. jQuery Modernizr (prepended to the script below) So I'm just troubleshooting some things and getting back to basics on a project. As is, jsHint returns the error if (Modernizr.touch) { 'Modernizr'…
sheriffderek
  • 8,848
  • 6
  • 43
  • 70
0
votes
2 answers

Javascript validation/inspection: Detect the use of undeclared methods or properties of an object

Please consider the following code. The following is according to JSLint or JSHint perfectly valid Javascript code: function fun() { "use strict"; var myvar = ""; myvar.foo(); } The following not: function fun() { "use strict"; …
finrod
  • 521
  • 8
  • 21
0
votes
0 answers

Javascript - Build/Lint time check for undefined object references

I am seeing if there is a build time (using Grunt or maybe JSHint) to only use defined object references. Given this object, throw an error at build (parse) time if referencing an undefined property: var o = { foo: 'has a value.', num:…
beeryardtech
  • 605
  • 1
  • 4
  • 15
0
votes
2 answers

IntelliJ IDEA / WebStorm "noinspection JSHint" vs "jshint ignore:line"

Is there a way to configure IntelliJ IDEA / WebStorm to add // jshint ignore:line in order to suppress JSHint warnings? By default, IntelliJ adds //noinspection JSHint, which is not recognized by JSHint itself.
jeromerg
  • 2,997
  • 2
  • 26
  • 36
0
votes
1 answer

Regular expression causes js hint error

Hi I am using this RegExp to parse a url. var urlRegex =…
user3310447
  • 135
  • 2
  • 13
0
votes
0 answers

Use the function form of "use strict"

I have the same error when I run jshint app.js or use Sublime 2.0 with sublimelinter. My configuration looks very similar in sublimelinter and in package.json: "evil": true, "regexdash": true, "browser": true, "wsh": true, …
Thomas
  • 503
  • 1
  • 12
  • 18
0
votes
1 answer

grunt jshint angular service Missing 'new' prefix when invoking a constructor

gruntfile module.exports = function(grunt) { // Project configuration. grunt.initConfig({ // This line makes your node configurations available for use pkg: grunt.file.readJSON('package.json'), banner: …
Whisher
  • 31,320
  • 32
  • 120
  • 201
0
votes
1 answer

JSHint not handling defineProperty syntax?

I have this piece of code in a constructor function: Object.defineProperty(this, "color", { get : function() { return color; }, set : function(newVal) { color = newVal; …
devboell
  • 1,180
  • 2
  • 16
  • 34
0
votes
1 answer

Alternative to making functions in a loop

I have a the following code this.addHandlers = function (interactions) { for(var eventType in interactions) { if(interactions[eventType]) { this.on(eventType, function () { // do something with…
Jim Jeffries
  • 9,841
  • 15
  • 62
  • 103
0
votes
1 answer

grunt-contrib-jshint is not ignoring specified directories

I have the following folders and files: js/ lib/ jQuery.js compiled/ all.js file1.js file2.js I want JSHint to lint only file1 and file2 (without having to specify the exact files) and for it not to lint the lib folder and…
ajcw
  • 23,604
  • 6
  • 30
  • 47
0
votes
1 answer

useminPrepare options property not defined

I'm getting a jshint error when I run grunt from the command line. Running "useminPrepare:html" (useminPrepare) task Going through public/index.html to update the config Looking for build script HTML comment blocks Warning: An error…
Connor Leech
  • 18,052
  • 30
  • 105
  • 150