Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling warning about "require" function in JSHint

People also ask

How do I ignore JSHint warning?

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.

What is JSHint used for?

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).

What is JSHint node?

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.

Is node JS a server?

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:

  1. Open JSON Settings file using the Preferences: Open Settings (JSON) via the Command Palette Window (Ctrl-Shift-P).
  2. Add this section into the settings.json file:

    { "jshint.options": { "esversion": 8, // This gets rid of some other warnings "node": true } }