JSHint is not working

4.2k views Asked by At

enter image description hereenter image description hereI have installed jshint using the following command

 npm install -g jshint

I have test.js file with the following statement

      console.log(a)

I tested the file using the following command

    jshint test.js

Problem: jshint is not working

It should throw the following error/warning

  1. One warning - Missing semicolon

  2. One undefined variable - a

Contents of .jshintrc file

 {

  "bitwise"       : true,     // Prohibit bitwise operators (&, |, ^, etc.).
  "curly"         : true,     // Require {} for every new block or scope.
  "eqeqeq"        : true,     // Require triple equals i.e. `===`.
  "forin"         : true,     // Tolerate `for in` loops without `hasOwnPrototype`.
  "immed"         : true,     // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
  "latedef"       : true,     // Prohibit variable use before definition.
  "newcap"        : true,     // Require capitalization of all constructor functions e.g. `new F()`.
  "noarg"         : true,     // Prohibit use of `arguments.caller` and `arguments.callee`.
  "noempty"       : true,     // Prohibit use of empty blocks.
  "nonew"         : true,     // Prohibit use of constructors for side-effects.
  "plusplus"      : true,     // Prohibit use of `++` & `--`.
  "regexp"        : true,     // Prohibit `.` and `[^...]` in regular expressions.
  "undef"         : true,     // Require all non-global variables be declared before they are used.
  "strict"        : true,     // Require `use strict` pragma in every file.
  "trailing"      : true     // Prohibit trailing whitespaces.
 }

Note: I have tried re-installing jshint with reference as well.

Any suggestion will be grateful.

1

There are 1 answers

0
karthick On BEST ANSWER

Installing Node an npm through the official repositories has always given me trouble. I suspect that this could be due to tools depending on node, when the actual command on Ubuntu is nodejs.

Follow the steps to make jshint work

  1. Remove node and npm

  2. Reinstall the node using nvm. Following command will do the stuff.

    curl https://raw.githubusercontent.com/creationix/nvm/v0.15.0/install.sh | bash
    source ~/.nvm/nvm.sh
    nvm install 0.12 
    nvm use 0.12
    

    Note: Now you should be able to run Node with the node command, you should be able to install modules globally without sudo

  3. Now install the jshint globally using the following command

    npm install -g jshint
    

Now jshint will work like a charm :)