Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Options' parameter conflates JSHint options and grunt command line arguments #178

Closed
MaxPRafferty opened this issue Oct 2, 2014 · 1 comment

Comments

@MaxPRafferty
Copy link

Issue

There is a name conflict between the "options" passed directly to the JSHint task and the options that grunt appends as command line arguments. I have seen this particularly with the --verbose argument. Some special options provided by grunt-contrib-jshint, such as ignores or reporter, behave correctly.


This behavior can be clearly seen with a task like:

jshint: {
    src: {
        options:{
            reporter: require('jshint-stylish'), /*not passed to JSHint, ok*/
            unused: false, /*passed to JSHint, ok*/
            verbose:true /*passed to JSHint, error*/
        }
        files{
            src:[ '/**/*.js' ]
        }
    }
}

When run, this task will break on the first error, reported as:
line 0 col 0 Bad option: 'verbose'. (E001)
Note that it includes the error code, which is only provided when the JSHint command is run with --verbose (I use the stylish reporter in this case because it's verbose output is very easy to identify concisely). This shows that Grunt is correctly appending its task.options to the command being run, in this case --verbose.
This behavior can also be seen by using a .jshintrc file, as the options are no longer passed to the linter, so the verbose flag can be passed to grunt as expected. Because of the behavior of the .jshintrc option, however, it is currently not possible to run in verbose mode and override options in a subtask simultaneously.
While i encountered this when attempting to run in verbose mode, this will also be the case for any flag not explicitly supported by grunt-contrib-jshint (http://www.jshint.com/docs/cli/)

Proposed Solutions

  1. Provide an alternate reserved name where options can be passed to the linter separately from the grunt options (e.g. 'jshint_options'). The pro of this solution is that it does not require any additional "special" flags be considered in the task "options" (as ignores is to --excludes in the current version), and will support any future CLI flags added to JSHint. The con is that this is a breaking change for anyone using a task with the name of the selected reserved name.
  2. Implement special options handling for the missing JSHint CLI options (http://www.jshint.com/docs/cli/): verbose, show-non-errors, extract, help, and version. The only con of this solution is that if these options change or are added to, these changes will need to be reflected in this repo as well.
@sindresorhus
Copy link
Member

Should be resolved in grunt and not here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants