Coder Social home page Coder Social logo

rondevera / jslintmate Goto Github PK

View Code? Open in Web Editor NEW
207.0 9.0 23.0 1.71 MB

Quick, simple JSLint (or JSHint) in TextMate. Hurt your feelings in style. (See the `development` branch for the latest.)

Home Page: https://rondevera.github.io/jslintmate/

License: MIT License

Ruby 6.59% JavaScript 86.53% CSS 6.89%

jslintmate's Introduction

JSLintMate

Quick, simple JSLint and JSHint in TextMate. Hurt your feelings in style.

JSLintMate uses Ruby and JSC behind the scenes; both are part of OS X by default. No need to install anything else. Everything works offline.

Download JSLintMate.tmbundle

JSLintMate screenshots

(CSS geeks: Only three images are used throughout the UI. The red, striped error uses only CSS.)

What are these things? JSLint is a powerful JS code quality tool from expert Douglas Crockford. JSHint is a community-driven project based on JSLint, and is more tolerant of common JS patterns. (They're not the same as JavaScript Lint.)

Key features

  • Quick JSLint/JSHint on command-S.
  • Full problem details on control-L (JSLint) or control-shift-L (JSHint)—both customizable. Navigate the list with full mouse/trackpad/keyboard support.
  • Support for options files that help you—and your teammates—use the same coding standards everywhere. Options files can live in your home directory or in project repositories. They use standard JSON/YAML, so they can be read not just by JSLintMate, but also by teammates' lint tools in other editors, automated testing systems, continuous integration systems, and more.
  • Support for using your own custom or edge build of JSLint or JSHint.

Setup

Download JSLintMate.tmbundle and double-click it. TextMate should install it for you automatically—that's all.

Or via Git:

# To install for the first time:
mkdir -p ~/Library/Application\ Support/TextMate/Pristine\ Copy/Bundles
cd ~/Library/Application\ Support/TextMate/Pristine\ Copy/Bundles
git clone git://github.com/rondevera/jslintmate.git "JavaScript JSLintMate.tmbundle"
osascript -e 'tell app "TextMate" to reload bundles'
  # Alternatively, switch to TextMate and select
  # Bundles > Bundle Editor > Reload Bundles.

# To update to the latest version:
cd ~/Library/Application\ Support/TextMate/Pristine\ Copy/Bundles
git pull

TextMate 2

Installation: While TextMate 2 is in development, installation is temporarily a bit more involved:

  1. Download JSLintMate.tmbundle and unzip it.
  2. Create the bundles path: mkdir -p ~/Library/Application\ Support/Avian/Pristine\ Copy/Bundles/.
  3. Open the same path: open ~/Library/Application\ Support/Avian/Pristine\ Copy/Bundles/.
  4. Drop JavaScript JSLintMate.tmbundle into the Bundles directory.

Project setup: It's worth creating a .tm_properties file in your project directory containing this (source):

projectDirectory     = "$CWD"
TM_PROJECT_DIRECTORY = "$projectDirectory"

This lets you use $TM_PROJECT_DIRECTORY in your JSLintMate settings, which is useful for pointing to project-specific JSLint/JSHint options and custom builds.

Display: In TextMate 2, JSLintMate runs in a panel in the main window, rather than in a separate window. To make TextMate 2 open JSLintMate in a separate window, run this in Terminal (source):

defaults write com.macromates.TextMate.preview htmlOutputPlacement window

Usage

JSLintMate has two modes:

  • Quick mode shows a tooltip with a preview of the problems (if any) whenever you hit command-S.

  • Full mode shows a full list of problems whenever you hit control-L (JSLint) or control-shift-L (JSHint).

Quick mode

While you're coding, hit command-S to save changes and automatically run the file through JSLint. If any problems are found, JSLintMate shows a few of them in a tooltip.

If you'd prefer to run JSHint on save:

  1. Select Bundles > Bundle Editor > Show Bundle Editor.
  2. Expand JavaScript JSLintMate and highlight Linters.
  3. Change the value for TM_JSLINTMATE_DEFAULT_LINTER to jshint, then close the window to save changes.

If you don't want JSLintMate to do anything on save, open the Bundle Editor window again, and remove the keyboard shortcut for the Run JSLintMate and Save command.

To skip the tooltip and see the full list of problems, use full mode.

Full mode

To see the full list of problems in a JS file, hit control-L to run it through JSLint, or control-shift-L to use JSHint. Click a problem to jump to that line in the file. Fix and repeat.

You can also navigate the list of problems with your keyboard: up/down/k/j to move up/down, and return to select.

Options

If JSLint or JSHint are too strict or lenient for your taste, you can set options for each. These options serve as a barebones code style guide, and let teammates stick to the same standards. Three ways to do this:

Set options at the top of each JS file

Adding options atop each JS file gives you fine-grained control. For example:

  /*jslint  browser:  true,
            newcap:   true,
            nomen:    false,
            plusplus: false,
            undef:    false,
            vars:     false,
            white:    false */
  /*global  window, jQuery, $, MyApp */

This example is specifically for JSLint. To use it with JSHint, change /*jslint to /*jshint and tweak options as needed.

The exact option names and values change occasionally. For the latest, check the JSLint docs and the JSHint docs.

Keep a personal options file

You can maintain an options file to use your favorite JSLint/JSHint options across projects. These files can be written in JSON or YAML.

JSLintMate comes with some example options files: jslint.json, jslint.yml, jshint.json, and jshint.yml. To use one of these, save a copy as ~/.jslintrc or ~/.jshintrc. JSLintMate reads from these paths by default, and automatically detects whether they contain JSON or YAML.

If you want to rename your options files or store them elsewhere:

  1. Within TextMate, select Bundles > Bundle Editor > Show Bundle Editor.
  2. Expand JavaScript JSLintMate and highlight Options Files.
  3. Change the values for TM_JSLINTMATE_JSLINT_OPTIONS_FILE and TM_JSLINTMATE_JSHINT_OPTIONS_FILE to the file paths you prefer.

Keep an options file in your project

You can also store your options file in your project. This is great for sharing options with collaborators—everyone uses the same options for all JS files, and different projects can have different options.

To set this up:

  1. Within TextMate, select Bundles > Bundle Editor > Show Bundle Editor.
  2. Expand JavaScript JSLintMate and highlight Options Files.
  3. Change the value for TM_JSLINTMATE_JSLINT_OPTIONS_FILE to a path in your project, e.g., $TM_PROJECT_DIRECTORY/config/jslint.yml. Do the same for JSHint if needed, making sure to use a separate options file.

Options files are meant to be understood by a wide variety of tools, not just JSLintMate. This includes lint tools in other editors, continuous integration systems, and other automated testing systems.

Deprecated: Specify global options for use across projects

Here's the old way to maintain personal, cross-project options. This feature will be removed in an upcoming version. Please use a ~/.jslintrc or ~/.jshintrc file via the "Options Files" preferences instead. Bundle commands no longer need to be modified directly.

  1. Within TextMate, select Bundles > Bundle Editor > Edit Commands > JavaScript JSLintMate > Run JSLintMate.

  2. Add your list of options as --linter-options. For example:

      ruby "$TM_BUNDLE_SUPPORT/lib/jslintmate.rb" \
        --linter-options=browser:true,white:false
    

Options file fallbacks

TM_JSLINTMATE_JSLINT_OPTIONS_FILE and TM_JSLINTMATE_JSHINT_OPTIONS_FILE support options file fallbacks. Change each setting to a colon-separated list of file paths, and JSLintMate will use the first readable file in each list.

For example, $TM_PROJECT_DIRECTORY/config/jslint.json:~/.jslintrc tells JSLintMate to first look for a project-specific options file (e.g., for options shared with a team). If this file is not readable, JSLintMate uses your personal options file as a fallback.

Option precedence

If you specify options in your JS files and in options files, they'll be merged at runtime:

  1. Highest precedence: Options in the JS file, e.g., /*jslint browser: true */
  2. First readable options file
  3. JSLintMate's default options

For more info, read about JSLint's options and JSHint's options.

Unused variables

JSLintMate reports warnings from JSLint/JSHint about variables that are declared but not used. It's good to clean up code by removing unused variables, but if you'd rather not see these warnings:

  1. Within TextMate, select Bundles > Bundle Editor > Show Bundle Editor.
  2. Expand JavaScript JSLintMate and highlight Unused Variables.
  3. Change the value of TM_JSLINTMATE_WARN_ABOUT_UNUSED_VARIABLES to false.

To resume seeing warnings about unused variables, set this value back to true.

Custom JSLint/JSHint builds

JSLintMate is packaged with copies of JSLint and JSHint, but you can use your own copies instead. This is useful for testing an edge build or using your own modified version.

If you store a copy of your linter in your project, point your bundle prefs at it:

  1. Within TextMate, select Bundles > Bundle Editor > Show Bundle Editor.
  2. Expand JavaScript JSLintMate and highlight Linters.
  3. Change the value for TM_JSLINTMATE_JSLINT_FILE to point to your linter. This could be a path in your project (e.g., $TM_PROJECT_DIRECTORY/lib/jslint.js), a path in your home directory (e.g., ~/lib/jslint.js), or anything else. If needed, do the same for JSHint, making sure to use a separate linter file.

About

This project is adapted from:

JSLintMate is released under the MIT License. The bundle contains copies of JSLint and JSHint, which use their own license(s). Use JSLintMate for good, not evil.

jslintmate's People

Contributors

rondevera 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

jslintmate's Issues

Unused variables in callbacks

The previous version reported unused variables only when they were declared with var (and not used). The latest version now reports them when they are defined in function (...).

Would it be possible to differentiate between those two? I find it useful to keep this detection on in order to remove some vars I set up (sometimes at a cost) without using them, but when using callbacks I often like to list all the data I'm expecting to get (especially if I have a lot of similar callbacks in a row). Ideally I could get warnings for the former but not for the latter.

Thanks!

JSHint/JSLint on save

There is this sentence in the Readme:

"This bundle doesn't run JSLint/JSHint on save because doing so can incur noticeable overhead."

I do not understand what is meant by "overhead" in this. I've used on-save JSLint with the Javascript Tools bundle here: https://github.com/subtleGradient/javascript-tools.tmbundle

It shows a small tooltip notifications if there's warnings or errors. This has been working great for me in the past and I notice all the errors straight away without having to worry about committing non-linted code by accident.

The only downside of Javascript tools is that it does not work with JSHint. So it'd be great if you had the on-save option or explained what is meant by "overhead" in the Readme.

Thanks! :)

