Code Monkey home page Code Monkey logo

broccoli-jshint's Introduction

Broccoli JSHint

Build Status

Run JSHint on the provided node.

Usage

var JSHinter = require('broccoli-jshint');

// Assuming someNode contains .js files
var node = new JSHinter(someNode);

Documentation

new JSHinter(inputNode, options)


options.jshintrcRoot {String}

Will look in the root of the provided node for a .jshintrc. If you would prefer to use another specific root for looking up your JSHint config, supply this option.

Default: input node root


options.jshintrcPath {String}

Specify the path to the .jshintrc that you would like to use. Use this option if you would like to use a .jshintrc file from a path that is not in the same hierarchy as your input node (if it is use the .jshintrcRoot).

Default: undefined


options.log {true|false}

Should we log errors to the console?

Default: true


options.disableTestGenerator {true|false}

If true tests will not be generated.

Default: false


options.testGenerator {Function}

The function used to generate test modules. You can provide a custom function for your client side testing framework of choice.

The function receives the following arguments:

  • relativePath - The relative path to the file being tested.
  • errors - A generated string of errors found.

Default generates QUnit style tests:

var path = require('path');

function(relativePath, errors) {
  return "module('" + path.dirname(relativePath) + "');";
         "test('" + relativePath + "' should pass jshint', function() { " +
         "  ok(passed, moduleName+" should pass jshint."+(errors ? "\n"+errors : '')); " +
         "});"
};

options.console {Object}

Allows you to provide a custom console object. This is useful if you have to supress console output in CI for example.

Default: console


options.annotation {String}

A human-readable description for this plugin instance.

Default: undefined

ZOMG!!! TESTS?!?!!?

I know, right?

Running the tests:

npm install
npm test

License

This project is distributed under the MIT license.

broccoli-jshint's People

Contributors

cyril-sf avatar haydn avatar joliss avatar kagemusha avatar mitchlloyd avatar patsy-issa avatar ramybenaroya avatar rwjblue avatar sebastianseilund avatar snostorm avatar stefanpenner avatar topaxi avatar turbo87 avatar wmeldon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

broccoli-jshint's Issues

Per Directory .jshintrc detection.

The current implementation only takes the root .jshintrc under consideration when processing a file tree.

Given

.jshintrc
/app
    foo.js
    .jshintrc
/tests
    foo_test.js
    .jshintrc

When linting foo.js, the rules from /app/.jshintrc would overwrite any overlapping rules found in /.jshintrc.

This would allow all the files to be linted, but /tests/foo_test.js could use a different set of rules than /app/foo.js.

This is where a call to get the relative .jshint could occur.

One possible approach would be to load all of the .jshint files into an array of paths up front and then just do string comparisons. Or perhaps cache as needed?

.jshintrc formatting error

If one has a formatting error in the .jshintrc file the error is reported incorrectly.

For example, there might be an extra comma:

{
  "predef": [
    "document",
    "window", // Extra comma here
  ],
}

In this case, the following error is thrown:

ReferenceError: self is not defined
    at JSHinter.getConfig (/Users/Duncan/Development/ember-easy-form-extensions/node_modules/ember-cli-qunit/node_modules/broccoli-jshint/index.js:114:7)

However, a closer look at the line in question shows:

self.console.error(chalk.red('Error occured parsing .jshintrc.'));

The call to chalk.red() is never made because self is undefined.

Add support for 'extends'

The extends on JSHint feature has been supported for awhile but during a recent migration discovered this isn't supported.

Not entirely sure how this should be resolved, would broccoli-jshint need to manually merge .jshintrc files?

Steps to repro.

// app/.jshintrc
{
  node: true
}

// app/tests/.jshintrc
{
  "extends": "../.jshintrc"
}
Livereload server on port 35729
Serving on http://localhost:4200/
self is not defined
ReferenceError: self is not defined
    at JSHinter.getConfig (C:\dev\project\node_modules\ember-cli-qunit\node_modules\broccoli-jshint\index.js:114:7)
    at C:\dev\project\node_modules\ember-cli-qunit\node_modules\broccoli-jshint\index.js:37:28
    at lib$rsvp$$internal$$tryCatch (C:\dev\project\node_modules\ember-cli\node_modules\rsvp\dist\rsvp.js:489:16)
    at lib$rsvp$$internal$$invokeCallback (C:\dev\project\node_modules\ember-cli\node_modules\rsvp\dist\rsvp.js:501:17)
    at lib$rsvp$$internal$$publish (C:\dev\project\node_modules\ember-cli\node_modules\rsvp\dist\rsvp.js:472:11)
    at lib$rsvp$asap$$flush (C:\dev\project\node_modules\ember-cli\node_modules\rsvp\dist\rsvp.js:1290:9)
    at process._tickCallback (node.js:355:11)

