Coder Social home page Coder Social logo

grunt-jslint's Introduction

grunt-jslint

Build Status Dependency Status

Validates JavaScript files with JSLint as a grunt task.

Installation

Install this grunt plugin next to your project's Gruntfile with: npm install grunt-jslint

Then add this line to your project's gruntfile:

grunt.loadNpmTasks('grunt-jslint');

Documentation

A multi-task to validate your JavaScript files with JSLint.

Supports the following options:

  • files An array of files or wildcards which you want to be validated by JSLint
  • exclude An array of files or wildcards which you do not want to be validated by JSLint
  • directives Configuration options/settings to pre-define in JSLint. Pre-defined globals are included within this object as predef: ['myglobal']
  • options
    • errorsOnly A Boolean option which tells the plugin to only display errors when set to true
    • log A String/filepath option which, when provided, tells the plugin where to write a verbose log to
    • junit A String/filepath option which, when provided, tells the plugin where to write a JUnit-style XML file to
    • failOnError A Boolean option - defaults to true; when set to false, grunt will not fail if JSLint detects an error
    • checkstyle A String/filepath option which, when provided, tells the plugin where to write a CheckStyle-XML file to
    • shebang Ignore shebang lines (#!/usr/bin/whatever) from files
    • edition Specify edition of jslint to use. Either a date which is a JSLint edition (see node_modules/jslint/lib for valid choices), or 'latest' for the latest version, or a path (absolute or relative to process current directory) to the JSLint

Example Usage

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

  grunt.loadNpmTasks('grunt-jslint'); // load the task

  grunt.initConfig({
    jslint: { // configure the task
      // lint your project's server code
      server: {
        src: [ // some example files
          'server/lib/*.js',
          'server/routes/*.js',
          'server/*.js',
          'server/test/*.js'
        ],
        exclude: [
          'server/config.js'
        ],
        directives: { // example directives
          node: true,
          todo: true
        },
        options: {
          edition: 'latest', // specify an edition of jslint or use 'dir/mycustom-jslint.js' for own path
          junit: 'out/server-junit.xml', // write the output to a JUnit XML
          log: 'out/server-lint.log',
          jslintXml: 'out/server-jslint.xml',
          errorsOnly: true, // only display errors
          failOnError: false, // defaults to true
          checkstyle: 'out/server-checkstyle.xml' // write a checkstyle-XML
        }
      },
      // lint your project's client code
      client: {
        src: [
          'client/**/*.js'
        ],
        directives: {
          browser: true,
          predef: [
            'jQuery'
          ]
        },
        options: {
          junit: 'out/client-junit.xml'
        }
      }
    }
  });

  grunt.registerTask('default', 'jslint');
};

Contributing

All files should be validated with JSLint. Bug fixes and/or new features must be accompanied by a passing test. Tests are written with vows.

Validating coding style

Run grunt jslint in the root of your repository.

Running the tests

Run make test in the root of your repository.

License

Copyright (c) 2013 Stephen Mathieson Licensed under the WTFPL license.

grunt-jslint's People

Contributors

dsturley avatar erisds avatar glan avatar joeheyming avatar sbrandwoo avatar skateside avatar smikes avatar stephenmathieson avatar sterpe avatar zaggino 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

Watchers

 avatar  avatar  avatar  avatar  avatar

grunt-jslint's Issues

Ran npm install but the jslint directory is missing

I ran npm install grunt-jslint and got an error like this:
ENOENT, no such file or directory. Turns out the grunt-jslint\jslint directory is missing.I can copy the folder from elsewhere, but the package seems to be wrong.

Two or more setups

Hello guys

I try to use...

jslint: {
    dev: {
        files: ['source/**/*.js'],
        directives: {
            browser: true,
            indent: 4,
            predef: [
                'jQuery'
            ]
        }
    },
    grunt: {
        files: ['Gruntfile.js'],
        directives: {
            node: true,
            indent: 4
        }
    }
},

Running grunt jslint:grunt the output is >> NO FILES?!?

The module is looking the files in the root of the object, like:

jslint: {
    files: ['source/**/*.js'],
    directives: {
        browser: true,
        indent: 4,
        predef: [
            'jQuery'
        ]
    }
},

But, I want to make two or more setups. How can I do this?

