Git Product home page Git Product logo

sublime-jshint's Introduction

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

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:

  • 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!

sublime-jshint's People

Contributors

area avatar bcomnes avatar borysf avatar cytodev avatar eoftedal avatar falsefalse avatar jdavisclark avatar jm3 avatar orlandocr avatar pizzabrandon avatar sevastos avatar shovon avatar ulidtko avatar valueof avatar victorporof avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sublime-jshint's Issues

Integration with Rails Assets Pipeline

Hi,

I don't consider this an issue, but it would be awesome if this could read JS files with require directives from Rails assets pipeline. Example:

I have a file called info.js that reads:

//= require jquery
function initializeJSPlugins($target) {
  if ( $target === undefined ) { $target = $("body"); }
}

JSHint tells me that $ is undefined, but only bacuase it didn't read the line //= require jquery properly. I'm not asking it to JSHint jquery, just this file, but after reading jquery... does that make any sense?

If my request does make sense and there's any way to make this to work please let me know. Thanks in advance 👍

.jshintignore not being honored

I have a .jshintignore file and inside is
test/**/*
However when saving (which executes jshint) it is still throwing the warnings. I would like for the jshintignore file to specify files that when linted do not throw warnings.

Misformatted .jshintrc should produce some visible error

It looks like it uses some default values if there's an error (but the user has no idea). For example, I've had a trailing comma in the globals object:

"globals": {
"_": true,
},
"smarttabs": true,
...
The plugin misbehaved, it jshinted my code as if smarttabs was set to false.

Node.js was not found in the default path, but I have specified it?

In ~/.config/sublime-text-3/Packages/JSHint Gutter/JSHint.sublime-settings

In console:

% which node
/usr/local/bin/node

Then in settings:

"node_path": "/usr/local/bin/node",

But I still get the error and the process fails.

Using build 3047 on Linux (Lubuntu).

Any ideas?

When indenting with tabs, wrong symbol gets squiggly underline

screen shot 2013-08-15 at 11 55 45 am

As you can see in the screenshot, the wrong symbol is underlined. The word "template" should be underlined.

