Giter Site home page Giter Site logo

nodelint's Introduction

nodelint

  • Node.js is a V8 based framework for writing Javascript applications outside the browser.

  • JSLint is a code quality tool that checks for problems in Javascript programs.

  • nodelint lets you run JSLint from the command line.

  • nodelint currently supports node version 0.4.x and tested with 0.5.9 so should run on 0.6.x

installation

npm:

$ npm install nodelint

If you clone nodelint from Github, you should init JSLint submodule:

$ git submodule update --init

usage

You can use nodelint directly if you have node in your $PATH, or if you installed it using npm -g:

$ nodelint path/to/your/file.js

Otherwise, you need to run it with node:

$ node path/to/nodelint path/to/your/file.js

You can also specify a directory param and nodelint will find all .js files under that directory and its subdirectories:

$ node path/to/nodelint dir1/ dir2/

Enjoy!

configuration

You can override default JSLint options by passing config file with the optional --config parameter:

$ nodelint file1 file2 dir1 dir2 --config path/to/your/config/file.js

For example, if the default config.js has:

var options = {
    adsafe       : false,
    bitwise      : true,
    ...
    "predef"     : []
};

And your own path/to/your/config/file.js looks like:

var options = {
    bitwise      : false,
    browser      : false
};

Then the final options used will be:

var options = {
    adsafe       : false,
    bitwise      : false,
    browser      : false,
    ...
    "predef"     : []
};

Take a look at JSLint's options to see what to put in the options variable.

You can also add your configuration inside the JS files itself: JSLint will use this one instead of the global one.

Simply add some comments at the beginning of the file. Note that there is no space between /* and global and between /* and jslint:

// define your global objects:
/*global YUI, JQuery */

// define your jslint-options:
/*jslint white: true, onevar: true, undef: true, nomen: true */

reporters

By default nodelint uses an internal reporter to output it's results to the console. There may be times when a more customizable reporting system might be needed (i.e. IDE/Text Editor integrations or customized console outputs).

nodelint allows you to designate a custom reporter for outputting the results from JSLint's run. This reporter will override the default one built into nodelint. To utilize a custom reporter first create a js file that exports reporter function:

example-reporter.js:

var util = require('util');

function report(results) {
    var len = results.length;
    util.puts(len + ' error' + ((len === 1) ? '' : 's'));
}

exports.report = report;

Then when you run nodelint from the command line, pass in the customized reporter:

$ ./nodelint path/to/file.js --reporter path/to/file/example-reporter.js

For brevity sake, this is a fairly simple reporter.

nodelint includes some build-in reportes for VIM, Textmate and JetBrains IDEA integration.

Also it include XML reporter, that produces reports which can also be integrated with a Continuous Integration server like Hudson using the Violations Plugin.

Please see the [wiki][wiki] for integration with various editors.

contribute

To contribute any patches, simply fork this repository using GitHub and send a pull request to me <http://github.com/tav>. Thanks!

credits

  • tav, wrote nodelint

  • Felix Geisendörfer, clarified Node.js specific details

  • Douglas Crockford, wrote the original JSLint and rhino.js runner

  • Nathan Landis, updated nodelint to Node's new API.

  • Oleg Efimov, added support for overridable configurations, running nodelint from a symlink and updates to reflect Node.js API changes.

  • Matthew Kitt, added support for configurable reporters, various code cleanups and improvements including updates to reflect Node.js API changes.

  • Corey Hart, updated nodelint with multiple files and config support.

  • Mamading Ceesay, added support for using nodelint within Emacs.

  • Matt Ranney, updated nodelint to use sys.error.

  • Cliffano Subagio, added npm installation support, XML reporter, and directory param support.

  • Clemens Akens, updated to latest JSLint from Crockford repo

  • Paul Armstrong, updates to reflect Node.js and npm API changes

nodelint's People

Contributors

azatoth avatar clebert avatar cliffano avatar codenothing avatar mranney avatar paularmstrong avatar phanatic avatar sannis avatar tav 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

Watchers

 avatar  avatar  avatar  avatar  avatar

nodelint's Issues

Makefile don't work

Hi,

the Makefile has a problem. The target stamp-build depends on the file dependencies. The target
tries to copy all its dependencies via $^ to dist. But the file dependencies don't exit. The target for
dependencies is empty. I have a solution, but I'm not sure it's what has been intended. Have a look at goldenHairDafo/nodelint commit a26d7c

Regards,
Dafo

Deal with new JSLint options