// output
unit/components/my-component-test.js: line 0, col 0, Bad option: 'extends'.

v0.5.0 Creating files for each test in Ember CLI

The files are supposed to be smashed into one file for tests and one file for app but something is going wrong and I'm ending up with this:
screen shot 2014-05-23 at 1 18 14 pm

Master ECLI only ends up running the JSHint tests for the test files (as they all have the word test in them) and switching back to 0.4.0 fixes it.

Adding v0.5.0 of jshint to v0.0.28 of ECLI causes the issue as well.

I can't really tell if the issue is on this side or if ECLI needs to use this plugin differently due the changes you made.

Edit: Relavent CLI pull: ember-cli/ember-cli#758

Add `assert.expect` to generated tests

We'd like to turn on QUnit.config.requireExpects in our project and in order to do so we need our JSHint tests to also add an assert.expect statement.

I realize it doesn't add a whole lot of value to the generated tests, but it would be nice to offer developers the option to use requireExpects with this module.

If this sounds reasonable I'll make the required PR (should be simple).

.jshintignore isn't being picked up.

I'm adding this here because I was looking into ember-cli/ember-cli#4586 to see how much work it would be. There's no way for the JSHint API to pickup .jshintignore files and it's intentional: jshint/jshint#2126

To solve it we would need to read the .jshintignore files and skip matching on our own in broccoli-jshint. There's a few issues with how JSHint picks up the .jshintignore files too, that should be bug-for-bug matched? https://github.com/jshint/jshint/issues?q=is%3Aissue+.jshintignore+is%3Aopen

.jshintrc global aren't being picked up

Apologies, I tried to submit a PR but the tests failed or failed to run at all (I'm developing on a Windows machine - le sigh).

Summary
I noticed that when I was using this module the global options I had set up in my .jshintrc file were not being picked up by jshint. According to this comment the globals need to be passed in as the third parameter when calling jshint.

My PR would have looked like this:

JSHinter.prototype.processString = function (content, relativePath) {

  var globals;
  if (this.jshintrc && this.jshintrc.globals) {
    globals = this.jshintrc.globals;
    delete this.jshintrc.globals;
  } else {
    globals = {};
  }

  var passed = JSHINT(content, this.jshintrc, globals);
  var errors = this.processErrors(relativePath, JSHINT.errors);

  if (!passed && this.log) {
    this.logError(errors);
  }

  if (!this.disableTestGenerator) {
    return this.testGenerator(relativePath, passed, errors);
  }
};

Any chance someone could make the pull request for me?

Is it possible to jshint while running broccoli serve?

Hi,

Sorry if this is not the right place to ask (please let me know where I can ask these sort of questions in the future if this is not the place).

I got this working after looking at index.js in broccoli-jshint/tests. This is the relevant part of my Brocfile.js:

var jshintTree = require('broccoli-jshint');
var broccoli = require('broccoli');

var appJs =  'app/js';
appJs = pickFiles(appJs, {
    srcDir  : '/',
    files   : ['**/*.js'],
    destDir : '/js'
});

builder = new broccoli.Builder(jshintTree(appJs));
builder.build();

// etc... module.exports = mergeTrees([appHtml, appJs]);

Running broccoli build build gives me jshint output, but I can't get the same sort of instant feedback I was expecting when using broccoli serve.

Is there a way to have this set up so that while the broccoli server is running, changing code gives me jshint output? Or am I approaching this in the wrong way? I was thinking that perhaps I should have jshint run as part of a grunt set of tasks. Haven't used the grunt-broccoli plugin yet but the idea would be to have jshint run as a task since it's technically not a build step correct? (as in it doesn't output any files).

Any thoughts on this / am I using this plugin correctly?

Regards,
J

Test Pluggability?

I've been enjoying the automatic test generation provided by this package but, being strangely insistent on using Mocha, I was wondering if there was any plan to allow easier modification of the tests generated.

I currently override the prototype after it's been included. It works, but it's not exactly an "official" approach.

The configurability will also need to be addressed in ECLI, but I'll tackle that when I come to it.

How to integrate into larger build process?

I am having trouble figuring out how to integrate this into a larger broccoli build process. Because it renames the files to have jshint.js, it breaks my browserify build step because all of the requires are now incorrect. Currently my build step is as follows:

  • React process jsx into js
  • jshint
  • browserify

If I just create a separate tree for the jshint, the errors are not reported. Any tips on what to do here?

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.