Passing es5 -- Not Catching Trailing Commas

Hey all,

Having the same issue described here reid/node-jslint#36 -- seems that you need to pass this:

--es5=false

to node-jslint to get it to pick up trailing commas. However, passing the option in through directives doesn't work in the Grunt task. Is there a fix for this (and/or has anyone else ran into this)?

Options.edition with the aboslute path didn't work

Much appreciate this great application. I want to use a specific version: JSLint 2012-02-03. I cannot find it in node_modules/grunt-jslint/node_modules/jslint/lib/, so I specified a absolute path to 'edition', then the following error occurred:

$ grunt
Running "jslint:server" (jslint) task
Warning: Object /tmp/jslint.js has no method 'resolve' Use --force to continue.

Aborted due to warnings.

I run the make test on local for grunt-jslint, no error was found.

But I noticed that there was a variable named path in the function loadJSLintFromPath and the object path created from requrie('path') had the same name. I changed the name of one of them as following, it seems work.

var path = require('path');
...
function loadJSLintFromPath(jslintpath, cb) {
var ctx = vm.createContext();
var f = fs.readFileSync(path.resolve(process.cwd(), jslintpath));
...

Could you please take a look on this issue? Thanks!

Add support for grunt 0.4.0rc7

Running a build with the version of grunt throws the following error:

Warning: Object # has no method 'expandFiles' Use --force to continue.

will it be updated?

I used to write get, set function which is in es5 feature.
I found some articles that it covers over 1.1.0 version.
Sadly, the jslint that is in grunt-jslint is 0.8.1 version.
That's why everytime I check grunt-jslint, it faild because of these reasons.

I gotta question that is this package has possibility to update for new version?
Hope your positive feedback.

Warning: grunt-jslint's interface has changed

Hi, first I wanna thank you for developing grunt-jslint!

I'm using grunt-jslint 1.1.12 with

  • npm 1.4.14
  • nodejs 0.10.29
  • grunt-cli 0.1.13
  • grunt 0.4.5

and get the following warning when i want to use jslint in my build process:

Warning: grunt-jslint's interface has changed since 0.2.x; see https://github.com/stephenmathieson/grunt-jslint for update instructions. Use --force to continue.

here is my Grunt configuration:

jslint: {
    options: {
        edition: 'latest',
        errorsOnly: false,
        failOnError: true,
        checkstyle: 'build/checkstyle.xml'
    },
    all: {
        src: [
            'Gruntfile.js',
            'src/main/js/**/*.js',
            'src/test/js/**/*.js'
        ]
    }
},

Does anybody know the reason for that message? Am I using it wrong? and noo! I don't always want to use "--force"

Does not fail the build upon linting failure (v0.2.5a)

Failing JSLint tests does not fail the build as the JSHint plugin does.
This needs to work the same way as JSHint does in that regard, does it not?

Running "jslint" task
FAIL    src/public/media/js/tests/logger/logger.test.js (1)
src/public/media/js/tests/logger/logger.test.js:2:1   Use the function form of 'use strict'.

# JSLint failed, 1 violations in 1 files.  1 files scanned.
Running "qunit:all" (qunit) task
Testing src/public/media/js/tests/logger/logger.test.html test
..OK
>> 2 assertions passed (52ms)

Done, without errors.

grunt dependencies

Hi,

Could the grunt dependency could be moved to a devDependencies to reduce npm install time?

Thanks for your work!

Error: EISDIR

When configured like following:

jslint: {
            client: {
                src: ['*.js', 'src/**/*.js'],
                exclude: ['src/thirdparty/*', 'src/widgets/*'],
                directives: {
                    "vars":     true,
                    "plusplus": true,
                    "devel":    true,
                    "nomen":    true,
                    "maxerr":   50
                },
                options: {
                    errorsOnly: false, // only display errors
                    failOnError: false, // defaults to true
                }
            }
        },

I get this error in my project

$ grunt jslint
Running "jslint:client" (jslint) task
>> Error: EISDIR, read
Warning: Task "jslint:client" failed. Use --force to continue.

Aborted due to warnings.

Exclude is not working ...

This is my code structure:

       jslint: {
            client: {
                src: [
                    'js/**/*.js'
                ],
                exclude: [
                    'js/jsDocs/**/*.js',
                    'js/lib/**/*.js',
                    'js/scripts.min.js'
                ],
                directives: {
                    browser: true,
                    predef: [
                        'jQuery',
                        'window',
                        'document',
                        'alert'
                    ]
                }
            }
        },

It still brings in the jsDocs and lib js files. How come?

Thanks

Changes to node-jslint

Currently grunt-jslint does not require anything in particular as an engine. Node-jslint will be using streams soon (from v 0.4.0, out next week), which means node-jslint will require version >= 0.10.0.

I see two options for grunt-jslint -

  1. require version >= 0.10.0
  2. lock into the 0.3.x versions of node-jslint for now

Do you have a preference? I'd choose 1., because nobody should be running node 0.8 or older in production anymore...

@stephenmathieson

Non-trivial exclude rules take forever to filter.

//in tasks/jslint.js
excludedFiles = grunt.file.expand(excludedFiles);

  files = grunt.file
    .expand(files)
    .filter(function (file) {
      return excludedFiles.indexOf(file) === -1;
    });

This is a big-O of (n^2) algorithm for file exclusion and is taking 10 seconds on my relatively small project which excludes '/node_modules/'. By contrast, grunt-contrib-jshint takes a handful of milliseconds to do the same thing.

Please accept my related pull request.

Request - option to run custom function if JSLint fails

Wanted to start a discussion here first before doing a pull-request or fork. I'd like to have the ability to define a custom function to run if JSLint fails. I'm working on moving my team's build processes into Grunt; having some flexibility on extending this plugin will be necessary to get buy-in.

For my particular use case, I'm simply trying to invoke a say command so I receive an audible notification when linting fails. Our team uses JSLint + a file watcher for continual linting during development, so we don't always have the console in the foreground.

Reading and removing BOM from UTF8 file

It would be great if their was a way that the plugin could read and process UTF8 files with a Byte Order Mark (BOM) such is the default saved by Visual Studio and many other Windows applications by default.

Grunt 0.4 Release

I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.

If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.

If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8" as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0" to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.

Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.

Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!

If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.

Thanks, we really appreciate your work!

jslint submodule is not included in npm package.

For example:

npm install grunt-jslint

grunt jslint

Error: ENOENT, no such file or directory 'xxx/node_modules/grunt-jslint/jslint/jslint.js'
Warning: Task "jslint" not found. Use --force to continue.

Ignore specific warnings

Is there a way to ignore specific warnings?

For example, I am trying to use Bluebird in my latest project and it's causing "Read only" errors everywhere it's included. I would like to set a global option in my Gruntfile to ignore the warning but the following does not work.

jslint: {backend: {directives: { W020: true // or false }}}

The other solution, suggested by the JSLint/Hint documentation does not work either. It actually causes more errors.

/*jslint -W020 */

Results in:

file.js:3:10 Expected '*/' and instead saw '-'. file.js:3:11 Expected 'W020' at column 1, not column 11. file.js:3:15 Expected ';' and instead saw '*/'. file.js:3:16 Expected '*/' at column 1, not column 16. file.js:3:16 Unexpected '*/'.

excludes doesn't seem to work

I'm using the following code:

module.exports = function( grunt ) {

  "use strict";

  grunt.initConfig({
    pkg: grunt.file.readJSON( "package.json" ),
    jshint: {
      files: [
        "Gruntfile.js",
        "compile.js",
        "scripts/MathFunction/*.js"
      ],
      excludes: [
        "scripts/MathFunction/*_*.js"
      ]
    }
  });
  grunt.loadNpmTasks( "grunt-contrib-jshint" );
  grunt.registerTask( "default", [ "jshint" ]);
};

However, running this with grunt yields:

Running "jshint:files" (jshint) task
Linting scripts/MathFunction/MathFunction_footer.js...ERROR
[L2:C1] W116: Expected '(end)' and instead saw '}'.
}(window, document, window.console, MathJax, isNaN, Math.pow));

Linting scripts/MathFunction/MathFunction_header.js...ERROR
[L4:C74] E019: Unmatched '{'.
(function loadMathParser(window, document, console, MathJax, isNaN, pow) {
[L4:C1] E019: Unmatched '('.
(function loadMathParser(window, document, console, MathJax, isNaN, pow) {
>> Expected an assignment or function call and instead saw an expression.
>> Missing semicolon.

Warning: Task "jshint:files" failed. Used --force, continuing.

Despite being told to exclude these two files, it still jslints them. Even turning the excludes array into those two specific files still gets them linted.

New templating doesn't work

As of the very recent update to 0.2.3, many of the templating calls in jslint.js do not work, with the error

Warning: An error occurred while processing a template (report is not defined). Use --force to continue.

I believe the calls to grunt.template.process should in fact be calls to underscore.template, or it is possible that some dependency is missing from the package configuration.

node-jslint will require node 0.8

It happened again: to deal with a node/windows/stdout bug that's present in 0.10 and (maybe?) fixed in 0.12, I need node-jslint to require a package that depends on node >= 0.10.

I'm going to split node-jslint into two parts: node-jslint will remain the frontend, and there will be a new package, the backend, that just provides the different jslint editions and the loading logic.

So node-jslint will require node >= 0.10, but this new package will not have an engine dependency. I'll switch grunt-jslint to depend on the new package; grunt-jslint's engine requirement won't change.

This will go out as node-jslint 0.6, probably tomorrow.

Running grunt from MSBuild with --no-color set, jslint plugin sends color codes to external file

I'm executing grunt from MSBuild in Visual Studio with an Exec command like this:

<Exec ContinueOnError="true" 
   WorkingDirectory="%(GruntDir.Fullpath)" 
   Command="grunt.cmd --no-color > logs\grunt-output.log">

Grunt output is not displayed properly in the Visual Studio output window, so the only way to see errors from jslint is to send them to an external file. With the --no-color option set, grunt errors are sent without colour codes. However, the grunt-jslint errors are still sent with colour codes. e.g:
[31m../debug/js/src/jquery.ui.menubar.js:16�[39m�[31m:10�[39m Expected exactly one space between 'function' and '('.
�See grunt issue 510 for a relevant discussion. How can I switch off these colour codes when running grunt-jslint from tool other than the command line?

Directive "unparam" ignored.

While debugging an issue where JSLint would not honor the directive "unparam" I came across some code I believe to be dead.

In lib/jslint.js:111

if (!directives.unused) {
  violations.concat(data.unused);
}

There is no property unused in the data structure returned by JSLINT.data(). Was there such in previous versions of JSLINT? Also there is no directive named unused in JSLINT. How was this construct suppose to work and what was its purpose?

exclude array is ignored

This is what I use for the jslint grunt task.

jslint: {
  all: {
    src: [
      './js/**/*.js'
    ],
    exclude: [
      './js/bundle*.js'
    ]
  }
}

[email protected] excludes bundle.min.js and bundle.js from JSLinting. However in 1.1.6, it does not exclude those files. I have also tried explicitly listing both ./js/bundle.min.js and ./js/bundle.js in the array, but they are not excluded.

How to set jslint options...

Trying to remove some formatting errors from the linting for all files...

e.g.
options: {
jslint white: false,
}

this gives an error

Using 0.2.3-1

I'm updating a project to grunt 0.4 and so I need to use release 0.2.3-1 of grunt-jslint. Unfortunately this version isn't available via npm install yet.

I tried adding the git URL as a dependency in my package.json:

"grunt-jslint": "git://github.com/stephenmathieson/grunt-jslint.git#0.2.3-1",

However this dies with:

Loading "jslint.js" tasks and helpers...ERROR
>> TaskError: Unable to read "[path]node_modules/grunt-jslint/tasks/JSLint/jslint.js" file (Error code: ENOENT).

Looking at it I think this is because the JSLint submodule is not available. Is there a workaround for this or is it possible to make 0.2.3-1 available via npm?

Thanks!

New version of JSLint

Hi,

Just a heads up that there is a newer version of JSLint available now. I was trying to use the options available at jslint.com and failing.

Please update to latest jslint version

grunt-jslint does’t report all errors of missing space between function keyword and parenthesis of an anonymous function.

Example:

(function () {
    'use strict';

    module.exports = {
        start: function () {
            this.router.on('action:start', function() { this.set({loading: false}); });
        }
    };

}());

The callback function violates clearly jslint rules but this error doesn’t get reported.

This issue is probably fixed by ba6642aa85 commit of jslint

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.