The reason for this is that jshint considers tabs 4 columns wide (jshint/jshint#805), but the col parameter in Sublime's text_point funtion "is interpreted as the number of characters to advance past the beginning of the row."

Setting "indent": 1 in .jshintrc fixes the problem for me, but it would be better if this worked by default.

"Mixed double and single quotes." false positives.

Any time there's 2 double quotes, Sublime-JSHint says:

"Mixed double and single quotes."

It points to code such as the return statement in:

if (index < 0) {
    return "";
}

Mixed quotes aren't being used there. Why is a false positive being thrown?

Please re-think/remove shortcuts

Don't know how stuff works on other platforms, but on Windows there are some small issues:

On default keymap file:

{ "keys": ["ctrl+shift+j"], "command": "expand_selection", "args": {"to": "indentation"} }

Also, ctrl+esc is equivalent with pressing windows key (will show start menu).

So you should either remove or disable shortcuts completely (see emmet for inspiration)

Oh, and btw, the plugin make my editor freeze (latest ST3 dev release, but I'm pretty sure there is a pluggin that is messing around because vanilla ST3 works just fine)

Differentiate Errors and Warnings

I'm not sure whether JSHint supports this, but it would be great to get different icons for errors, warnings (e.g. unused variables) and suggestions ("did you mean…?").

Please update to JSHint 2.3.0

JSHint has updated to 2.3.0 and includes a number of updates, including (important to me) switch/case indent fixes. It would be nice to get rid of my redlines. 👍

sometimes error messages appear in wrong lines

lint
Consider the following example (there's a trailing whitespace in the 2nd line, right after "1,"):

var a = [
    1, 
];
console.log(a);

It shows me error in line 3. The error says "2: 7 trailing whitespace."

Linting json files?

I'm unsure if this is an issue in the plugin or not.

It looks like the jshint is being applied to .json files, when I'm pretty sure it shouldn't be. For example, I have the rule that says "quotmark": "single" so my valid json files get highlighted as all wrong.

Shouldn't the linter apply to .js files (or user specified) only? And not apply to .json files?

Helpful Tip for Windows

You may want to add this helpful info for Windows users. The basic Node install on Windows would change the JSHint settings to the following for it to work...

"node_path": "/Program Files/nodejs/node.exe",

Warning icon does not show up correctly on OS X

The warning icon that is supposed to show up in the gutter is shown as corrupted bitmap:

screen shot 2013-09-16 at 22 35 28

Note: the ST console shows the following message:
Unable to decode Packages//Users/luc/Dropbox/Sync/Sublime Text 3/Packages/JSHint Gutter/warning.png

This is using ST3 (build 3047) under OS X 10.8.5.

Configurable delay before linting

Proposition:
Can you add option to setting 'linting_delay'. So that hinter will wait for this delay after I stop changing buffer before linting. Changing buffer should reset timer to wait another delay.

Error in Windows 7 x64

I have Sublime Text 2 Build 2181 installed with node.js in Windows 7 x64.

If i open a javacsript file (filename.js) and do ctrl+b, with build selected in JSHint, it give me this error:

[Decode error - output not utf-8][Finished]

But if i open console i will see this:

Running node D:\Users\Exadra37\AppData\Roaming\Sublime Text 2\Packages/Sublime-JSHint/scripts/run.js ajax.js browser: true v8: true es5: true esnext: true globalstrict: true strictundef: true laxradix: true trailing: true undef: false sub: true

Now if i try to use as python plugin with ctrl+alt+j that i defined in user key binding { "keys": ["ctrl+alt+j"], "command": "jshint" } , i don´t see anything happen.

Also if i try to run from ctrl+shift+p and select JSHint : Linter , nothing happens.

For last i try to run from console with view.run_command("jshint") and show this in console:

view.run_command("jshint")

This is a bug or i am do anything wrong?

Allow specifying options through a config file

Currently, the only way to specify options is in the .sublime-build file. However, this means that settings that I use in my build system (using a .json config file) are unusable.

If there's already a way to do so, I'll be grateful to know about it, else could you consider adding this feature please?

moz option not working

I am not sure if this is Sublime-JSHint or JSHint.

In Firefox source try linting browser/devtools/inspector/selection.js

I receive the error:
'function closure expressions' is only available in Mozilla JavaScript extensions (use moz option).

Here is my .jshintrc:
{ "browser": true, "esnext": true, "moz": true, "globals": {}, "globalstrict": false, "quotmark": true, "smarttabs": true, "trailing": true, "undef": true, "unused": true }

The moz option is set to true so it should be used.

clicking on a JSHint buffer throws TypeError in console error

In ST2 and ST3, clicking the mouse in a JSHint buffer while the console is open gives this error on every click:

Traceback (most recent call last):
  File "/Applications/Sublime Text 3.app/Contents/MacOS/sublime_plugin.py", line 287, in on_selection_modified
    callback.on_selection_modified(v)
TypeError: on_selection_modified() takes 1 positional argument but 2 were given
Traceback (most recent call last):
  File "/Applications/Sublime Text 3.app/Contents/MacOS/sublime_plugin.py", line 287, in on_selection_modified
    callback.on_selection_modified(v)
TypeError: on_selection_modified() takes 1 positional argument but 2 were given

Add the ability to get the JSHint error-output on the console instead of a GUI window

Hello guys,

I like this plugin really much and I'm using it every day at work but it would be really nice to get the error-output in the console instead of the GUI window because its easier to read while working and you don't get interrupted (I got the "onsave" option enabled so I don't get any errors shown at all (they will only show up if I press CTRL+ALT+J (command: "jshint") which opens the GUI window..)).

Another benefit would be (as it was in an earlier version of this plugin) that, I hope, you could use the F4 and SHIFT+F4 keys to navigate through the errors.

What do you think? I'd really like this feature to be implemented! Keep up the good work 👍

Greetings

Getting error "0:0 Bad option: 'private'."

I'm getting a weird error on all files. Even the most simple.

/* jshint node:true */

module.export = function(grunt) {
    'use strict';

    grunt.initConfig({

    });
};

Also with this

// jshint node:true

module.export = function(grunt) {
    'use strict';

    grunt.initConfig({

    });
};

AttributeError: 'module' object has no attribute 'DRAW_NO_OUTLINE'

Can someone tell me what's wrong with it? Is caused by my python setting?

view.run_command("jshint")
Saving buffer to: D:\Program Files\Sublime3\Data\Packages\Sublime-JSHint/.temp
Plugin folder is: D:\Program Files\Sublime3\Data\Packages\Sublime-JSHint
Traceback (most recent call last):
File "D:\Program Files\Sublime3\sublime_plugin.py", line 382, in run_
return self.run(edit)
File "D:\Program Files\Sublime3\Data\Packages\Sublime-JSHint\JSHint.py", line 110, in run
self.add_regions(regions)
File "D:\Program Files\Sublime3\Data\Packages\Sublime-JSHint\JSHint.py", line 123, in add_regions
sublime.DRAW_SQUIGGLY_UNDERLINE |
AttributeError: 'module' object has no attribute 'DRAW_NO_OUTLINE'

Look for .jshintrc all the way to the root if not found

Currently, Sublime-JSHint is set-up to look for a .jshintrc file only one directory up, if not found in the same directory as the file being linted.

However, the official JSHint looks for a .jshintrc all the way to the root, if none is found in the current working directory.

I think Sublime-JSHint should do something similar to the official JSHint.

selecting line in lint popup takes you to the wrong location

If you perform a lint and have several errors, the popup box shows up with errors as expected. If you scroll through this popup and click or press enter, the plugin should take you to that line. However, it takes you to the line that is above the one you selected.

FYI I'm using this plugin on ST3.

Set Node directory on Windows

To get working on Windows you need to specify the node.exe. The below worked for me.

"node_path": "c:/path/to/node/node.exe",

JSHint Gutter not respecting project .jshintrc

I have the latest build of JSHint Gutter and it doesn't seem to be using the .jshintrc file that's in my project. I placed some trace statements in run.js and it did correctly find my .jshintrc file in the root of my project folder. My js file is showing errors for defined globals that do not occur when running jshint from the terminal or using when using https://github.com/uipoet/sublime-jshint.

This is JSHint Gutter is returning:
image

This is what https://github.com/uipoet/sublime-jshint is returning:

[JSHint: /Volumes/C/dev/project/Scripts/app/main.js]

✓ 0 errors, [esc] to hide.

[Finished in 0.2s]

Here are samples:
https://gist.github.com/psyrendust/5947842

Missing "trailing whitespace" warning for lines with only spaces

Noticed that there's an issue with this plugin not providing a trailing whitespace warning when the line in question is empty. Strictly speaking I suppose this isn't trailing whitespace, but since JSHint command-line seems to pick it up, it's unusual that this doesn't.

Example:

(function($) {

    function one() {
        var a = 0;    <--- will pick up trailing whitespace here
    }

    <--- but won't pick it up when the line has only a few spaces, like here

    function two() {
        var b = 0;
    }

}(jQuery));

indent: false in .jshint not working

If I use /*jslint indent: false */ in the specified file it works and ignores well.

However, If "indent: false" in config file, lint still fires indent warnings. Any thoughts?

Support Package Manager for Sublime Text 3

ST3 build 3047, OS X ML, installed through latest Package Control:

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 549, in run_
    return self.run(edit)
  File "JSHint in /Users/niko/Library/Application Support/Sublime Text 3/Installed Packages/JSHint Gutter.sublime-package", line 24, in run
  File "X/codecs.py", line 884, in open
NotADirectoryError: [Errno 20] Not a directory: '/Users/niko/Library/Application Support/Sublime Text 3/Installed Packages/JSHint Gutter.sublime-package/.__temp__'

Issue on ubuntu when using with nvm

I am using node with nvm on ubuntu.
So I don't have an executable /usr/local/bin/node : L41

My executables will be in /home/revath/.nvm/<node version>/bin/node

Is there any way I can specify the path to executable?

Ability to disable line highlighting

I believe this is a new feature? When selecting a warning from the list, the line is now highlighted in white. I cannot figure out how to clear it easily other than clearing all annotations. I would love the ability to simply disable the line highlighting feature and only have the gutter icons.

Lint inside PHP files

Hi,

can i configure JSHint to check the js code in ctp/php files. Mean js code that is wraped by "<script type="text/javascript">" ?

Thank you very much,
akI

Blank items in Tools menu

There are some blank items in Sublime Text 3's Tools menu, please see the screenshot:

SublimeText-blank-items-in-Tools-menu.png

All my installed packages list below:

- Package Control
- Vintageous
- Emmet/PyV8
- MarkdownEditing
- SmartMarkdown
- ColorPicker
- Dayle Rees Color Schemes
- Sublime-HTMLPrettify
- Sublime-JSHint

Because Sublime-HTMLPrettify and Sublime-JSHint can't install via Package Control, so they were installed at last. When I restart Sublime Text 3 after the two packages installed, the blank items display in Tools menu.

At first, I guess these problems caused by me, so I delete whole Data folder under Sublime Text 3 to revert to a freshly installed state, then I reinstall all packages. After installed one package, I have restarted Sublime Text 3 one time, and went to see the Tools menu. Finally, I have found the two packages are the root cause.

So, could you give me some help to fix this? Thanks.

Below are my computer's environment:

- Windows 7 32-bit Ultimate
- Sublime Text 3 build 3047 portable

I know Sublime-HTMLPrettify and Sublime-JSHint created by one person, but I will put this post to their own issue tracker. Thanks again.

Highlight line on minimap

Is it possible to highlight lines with issues on the minimap? Don't know if this is even doable but it would be a nice feature.

Warning icon does not show up correctly

I'm not sure if this feature is a part of Sublime2/this plugin, but just recently 2 issues appeared with this plugin (that I very much love):

  • This file got "reset" - all my changes to it have been wiped:
    ~/Library/Application Support/Sublime Text 2/Packages/JSHint Gutter/.jshintrc
  • When I run the plugin, instead of seeing alert icon on the left, I see some "error image missing" type of red dashed square:
    image

show a tooltip with error for a particular line...

... when I hover over the error icon for this line or when I press some keyboard combo.

Benefits:

  • with the mouse hover, I don't have to remember the keyboard combo. I imagine not everybody does.
  • in those cases when there's craploads of errors for this file, I don't have to search for this line in the popup.

Ignoring specific JSHint error codes? (i.e. W014)

I can't seem to find the previous thread I made on this.

Essentially, adding this to .jshintrc used to work, but has no effect anymore:

"-W014": true,

How can we ignore specific JSHint errors?

Thanks...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.