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

grunt-coffee-jshint #330

Merged
merged 4 commits into from Apr 22, 2015
Merged

grunt-coffee-jshint #330

merged 4 commits into from Apr 22, 2015

Conversation

m1kc
Copy link
Member

@m1kc m1kc commented Jan 2, 2015

https://npmjs.org/package/grunt-coffee-jshint

Потребует внимательной настройки, но детектит больше ошибок.

@m1kc m1kc added the feature label Feb 22, 2014
@m1kc
Copy link
Member Author

m1kc commented Jan 2, 2015

Переписал таск, для PR (chalk ещё можно добавить):

/*
 * grunt-coffee-jshint
 * https://github.com/bmac/grunt-coffee-jshint
 *
 * Copyright (c) 2013 bmac
 * Licensed under the MIT license.
 */

'use strict';

var hintFiles = require("coffee-jshint/lib-js/hint");


module.exports = function(grunt) {

    // Please see the Grunt documentation for more information regarding task
    // creation: http://gruntjs.com/creating-tasks

    grunt.registerMultiTask('coffee_jshint', 'grunt wrapper for coffee-jshint', function() {
        // Merge task-specific and/or target-specific options with these defaults.
        var options = this.options({
            jshintOptions: [],
            withDefaults: true,
            globals: []
        });
        var files = this.filesSrc;

        var errnum = 0;
        var fnum = 0;
        files.forEach(function(path) {
            var x = hintFile(path, options);
            fnum++;
            if (x.length > 0)
            {
                grunt.log.warn(x);
                errnum++;
            }
        });

        if (errnum === 0)
        {
            grunt.log.ok(fnum+" files lint free.");
        }
    });

    var hintFile = function(path, options) {

        var errors = hintFiles([path],
                               {options: options.jshintOptions,
                                withDefaults: options.withDefaults,
                                globals: options.globals},
                               false);
        var flattened_errors = [].concat.apply([], errors);
        var formatted_errors = flattened_errors.map(function(error) {
            return '' + path + ': ' + error.line + ":" + error.character + " " + error.reason;
        });

        return formatted_errors.join('\n');
    };

};

m1kc added a commit that referenced this pull request Apr 22, 2015
@m1kc m1kc merged commit 9e4cada into master Apr 22, 2015
@m1kc m1kc deleted the coffee-jshint-330 branch April 22, 2015 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant