kangax / html-lint

Linter that was originally part of kangax/html-minifier
MIT License
47 stars 6 forks source link

Documentation? Gulp/Grunt plugins? #6

Open reloaded opened 8 years ago

reloaded commented 8 years ago

Where is the package documentation/usage?

Are there any Gulp/Grunt plugins?

Can html-lint correctly lint check Angular.js HTML template partials?

alexlamsl commented 8 years ago

https://github.com/kangax/html-lint#usage is all there is. No configuration options at the moment.

Unlike html-minifier, there isn't any plugins for this yet. Feel free to create something similar to gulp-htmlmin or grunt-contrib-htmlmin.

No idea what "template partials" mean, but as long as they are valid HTML it should parse okay.

IceCreamYou commented 8 years ago

Here is a Grunt plugin. Drop it directly into your Gruntfile.js:

    // Define the Lint HTML task.
    grunt.registerMultiTask('linthtml', 'Lint HTML.', function() {
        var lint = require('html-minifier-lint').lint,
            filesToLint = grunt.file.expand(this.data.target),
            errorOutput = '',
            result;
        if (!filesToLint.length) {
            grunt.log.writeln('No HTML files found to lint.');
        }
        for (var i = 0, l = filesToLint.length; i < l; i++) {
            result = lint(grunt.file.read(filesToLint[i]));
            if (result) {
                errorOutput += '\n' + filesToLint[i] + '\n' + result;
            }
        }
        if (errorOutput) {
            grunt.log.error(errorOutput.substring(1));
            return false;
        }
        if (this.data.verbose) {
            grunt.log.writeln('These HTML files validated successfully:\n - ' + filesToLint.join('\n - '));
        }
        else {
            grunt.log.writeln('HTML validated successfully.');
        }
    });

And change your config:

    grunt.initConfig({
        linthtml: {
            dev: {
                target: ['app/**/*.html'], // array of file paths/globs of HTML files to lint
                verbose: true, // optional, defaults to false
            },
        },
    });