3

I'm using grunt with the grunt-eslint plugin. This is part of a larger grunt task that first finds changed files and does various tasks with them. If there aren't any JS files changed (for example if I just change a CSS file) the whole task aborts because eslint fails with a "could not find any files to validate" message.

$ grunt eslint:precommit
Running "eslint:precommit" (eslint) task
Could not find any files to validate.
Warning: Task "eslint:precommit" failed. Use --force to continue.

Aborted due to warnings.

I don't want the task to fail if there aren't any JS files found.

Is there a way to either:

A. Have the grunt task not even call eslint and not fail if no files are run?

B. Have eslint not fail if no files are run?

(Related, but specific to a different tool called from grunt: Can an assemble target be silenced if there are no matching files? (Without using --force))

Community
  • 1
  • 1
Marc Stober
  • 10,237
  • 3
  • 26
  • 31

1 Answers1

1

Using Dynamic task is your solution, here the link for the docs: http://gruntjs.com/frequently-asked-questions#dynamic-alias-tasks

Related links:

Community
  • 1
  • 1
Gyandeep
  • 12,726
  • 4
  • 31
  • 42
  • Thanks. So basically there is no option to skip a task if files aren't found, but I can create my own task that checks for files and calls the task I want to call if they are found? That's fine, I'm just trying to get grunt.file.isMatch to find the files now. – Marc Stober Jan 07 '16 at 12:32
  • 1
    And it's not grunt.file.isMatch, but grunt.file.expand that actually finds files. Blogged about it here: http://www.marcstober.com/blog/2016/01/07/grunt-file-match-and-grunt-file-ismatch-do-not-access-file-system/ – Marc Stober Jan 07 '16 at 14:06