vigetlabs / grunt-complexity

A JavaScript complexity analysis grunt task.
MIT License
221 stars 22 forks source link

Empty target file causes failure #20

Closed Todd-Werelius closed 8 years ago

Todd-Werelius commented 10 years ago

This is a bit of an edge case, but I was using this on a project with a lot of files and sub directories and was using file globbing to send them all through

files: [{
   expand: true,
   cwd: './lib',
   src: ['**/*.js']
}],

Whenever I ran the grunt task it would immediately spit out a

Warning:  invalid source Use 

Without outputting anything else, this was driving me mad until I went through file by file and found an empty .js file

Apparently complexity-report does not like zero length files and the very first line tosses that error, not sure how to get the task to continue without without doing a real hack (below)

A very minor change would allow it to continue which might not be the way to go, but since this is a few rev's behind it might okay until things catch up

files.map(function(filepath) {

    var content = grunt.file.read(filepath);

    // *** Add a space if content is empty so cr.run will continue
    if (!content.length) {
       content = '  ';
    }

    return {
        filepath : filepath,
        analysis : cr.run( content, options )
    };
    .
    .
    .

If you think it makes sense I can do a PR and submit a change for review

nhunzaker commented 10 years ago

I imagine that is quite annoying. I'm totally cool with this change if you want to submit a PR.