There is some changes in JSLint defaults. I updated some of them as in @clebert fork (Sannis@7b033c5).

But there is some options, that I've revert and what to discuss:

  • regexp: false, that disallow . in regexps
  • sloppy: true, that need 'use strict' for all files
  • stupid: true, that disallow ...Sync Node.js methods

There is no problem to fix this in nodelint sources, but what about users that will be affected by such update? I need some help to decide.

// cc: @tav, @mkitt, @cliffano, @paularmstrong, @codenothing, @mranney, @azatoth

License?

Hi!

I found a mention of Public Domain in the package.json but this is not binding legally.
Could a license file be added?

Thank you!

Suppress ANSI colors

Out of the box, and using the default formatter, nodelint uses ANSI colors to mark error messages red in the console. It would be great if there was a way to suppress these. Two ideas spring to mind:

  • provide a --nocolor flag
  • and/or respect the NODE_DISABLE_COLORS environment variable

I'm not sure which is the best approach, but I've found similar issues filed for coffeescript and cli.

large output gets truncated on xml reporter

I've a very large project and when i run the xml reporter i get truncated output, i hacked it by modifying the xml reporter to write to a file and that solves it for me, but i think it should be fixed, here is my modified xml.js:

// example usage:
//
//     $ nodelint path/to/file.js --reporter examples/reporters/xml.js
//
// this reporter produces jslint xml that can be automatically recognised by
// Hudson Violations Plugin http://wiki.hudson-ci.org/display/HUDSON/Violations+Plugin

var path = require('path'),
    fs = require('fs');

function reporter(results) {

  function escape(str) {
    return (str) ? str.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;') : '';
  }

  var i, error, len, file,
      dir = process.cwd(),
      xml = '<?xml version="1.0" encoding="UTF-8" ?>\n<jslint>\n';

  for (i = 0, len = results.length; i < len; i += 1) {
    file = path.join(dir, results[i].file);
    error = results[i].error;
    xml += '\t<file name="' + file + '">\n' +
           '\t\t<issue char="' + error.character + '" evidence="' + escape(error.evidence || '') +
           '" line="' + error.line + '" reason="' + escape(error.reason) + '"/>\n' +
           '\t</file>\n';
  }

  xml += '</jslint>';
  var outputFile = process.env.NODELINT_OUT;
  if(outputFile) {
    fs.writeFileSync(outputFile, xml + '\n');
  } else {
    console.log(xml);
  }
}

ARGV error on node 0.5.10

I had to modify line 171 of nodelint as the following to make it run under node 0.5.10.
params = (process.ARGV || process.argv).splice(2);

