• Stars
    star
    688
  • Rank 65,712 (Top 2 %)
  • Language
    Python
  • Created about 13 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JSHint Gutter for Sublime Text 2 and 3 via node.js

JSHint Gutter for Sublime Text 2 and 3 via node.js

Sublime Text 3

JSHint

Node.js download

About

This is a Sublime Text 2 and 3 plugin allowing you to check your JavaScript code for nasty errors, coding conventions and other goodies. It relies on JSHint, a fork of JSLint (developed by Douglas Crockford). The linter is itself written in JavaScript, so you'll need something (node.js) to interpret JavaScript code outside the browser.

Screenshot

Installation

First of all, be sure you have node.js installed in order to run JSHint (a derivative work of JSLint, used to detect errors and potential problems in JS). Each OS has a different Packages folder required by Sublime Text. Open it via Preferences -> Browse Packages, and copy this repository contents to a new Sublime-JSHint folder there.

The shorter way of doing this is:

Through Sublime Package Manager

  • Ctrl+Shift+P or Cmd+Shift+P in Linux/Windows/OS X
  • type install, select Package Control: Install Package
  • type js gutter, select JSHint Gutter

Manually

Make sure you use the right Sublime Text folder. For example, on OS X, packages for version 2 are in ~/Library/Application\ Support/Sublime\ Text\ 2, while version 3 is labeled ~/Library/Application\ Support/Sublime\ Text\ 3.

These are for Sublime Text 3:

Mac

git clone https://github.com/victorporof/Sublime-JSHint.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Sublime-JSHint

Linux

git clone https://github.com/victorporof/Sublime-JSHint.git ~/.config/sublime-text-3/Packages/Sublime-JSHint

Windows

git clone https://github.com/victorporof/Sublime-JSHint.git "%APPDATA%/Sublime Text 3/Packages/Sublime-JSHint"

Usage

Tools -> Command Palette (Ctrl+Shift+P or Cmd+Shift+P) and type jshint.

-- or --

Ctrl+Shift+J (or Cmd+Shift+J if you're on a Mac).

-- or --

Right click in the current buffer and select JSHint -> Lint Code.

-- or --

Open a JavaScript file, pop out the console in Sublime Text from View -> Show Console, and type view.run_command("jshint").

Writing commands in the console is ugly. Set up your own key combo for this, by going to Preferences -> Key Bindings - User, and adding a command in that array: { "keys": ["super+shift+j"], "command": "jshint" }. You can use any other command you want, though most of them are already taken.

Oh noez, command not found!

If you get an error sh: node: command not found or similar, you don't have node in the right path. Try setting the absolute path to node in JSHint.sublime-settings.

  • Ctrl+Shift+P or Cmd+Shift+P in Linux/Windows/OS X
  • type jshint, select Set node Path

Simply using node without specifying a path sometimes doesn't work :(

For example, on Linux the path could be in /home/<user>/.nvm/<node version>/bin/node.

On Windows, the absolute path to node.exe must use forward slashes.

Be very careful on Linux!

Depending on your distribution and default package sources, apt-get install node (for example) will not install node.js, contrary to all human common sense and popular belief. You want nodejs instead. Best thing is to make it yourself from http://nodejs.org/#download.

Automatically linting on edit, load or save

This plugin can be set to automatically lint when a file is loaded, saved, or the current buffer is modified.

  • Ctrl+Shift+P or Cmd+Shift+P in Linux/Windows/OS X
  • type jshint, select Set Plugin Options

Note that live linting while editing is only available in Sublime Text 3.

Using your own .jshintrc options

The plugin looks for a .jshintrc file in the same directory as the source file you're prettifying (or any directory above if it doesn't exist, or in your home folder if everything else fails) and uses those options along the default ones. Here's an example of how it can look like.

These are the default options used by this plugin:

{
  // Details: https://github.com/victorporof/Sublime-JSHint#using-your-own-jshintrc-options
  // Example: https://github.com/jshint/jshint/blob/master/examples/.jshintrc
  // Documentation: http://www.jshint.com/docs/
  "browser": true,
  "esnext": true,
  "globals": {},
  "globalstrict": true,
  "quotmark": true,
  "undef": true,
  "unused": true
}

And here's how a .jshintrc file in your home folder could look like:

{
  "esnext": false,
  "moz": true,
  "boss": true,
  "node": true,
  "validthis": true,
  "globals": {
    "EventEmitter": true,
    "Promise": true
  }
}

See the documentation at jshint.com and a few examples here.

A few persistent options are always applied from a .jshintrc file located in the same directory as the plugin, if not overwritten by your own .jshintrc file. Those are defined here. You can safely add stuff to that json file if you want:

  • Ctrl+Shift+P or Cmd+Shift+P in Linux/Windows/OS X
  • type jshint, select Set Linting Preferences

Alternative for NPM packages

Alternatively for an NPM package, you can omit the .jshintrc file and instead place your jshint options in your package.json file as the property jshintConfig1. Check an example here.

Thank you!

More Repositories

1

Sublime-HTMLPrettify

HTML, CSS, JavaScript, JSON, React/JSX and Vue code formatter for Sublime Text 2 and 3 via node.js
JavaScript
1,924
star
2

Tilt

Tilt: a WebGL-based 3D visualization of a Webpage
JavaScript
488
star
3

rsx

Advanced JSX-like templating for Rust
Rust
320
star
4

firefox-restartless-template

Simple template project for developing restartless Firefox Developer Tools addons.
JavaScript
75
star
5

atom

Atom | Piano Roll 2: The scripting/styling documentation.
JavaScript
25
star
6

rsx-demo

Several demos for embedding RSX code
Swift
25
star
7

rsx-parser

JSX-like parser combinator for Rust
Rust
23
star
8

BeagleBone-SPI-UART

Enables SPI and UART (serial tty*) hardware ports on the BeagleBone Black
JavaScript
20
star
9

BDF.js

Simple library for reading Adobe Glyph Bitmap Distribution font files
JavaScript
15
star
10

MAX7219.js

Abstraction for the MAX7219 display driver controller
JavaScript
13
star
11

rsx-dom

Simple node tree abstraction layer over RSX syntax trees
Rust
13
star
12

rsx-layout

Flexbox layout engine for RSX DOM trees using YOGA
Rust
11
star
13

rsx-primitives

Basic component primitives necessary to render any RSX elements
Rust
10
star
14

servo-css-parser

Servo's CSS parser as a usable standalone crate
Rust
7
star
15

rsx-renderers

Several renderers for DisplayLists generated by the RSX Primitives library
JavaScript
7
star
16

rust-enum-str-derive

Self stringifying enum variants
Rust
5
star
17

reactenstein

Custom React reconciler using RSX as a backend
JavaScript
5
star
18

demo-angular

TypeScript
5
star
19

rsx-stylesheet

Simple style tree abstraction layer for RSX over Servo CSS stylesheets
Rust
4
star
20

javascript-AES

AES cipher implementation in JavaScript
JavaScript
3
star
21

rust-self-tokenize

Self tokenizing Rust data structures
Rust
2
star
22

noop-react-reconciler

A react reconciler that does absolutely nothing
JavaScript
2
star
23

rsx-shared

Traits and types shared between all RSX modules
Rust
2
star
24

rsx-resources

Resources cache for RSX
Rust
1
star
25

rsx-event-manager

Event manager for RSX
Rust
1
star
26

YouTube-Animated-Thumbnails

Firefox extension that animates the video thumbnails on YouTube
Shell
1
star
27

rsx-embedding

Several macros and helpers for embedding RSX Renderers on various platforms
Rust
1
star