In October 2013 jshint added a way to ignore blocks of code like this: // Code here will be linted with JSHint. /* jshint ignore:start */ // Code here will be ignored by JSHint. /* jshint ignore:end */ // Code here will be linted with JSHint.
JSHint is a static code analysis tool used in software development for checking if JavaScript source code complies with coding rules. JSHint was created in 2011 by Anton Kovalyov as a fork of the JSLint project (by Douglas Crockford).
JSHint is a program that flags suspicious usage in programs written in JavaScript. The core project consists of a library itself as well as a CLI program distributed as a Node module.
Node. js is an open source server environment. Node. js uses JavaScript on the server.
jshint is not aware of node.js globals by default you need to inform it.
add this comment to the top:
/* jshint node: true */
We can set node
as the global environment variable in JSHint's .jshintrc
file
This option defines globals available when your code is running inside of the Node runtime environment. Node.js is a server-side JavaScript environment that uses an asynchronous event-driven model. This option also skips some warnings that make sense in the browser environments but don't make sense in Node such as file-level use strict pragmas and console.log statements.
For more info http://jshint.com/docs/options/#node
{
"node": true
}
Errors like 'require' is not defined
, 'console' is not defined
, 'module' is not defined
won't show up any more
You can configure JSHint by adding "require" to the .jshintrc
file. For instance:
{
"globals" : {
"require": false
}
}
Or you can define globals per specific file only by:
/* global require */
For more information about how to configure JSHint please read JSHint Documentation
I stumbled upon this answer and couldn't get anything to work in VSCode. I got this to work:
Preferences: Open Settings (JSON)
via the Command Palette Window (Ctrl-Shift-P).Add this section into the settings.json
file:
{
"jshint.options": {
"esversion": 8, // This gets rid of some other warnings
"node": true
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With