Closed ghost closed 10 years ago
Thanks for the report. Your coffeelint
config is using the "files object format" for specifying dest
:src
pairs. With this format, the object property name is the dest
file and the property value is your src
pattern(s). So you are saying take the all source files in **/*.coffee
and map them to the destination file named src
.
Obviously the the coffeelint
task doesn't produce any destination files (so a file named src
is never created), but the newer
task doesn't know that. The newer
task looks at this files configuration and decides it needs to use all source files in the dest
:src
pair because the dest
file (named src
in your case`) doesn't yet exist.
So there are two alternative configurations for your coffeelint
task that should work. I'll provide them in JavaScript here because it should be useful to more people who find this ticket in the future.
Configuring tasks that don't generate dest
files:
grunt.initConfig({
coffeelint: {
app: {
src: '**/*.coffee'
}
} // ... additional task config
});
grunt.initConfig({
coffeelint: {
app: {
files: [{src: '**/*.coffee'}]
}
} // ... additional task config
});
Thank you! I have tried both solutions and none of them works :(
I set up the grunt-newer-coffeelint
repo to provide a complete example. You should be able to clone it, run npm install
, and then run npm start
to confirm things are working. When I do this, I can modify a single source file and see that only that single file is linted. See below for more output.
Run the start
task (verbose output edited to highlight important bits):
$ grunt --verbose start
Initializing
Command-line options: --verbose
... output clipped ...
Running "newer:coffeelint" (newer) task
Running "newer:coffeelint:app" (newer) task
Options: cache="/path/to/grunt-newer-coffeelint/node_modules/grunt-newer/.cache"
Running "coffeelint:app" (coffeelint) task
Verifying property coffeelint.app exists in config...OK
Files: lib/index.coffee, lib/more.coffee
Options: (none)
Linting lib/index.coffee...
Reading lib/index.coffee...OK
OK
Linting lib/more.coffee...
Reading lib/more.coffee...OK
OK
>> 2 files lint free.
Running "newer-postrun:coffeelint:app:-1:/path/to/grunt-newer-coffeelint/node_modules/grunt-newer/.cache" (newer-postrun) task
Writing /path/to/grunt-newer-coffeelint/node_modules/grunt-newer/.cache/coffeelint/app/timestamp...OK
Running "watch" task
Waiting...Verifying property watch exists in config...OK
Verifying property watch.all.files exists in config...OK
Watching lib/index.coffee for changes.
Watching lib/more.coffee for changes.
OK
So the two source .coffee
files were linted and the watch was started. All as expected.
Now, update the more.coffee
file (e.g. with touch lib/more.coffee
):
>> File "lib/more.coffee" changed.
Initializing
Command-line options: --verbose
... output clipped ...
Running "newer:coffeelint" (newer) task
Running "newer:coffeelint:app" (newer) task
Options: cache="/path/to/grunt-newer-coffeelint/node_modules/grunt-newer/.cache"
Files: lib/index.coffee, lib/more.coffee
Running "coffeelint:app" (coffeelint) task
Verifying property coffeelint.app exists in config...OK
Files: lib/more.coffee -> [no dest]
Options: (none)
Linting lib/more.coffee...
Reading lib/more.coffee...OK
OK
>> 1 file lint free.
Running "newer-postrun:coffeelint:app:1:/path/to/grunt-newer-coffeelint/node_modules/grunt-newer/.cache" (newer-postrun) task
Writing /path/to/grunt-newer-coffeelint/node_modules/grunt-newer/.cache/coffeelint/app/timestamp...OK
Done, without errors.
Completed in 0.461s at Mon Nov 25 2013 13:32:19 GMT-0700 (MST) - Waiting...
OK
This time only the single modified source file (more.coffee
) was run through the linter as expected.
Next, update the index.coffee
file (touch lib/index.coffee
) to confirm that only it gets linted.
>> File "lib/index.coffee" changed.
Initializing
Command-line options: --verbose
... output clipped ...
Running tasks: newer:coffeelint
Running "newer:coffeelint" (newer) task
Running "newer:coffeelint:app" (newer) task
Options: cache="/path/to/grunt-newer-coffeelint/node_modules/grunt-newer/.cache"
Files: lib/index.coffee, lib/more.coffee
Running "coffeelint:app" (coffeelint) task
Verifying property coffeelint.app exists in config...OK
Files: lib/index.coffee -> [no dest]
Options: (none)
Linting lib/index.coffee...
Reading lib/index.coffee...OK
OK
>> 1 file lint free.
Running "newer-postrun:coffeelint:app:1:/path/to/grunt-newer-coffeelint/node_modules/grunt-newer/.cache" (newer-postrun) task
Writing /path/to/grunt-newer-coffeelint/node_modules/grunt-newer/.cache/coffeelint/app/timestamp...OK
Done, without errors.
Completed in 0.487s at Mon Nov 25 2013 13:32:27 GMT-0700 (MST) - Waiting...
As expected, only one file (index.coffee
) run through the linter. I tested this with grunt-newer@0.5.4
and grunt-newer@0.6.0
and got expected results with both.
Please reopen if you are able to reproduce this with the grunt-newer-coffeelint example (or if you can provide another complete example that demonstrates a problem). Thanks.
Thanks @tschaub, your comment helped me get this working properly as I'm new to Grunt.
Hello, I tried to set up your module with the coffeelint task in the same way as it's in your example for jshint.
It looks like this:
However, when I change a coffescript file, it automatically execute the coffeelint task for all coffeescript files in the whole project.
What is wrong?
Thank you.