Save & Run JSLintMate error in Mavericks DP3

When saving, before normal output, you get an error:

xcrun: error: unrecognized option: --show-sdk-path

Followed by the normal output.

I'm not sure if this is truly a jslintmate error, or an error in some underlying TM library code that it is using (I think the latter, but I can't find where the error is being generated)

JSHint version is out-of-date

The version included herein does not have support for "expr" the setting to allow lines like

foo && foo.bar && foo.bar('baz');

I replaced the version in ~/Library/Application Support/TextMate/Bundles/JSHintMate.tmbundle/Support with the latest from http://jshint.com/jshint.js and it worked fine.

Don't reference jslint_on_rails as .jslintrc example

I started using the code reference on the jslint_on_rails project for my .jslintrc file, but that file doesn't match the configuration options for jslint and, more importantly, at least one value (nomen) has its definition reversed.

Two issues straight after installation, OSX 10.8.5, TM 1.5.11 (1635)

Immediately after installing, ^L gets me:

/Users/marauder/Library/Application Support/TextMate/Pristine Copy/Bundles/JavaScript JSLintMate.tmbundle/Support/lib/jslintmate/linter/options_files.rb:27:in first_readable_options_file_path': undefined methodfind' for nil:NilClass (NoMethodError) from /Users/marauder/Library/Application Support/TextMate/Pristine Copy/Bundles/JavaScript JSLintMate.tmbundle/Support/lib/jslintmate/linter.rb:196:in get_html_output' from /Users/marauder/Library/Application Support/TextMate/Pristine Copy/Bundles/JavaScript JSLintMate.tmbundle/Support/lib/jslintmate.rb:302:instart!' from /Users/marauder/Library/Application Support/TextMate/Pristine Copy/Bundles/JavaScript JSLintMate.tmbundle/Support/lib/jslintmate.rb:310

