InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Javascript

    Javascript strings

    • Javascript - check if string is number
    • Javascript - parseInt
    • string ends with check
    • string starts with check

    Javascript Array

    • array forEach
    • array append item
    • array remove last item
    • array prepend item
    • array remove first item
    • create array from 0 to N-1
    • convert array to json string

    Javascript control flow

    • for-in loop to iterate over keys of javascript object

    Javascript DOM

    • Javascript - DOM appendChild example
    • Javascript - get computed style of an element
    • Javascript - how to view text inside DOM element
    • Javascript - img onload examples
    • Javascript - ready vs on load event handler example
    • Javascript - use querySelector to set dom element html
    • Javascript DOMContentLoaded listener example
    • Javascript event bubble vs capture
    • Javascript how to stop event propagation
    • Javascript onscroll event handler
    • Javascript onscroll event handler with throttling
    • Make an element draggable using Vanilla Javascript
    • Multiple onload handlers using vanilla Javascipt
    • Use universal selector to get all DOM nodes in vanilla Javascript
    • document querySelector examples
    • dump all handlers on window object

    Javascript Cookbook

    • Are Javascript functions objects?
    • Declare and invoke anonymous function
    • HTML5 drag and drop
    • JSLint on command line on Ubuntu
    • Javascript - call vs apply
    • Javascript - implement class using function
    • Javascript - iterate over function arguments
    • Javascript - print all methods of an object
    • Javascript - run a function at regular interval
    • Javascript - textarea and text input select all
    • Javascript arrow function examples
    • Javascript check if variable is defined
    • Javascript local and global variables
    • Javascript parse json string
    • Javascript prototype examples
    • Javascript settimeout example
    • Javascript sleep implementation
    • Requirejs - quickstart guide for beginners
    • catch errors using window.onerror
    • print javascript object to log

    Javascript libraries

    • AngularJS
    • CasperJS
    • PhantomJS
    • React
    • jQuery

    Javascript global functions

    • Javascript - Number function
     
    • Home
    • > Tutorials
    • > Javascript

    Using JSLint on command line on Ubuntu linux – quick start guide

    By admin | Last updated on Mar 20, 2016

    Sometimes javascript is developed and tested by pushing it to the website and then checking if it is working in browser as intended. If your code base is large then pushing it to a development server can be time consuming. Using JSLint on command line, we can find many errors in the javascript without the need of a web browser.
    jslint-logo

    JSLint Introduction

    Here is the definition of JSLint as per Wikipedia JSLint page:

    JSLint is a static code analysis tool used in software development for checking if JavaScript source code complies with coding rules. It was developed by Douglas Crockford.

    You can get detailed information about jslint on the JSLint official site. It is also interesting to note that JSLint itself is written in Javascript. Its source code can be accessed from jslint github page.

    Installing Jslint on Ubuntu Linux

    We’ll be using the node.js version of JSLint (node-jslint) for running jslint on command line. Here are the steps to install it on Ubuntu Linux:

    1. First install nodejs and npm on Ubuntu Linux.
    2. Using npm, install jslint using the following command:
      sudo npm install -g jslint

      Note that -g is for global install which installs jslint in /usr/local/lib/node_modules/.

    3. Now run jslint on command line without any argument. You should see the help message.
      No files specified.
      Usage: /usr/local/bin/jslint [--indent] [--maxerr] [--maxlen] [--predef] [--anon] [--bitwise] [--browser] [--cap] [--continue] [--css] [--debug] [--devel] [--eqeq] [--es5] [--evil] [--forin] [--fragment] [--newcap] [--node] [--nomen] [--on] [--passfail] [--plusplus] [--properties] [--regexp] [--rhino] [--undef] [--unparam] [--sloppy] [--stupid] [--sub] [--vars] [--white] [--widget] [--windows] [--json] [--color] [--terse] [--] <scriptfile>...

    Using JSLint

    JSLint can be used on one or more javascript files. Here are some notes on how to use JSLint on command line:

    1. To run jslint on foo.js, run this command:
      jslint foo.js
    2. If you get “Missing ‘use strict’ statement.” error message, then add the following line to your code:
      "use strict";

      Note that this line is a backward compatible line and does not cause any problem even is the some browser javascript interpreter does not recognize it. It is just treated as a harmless string in that case.

    3. If you are using a global variable (e.g. jQuery), you may get this eror:
      'jQuery' was used before it was defined.

      To fix this add /*global jQuery */ somewhere at the top of your js file.

    4. JSLint assumes an indentation of 4 spaces. In case you are using a 2 space indent, run jslint with –indent 2. Here is how it will look like:
      jslint --indent 2 foo.js

      or alternatively you can add /*jslint indent: 2 */ line at the top of your file.

    5. In case you are using a bash script to push your code to development or production server,  you can use set -e and do a jslint before the code push line. That way if there is a jslint error, the script will exit instead of continuing. Here is how the bash script code will look like:
      #!/bin/bash
      set -e
      jslint foo.js
      ## Commands to push code to server
      ...

    Using JSLint on command line can help you detect many javascript errors much faster and thus lead to an improved workflow. It also keep javascript code lot more readable and hence more maintainable.

    Suggested posts:

    1. HTML import
    2. LXC (Linux Containers) – quick start tutorial on Ubuntu
    3. Python re search vs match
    4. How to use CasperJS to automate website testing
    5. document querySelector examples
    6. How to install phantomjs on Mac
    7. How to use phantomjs to create site/url snapshot thumbnail
    8. CSS max-width – limit maximum wodth of an element
    Share this article: share on facebook share on linkedin tweet this submit to reddit
    Posted in Tutorials | Tagged Javascript, Javascript cookbook, Node.js, Tutorials, Ubuntu Linux, Web Development
    • Browse content
    • Article Topics
    • Article archives
    • Contact Us
    Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

    Copyright © 2025 InfoHeap.

    Powered by WordPress