nodelint directory/ or nodelint directory/*

I can't use
nodelint lib/ tests/
as suggested by the documentation in README.md.
Yet I can use
nodelint lib/* tests/*

This is the output:

Error: Opening file <lib/>
Error: EISDIR, Is a directory

Error: Opening file <tests/>
Error: EISDIR, Is a directory

0 errors

Am I doing something wrong?

crash when trying to run - Cannot create property 'string' on string '(begin)'

package version 0.6.2
node version 6.9.1
macOS 10.12

i installed from npm -

npm install -g nodelint

then when i try to run it

increpare:tools stephenlavelle$ nodelint
undefined:2557
s.string = s;
^

TypeError: Cannot create property 'string' on string '(begin)'
at ultimate (eval at (/usr/local/Cellar/node/6.9.1/lib/node_modules/nodelint/nodelint:46:11), :2557:18)
at eval (eval at (/usr/local/Cellar/node/6.9.1/lib/node_modules/nodelint/nodelint:46:11), :3167:5)
at eval (eval at (/usr/local/Cellar/node/6.9.1/lib/node_modules/nodelint/nodelint:46:11), :6399:2)
at /usr/local/Cellar/node/6.9.1/lib/node_modules/nodelint/nodelint:46:3
at Object. (/usr/local/Cellar/node/6.9.1/lib/node_modules/nodelint/nodelint:194:2)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)

Wrong 'undef' option description and default value

Since version 0.5 nodelint doesn't show missing var in declarations and use of undeclared variables as errors by default. This is due to the true default value of undef configuration option.

JSLint.com instructions say that undef should be "true if variables and functions need not be declared before used", but config.js gives the opposite definition:

"undef"      : true,  // if variables should be declared before used

Update the version on npmjs.org

The version of nodelint published on npmjs.org is outdated, can someone with access please publish the latest version?

Thanks.

"sys" module is now called "util"

References to the module sys should be replaced with util, as sys has been renamed. Any time you reference it, node.js will return the following warning:

The "sys" module is now called "util". It should have a similar interface.

Edit: this log is thrown in node v0.5.9 and will likely also be present in v0.6.0, as they're in final testing now

Nodelint reporters make no difference to output

Nodelint could be the commandline interface to JSLint that I've been looking for. The reporters feature sets it apart from the other tools I've looked at (e.g. https://github.com/reid/node-jslint), but so far I been unable to make them work. I wonder if you can help?

I'm using this snippet of JS as a test:

var i;
for (i=1; i <= 100; i++) {
    if(i % 15 == 0) {
        console.log('Fizzbuzz');
    } else if(i % 5 == 0) {
        console.log('Buzz');
    } else if(i % 3 == 0) {
        console.log('Fizz');
    } else {
        console.log(i);
    }
};

If I run nodelint without specifying a reporter, I get the following output:

nodelint fizzbuzz.js
The "sys" module is now called "util". It should have a similar interface.
/Users/drew/code/nodelint/fizzbuzz.js, line 2, character 22: Unexpected '++'.
for (i=1; i <= 100; i++) {
/Users/drew/code/nodelint/fizzbuzz.js, line 3, character 15: Expected '===' and instead saw '=='.
if(i % 15 == 0) {
/Users/drew/code/nodelint/fizzbuzz.js, line 5, character 21: Expected '===' and instead saw '=='.
} else if(i % 5 == 0) {
/Users/drew/code/nodelint/fizzbuzz.js, line 7, character 21: Expected '===' and instead saw '=='.
} else if(i % 3 == 0) {
/Users/drew/code/nodelint/fizzbuzz.js, line 12, character 2: Unexpected ';'.
};
5 errors

I get exactly the same output if I include --reporter lib/reporters/vim.js, and the same goes for all of the reporters that are bundled in the nodelint/lib/reporters directory. Here's an example of the output. I've included the command line that I entered, so you can see if I'm doing anything wrong:

nodelint fizzbuzz.js --reporter lib/reporters/vim.js 
The "sys" module is now called "util". It should have a similar interface.
/Users/drew/code/nodelint/fizzbuzz.js, line 2, character 22: Unexpected '++'.
for (i=1; i <= 100; i++) {
/Users/drew/code/nodelint/fizzbuzz.js, line 3, character 15: Expected '===' and instead saw '=='.
if(i % 15 == 0) {
/Users/drew/code/nodelint/fizzbuzz.js, line 5, character 21: Expected '===' and instead saw '=='.
} else if(i % 5 == 0) {
/Users/drew/code/nodelint/fizzbuzz.js, line 7, character 21: Expected '===' and instead saw '=='.
} else if(i % 3 == 0) {
/Users/drew/code/nodelint/fizzbuzz.js, line 12, character 2: Unexpected ';'.
};
5 errors

I have the latest versions of node and nodelint installed, as follows:

node:     0.6.7
nodelint: 0.5.2

Do you have any idea what might be causing this?

Thanks,
Drew

Node standards?

I just downloaded the jslint package. Although I found it very useful, I think the executable should be named "node-lint" instead of "nodelint".
It is just a standard improvement but it is still important as jslint itself is created to define some standards for javascript (node based executable are named node-waf, node-repl, etc).

TypeError: Cannot assign to read only property 'string' of (begin)

19:09 $ nodelint apps/_global/data
undefined:2557
        s.string = s;
                 ^

TypeError: Cannot assign to read only property 'string' of (begin)
    at ultimate (eval at <anonymous> (/Users/kristianmandrup/npm/lib/node_modules/nodelint/nodelint:46:11), <anonymous>:2557:18)
    at eval (eval at <anonymous> (/Users/kristianmandrup/npm/lib/node_modules/nodelint/nodelint:46:11), <anonymous>:3167:5)
    at eval (eval at <anonymous> (/Users/kristianmandrup/npm/lib/node_modules/nodelint/nodelint:46:11), <anonymous>:6399:2)
    at /Users/kristianmandrup/npm/lib/node_modules/nodelint/nodelint:46:3
    at Object.<anonymous> (/Users/kristianmandrup/npm/lib/node_modules/nodelint/nodelint:194:2)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
✘-1 ~/repos/test123/repo-manager-v3 [master|✚ 3…14] 
19:09 $ ls apps/_global/data
available feeds     forms     index.js  lists     menus

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.