and ⌘S gets me

Please set your TM_JSLINTMATE_DEFAULT_LINTER preference
to 'jslint' or 'jshint'.

I don't know ruby so my quick attempts at troubleshooting came to nothing. It's probably trivial... but the documentation did promise one-click install.

Thanks!

run on unsaved code?

I would like to run a syntax check on the source without saving (so if the syntax is broken, it'll keep working in the browser, where I might be testing other things at the same time).
Is this possible?

Reporting of globals defined

Other plugins I've used with other text editors will list out all of the things defined at global, whether by accident or not. This plugin doesn't seem to warn or list about accidentally defined globals. Otherwise its an amazing project!

Unable to install on sublimeText

Hi,

I'm using sublime text 2 and i want to make this repo works with.

But when i clone this repo in my package folder, nothing is install..
Tmbundle are compatible with ST2, JSlintMate is it?

Thank's!

Dosn't work

^L or shift^L gives:
/Users/ashipunova/Library/Application Support/TextMate/Pristine Copy/Bundles/JavaScript JSLintMate.tmbundle/Support/lib/jslintmate/linter/options_files.rb:27:in first_readable_options_file_path': undefined methodfind' for nil:NilClass (NoMethodError) from /Users/ashipunova/Library/Application Support/TextMate/Pristine Copy/Bundles/JavaScript JSLintMate.tmbundle/Support/lib/jslintmate/linter.rb:196:in get_html_output' from /Users/ashipunova/Library/Application Support/TextMate/Pristine Copy/Bundles/JavaScript JSLintMate.tmbundle/Support/lib/jslintmate.rb:302:instart!' from /Users/ashipunova/Library/Application Support/TextMate/Pristine Copy/Bundles/JavaScript JSLintMate.tmbundle/Support/lib/jslintmate.rb:310:in `
'

TM2 output not in separate window and can't be closed

I installed the development branch in TM2 and after executing ctrl-L the output is displayed in a pane at the bottom of the TM2 window instead of in a separate window when using in TM1. This makes the results harder to review and it's not obvious how to close the results pane.

TextMate Version 2.0 (9064)

jslintmate version:

$ git log -1
commit 5a26f33c89022df2472c642809b61ee926d60c78
Author: Ron DeVera <[email protected]>
Date:   Sat Feb 18 00:27:54 2012 -0800

    Mirror readme screenshot dimensions w/GitHub page

Screenshot:

predef in yaml file not observed

I've tried a few different options with defining predef, all valid YAML statements.

predef:

  • AGlobal
  • AnotherGlobal

and

predef: [AGlobal, AnotherGlobal]

debugging shows that they are set on the command line when calling jsc, but jslint doesn't recognize them.

Has anyone had any luck with this?

jslint options seem to have boolean logic errors

I wrote this code to test it out:

var j = 0;
var i = 1;
var _foo = 'Scott';

document.createElement("div");

for (i = 1; i < 100; i++) {
    j += i;
}

I was expecting complaints about the _ and ++ but that is fine. So I added this to the top of the file:

/*jslint nomen: false, maxerr: 50, indent: 4 */

And still did not get the error about dangling _. I update it to true and it did correct itself. If you paste that code into jslint.com it works as expect... is this a bug in your implementation?

Error in Installing JSLintMate for TextMate in Mavericks

I am trying to install JSLintMate http://rondevera.github.io/jslintmate/ for my text mate. Downloaded the bundle from their website and it suggested that it will get install automatically.

On unzipping it is asking for file encoding format and i am selecting default UTF-8
screen shot 2014-03-30 at 12 54 29 am

But after running the installation bundle I am getting an error

The bundle “JavaScript JSLintMate 1.4.tmbundle” does not contain the required “info.plist” file (or that file is corrupt) and can therefore not be installed.
screen shot 2014-03-30 at 12 45 05 am

i am trying to install JSLintMate http://rondevera.github.io/jslintmate/ for my text mate. Downloaded the bundle from their website and it suggested that it will get install automatically.

On unzipping it is asking for file encoding format and i am selecting default UTF-8

enter image description here

But after running the installation bundle I am getting an error

The bundle “JavaScript JSLintMate 1.4.tmbundle” does not contain the required “info.plist” file (or that file is corrupt) and can therefore not be installed.

enter image description here

I searched on the web regarding this but not able to find the solution.

Text-Mate Version: 1.5.11
OSX: Maverics 10.9
JSLintMate: 1.4

Is there anything wrong from my side or some additional step is required to make it work.

Add Node support

Add Node support as a fallback if jsc is unavailable, or for later versions of JSHint that require Node.

UTF-8 support

Thee is an issue with UTF-8 support.

I don't know if it's from the bundle or JSLint (and JSHint).

Here is a screenshot

JSHint doesn't seem to recognize the smarttabs flag

In my JS files that are under heavy development, I get a lot of alerts for "Mixed Spaces and Tabs" because I have a lot of code commented out but because JSHint sees so many of those, I lose the benefit of it flagging other actual syntax errors. I tried adding /*jshint smarttabs:true/false */ (I've tried both settings) to the top of the file, but the errors still show up. Either I'm using the wrong flag or it's being ignored.

Config option todo does not work together with browser option

I just installed jslintmate. Before I had JSLinted some files using http://www.jslint.com.

I used the options :

/*jslint todo: true, browser: true */

This passes in the online form but throws me an error in Textmate (1 and 2) 'Unexpected todo'

To have it pass I need to separate the statements :

/jslint browser: true */
/
todo: true */

I also tried (both using spaces and tabs) :
/*jslint browser: true,
todo: true */

Broken on OSX 10.8

While it is nice to have everything pass through lint free... it is not very helpful. Every js file is passing through "lint free" on osx 10.8

predef ignored when has $ prefix

predefs such as $h, $v seem to be ignored.
$ by itself is working fine. any ideas?

using latest textmate 2 and jslintmate

thanks

Allow for use of .hintrc files

Many users have a global l/hinter config file in their home dir, that is in the same format as the README suggests in the commented portion at the top of the file.

ruby path/to/jslintmate.rb --linter-options-file="~/.hintrc" would be rad.

Setting options per project

The JSLintMate options (e.g. TM_JSLINTMATE_DEFAULT_LINTER) are set globally, and trying to override these in .tm_properties does not seem to have any effect. This would be very useful for setting linters and options on a per-project basis. Is this possible to fix?

undefined method `find' error

All run method are giving me this (added ~):

~/Library/Application Support/TextMate/Pristine Copy/Bundles/JavaScript JSLintMate.tmbundle/Support/lib/jslintmate/linter/options_files.rb:27:in `first_readable_options_file_path': undefined method `find' for nil:NilClass (NoMethodError) from ~/Library/Application Support/TextMate/Pristine Copy/Bundles/JavaScript JSLintMate.tmbundle/Support/lib/jslintmate/linter.rb:196:in `get_html_output' from ~/Library/Application Support/TextMate/Pristine Copy/Bundles/JavaScript JSLintMate.tmbundle/Support/lib/jslintmate.rb:302:in `start!' from ~/Library/Application Support/TextMate/Pristine Copy/Bundles/JavaScript JSLintMate.tmbundle/Support/lib/jslintmate.rb:310

$TM_BUNDLE_SUPPORT and "Pristine Copy"

I've just installed the bundle, following the instructions, but I get this error when I run the lint

Could not open file: /Users/jlecour/Library/Application Support/TextMate/Pristine Copy/Bundles/JSLintMate.tmbundle/Support/lib/jslint.js /Users/jlecour/Library/Application Support/TextMate/Bundles/JSLintMate.tmbundle/Support/lib/jslintmate.rb:27:in `read': No such file or directory - /Users/jlecour/Library/Application Support/TextMate/Pristine Copy/Bundles/JSLintMate.tmbundle/VERSION (Errno::ENOENT) from /Users/jlecour/Library/Application Support/TextMate/Bundles/JSLintMate.tmbundle/Support/lib/jslintmate.rb:27:in `version' from /Users/jlecour/Library/Application Support/TextMate/Bundles/JSLintMate.tmbundle/Support/lib/jslintmate.rb:64:in `link_to_jslintmate' from /Users/jlecour/Library/Application Support/TextMate/Bundles/JSLintMate.tmbundle/Support/lib/jslintmate.rb:172

I've found that it's an issue with the $TM_BUNDLE_SUPPORT environment variable.
In a shell, echo $TM_BUNDLE_SUPPORT returns "~/Library/Application Support/TextMate/Bundles" but inside TextMate it doesn't seem to work the same way.

I don't know if it's a bug, or a misconfiguration on my part, so if somebody has an idea, i'll take it.

Thanks

Embedded javascript

Would it be possible to add support for validating javascript in <script>-tags embedded in HTML?

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.