<commit_before>/*
 * grunt-w3c-html-validation
 * https://github.com/vikash-bhardwaj/grunt-w3c-html-validation
 * Forked from grunt-html-validation https://github.com/praveenvijayan/grunt-html-validation
 * Copyright (c) 2015 <NAME>
 * Licensed under the MIT license which is based on original license from Forked plug-in.
 */

'use strict';

module.exports = function (grunt) {

    var w3cjs = require('w3cjs'),
        colors = require('colors'),
        chalk = require('chalk'),
        rval = require('./lib/remoteval'),
        generateHTMLReports = require('./lib/generateHTMLReport');

    colors.setTheme({
        silly: 'rainbow',
        input: 'grey',
        verbose: 'cyan',
        prompt: 'grey',
        info: 'green',
        data: 'grey',
        help: 'cyan',
        warn: 'yellow',
        debug: 'blue',
        error: 'red',
        blue: 'blue'
    });

    var counter = 0,
        errorFileCounter = 0,
        msg = {
            error: 'Something went wrong',
            ok: 'Validation successful..',
            start: 'Validation started for.. '.info,
            networkError: 'Network error re-validating..'.error,
            validFile: 'Validated skipping..',
            nofile: ':- No file is specified in the path!',
            nextfile: 'Skipping to next file..'.verbose,
            eof: 'End of File..'.verbose,
            fileNotFound: 'File not found..'.error,
            remotePathError: 'Remote path '.error + '(options->remotePath) '.grey +
                             'is mandatory when remote files '.error +
                             '(options-> remoteFiles) '.grey + 'are specified!'.error
        },
        len,
        reportArry = [],
        retryCount = 0,
        reportFilename = '';

    grunt.registerMultiTask('validation', 'HTML W3C validation.', function () {
        // Merge task-specific and/or target-specific options with these defaults.
        var options = this.options({
            path: 'validation-status.json',
            reportpath: 'validation-report.json',
            reset: false,
            proxy: null,
            stoponerror: false,
            failHard: false,
            remotePath: false,
            maxTry: 3,
            relaxerror: [],
            doctype: false, // Defaults false for autodetect
            charset: false, // Defaults false for autodetect
            generateReport: true,
            errorHTMLRootDir: "w3cErrors",
            useTimeStamp: false,
            errorTemplate: "error_Template.html"
        });
        
        var done = this.async(),
            files = grunt.file.expand(this.filesSrc),
            flen = files.length,
            readSettings = {},
            isRelaxError = false;
        
        isRelaxError = options.relaxerror.length && options.relaxerror.length !== '';

        var makeFileList = function (files) {
            return files.map(function (file) {
                return options.remotePath + file;
            });
        };

        //Reset current validation status and start from scratch.
        if (options.reset) {
            grunt.file.write(options.path, '{}');
        }

        if (!flen) {
            var nomsg = this.data.src;
            console.log(nomsg + msg.nofile.error);
        }

        var addToReport = function (fname, status) {
            var relaxedReport = [];

            for (var i = 0; i < status.length; i++) {
                if (!checkRelaxError(status[i].message)) {
                    relaxedReport.push(status[i]);
                }
            }

            var report = {};
            report.filename = fname;
            report.error = relaxedReport;
            reportArry.push(report);

            /**
             * Code to generate the HTML Reports if needed
             */
            if(relaxedReport[0] && options.generateReport === true) {
                generateHTMLReports(report, options, errorFileCounter);
                errorFileCounter++;
            }
        };

        var wrapfile,
            wrapfile_line_start = 0;
        var validate = function (files) {
            if (files.length) {
                // fix: Fatal error: Unable to read 'undefined' file (Error code: ENOENT).
                if (!files[counter]) {
                    done();
                    return;
                }


                if (grunt.file.exists(options.path)) {
                    readSettings = grunt.file.readJSON(options.path);
                }
                var currFileStat = readSettings[files[counter]] || false;

                if (currFileStat) {
                    console.log(msg.validFile.green + files[counter]);
                    reportFilename = options.remoteFiles ? dummyFile[counter] : files[counter];
                    addToReport(reportFilename, false);
                    counter++;
                    validate(files);
                    done();
                    return;
                }

                if (files[counter] !== undefined) {

                    var filename = options.remoteFiles ? dummyFile[counter] : files[counter];

                    console.log(msg.start + filename);
                }

                var w3cjs_options = {
                    //file: files[counter],       // file can either be a local file or a remote file
                    // file: 'http://localhost:9001/010_gul006_business_landing_o2_v11.html',
                    output: 'json',             // Defaults to 'json', other option includes html
                    doctype: options.doctype,   // Defaults false for autodetect
                    charset: options.charset,   // Defaults false for autodetect
                    proxy: options.proxy,       // Proxy to pass to the w3c library
                    callback: function (res) {

                        flen = files.length;

                        if (!res.messages) {
                            ++retryCount;<commit_msg>Fixed the Issue of Local files were not validating properly if there were any error free URL<commit_after>/*
 * grunt-w3c-html-validation
 * https://github.com/vikash-bhardwaj/grunt-w3c-html-validation
 * Forked from grunt-html-validation https://github.com/praveenvijayan/grunt-html-validation
 * Copyright (c) 2015 <NAME>
 * Licensed under the MIT license which is based on original license from Forked plug-in.
 */

'use strict';

module.exports = function (grunt) {

    var w3cjs = require('w3cjs'),
        colors = require('colors'),
        chalk = require('chalk'),
        rval = require('./lib/remoteval'),
        generateHTMLReports = require('./lib/generateHTMLReport');

    colors.setTheme({
        silly: 'rainbow',
        input: 'grey',
        verbose: 'cyan',
        prompt: 'grey',
        info: 'green',
        data: 'grey',
        help: 'cyan',
        warn: 'yellow',
        debug: 'blue',
        error: 'red',
        blue: 'blue'
    });

    var counter = 0,
        errorFileCounter = 0,
        msg = {
            error: 'Something went wrong',
            ok: 'Validation successful..',
            start: 'Validation started for.. '.info,
            networkError: 'Network error re-validating..'.error,
            validFile: 'Validated skipping..',
            nofile: ':- No file is specified in the path!',
            nextfile: 'Skipping to next file..'.verbose,
            eof: 'End of File..'.verbose,
            fileNotFound: 'File not found..'.error,
            remotePathError: 'Remote path '.error + '(options->remotePath) '.grey +
                             'is mandatory when remote files '.error +
                             '(options-> remoteFiles) '.grey + 'are specified!'.error
        },
        len,
        reportArry = [],
        retryCount = 0,
        reportFilename = '';

    grunt.registerMultiTask('validation', 'HTML W3C validation.', function () {
        // Merge task-specific and/or target-specific options with these defaults.
        var options = this.options({
            path: 'validation-status.json',
            reportpath: 'validation-report.json',
            reset: true,
            proxy: null,
            stoponerror: false,
            failHard: false,
            remotePath: false,
            maxTry: 3,
            relaxerror: [],
            doctype: false, // Defaults false for autodetect
            charset: false, // Defaults false for autodetect
            generateReport: true,
            errorHTMLRootDir: "w3cErrors",
            useTimeStamp: false,
            errorTemplate: "error_Template.html"
        });
        
        var done = this.async(),
            files = grunt.file.expand(this.filesSrc),
            flen = files.length,
            readSettings = {},
            isRelaxError = false;
        
        isRelaxError = options.relaxerror.length && options.relaxerror.length !== '';

        var makeFileList = function (files) {
            return files.map(function (file) {
                return options.remotePath + file;
            });
        };

        //Reset current validation status and start from scratch.
        if (options.reset) {
            grunt.file.write(options.path, '{}');
        }

        if (!flen) {
            var nomsg = this.data.src;
            console.log(nomsg + msg.nofile.error);
        }

        var addToReport = function (fname, status) {
            var relaxedReport = [];

            for (var i = 0; i < status.length; i++) {
                if (!checkRelaxError(status[i].message)) {
                    relaxedReport.push(status[i]);
                }
            }

            var report = {};
            report.filename = fname;
            report.error = relaxedReport;
            reportArry.push(report);

            /**
             * Code to generate the HTML Reports if needed
             */
            if(relaxedReport[0] && options.generateReport === true) {
                generateHTMLReports(report, options, errorFileCounter);
                errorFileCounter++;
            }
        };

        var wrapfile,
            wrapfile_line_start = 0;
        var validate = function (files) {
            if (files.length) {
                // fix: Fatal error: Unable to read 'undefined' file (Error code: ENOENT).
                if (!files[counter]) {
                    done();
                    return;
                }


                if (grunt.file.exists(options.path)) {
                    readSettings = grunt.file.readJSON(options.path);
                }
                var currFileStat = readSettings[files[counter]] || false;

                if (currFileStat) {
                    console.log(msg.validFile.green + files[counter]);
                    reportFilename = options.remoteFiles ? dummyFile[counter] : files[counter];
                    addToReport(reportFilename, false);
                    counter++;
                    validate(files);
                    //done();
                    return;
                }

                if (files[counter] !== undefined) {

                    var filename = options.remoteFiles ? dummyFile[counter] : files[counter];

                    console.log(msg.start + filename);
                }

                var w3cjs_options = {
                    //file: files[counter],       // file can either be a local file or a remote file
                    // file: 'http://localhost:9001/010_gul006_business_landing_o2_v11.html',
                    output: 'json',             // Defaults to 'json', other option includes html
                    doctype: options.doctype,   // Defaults false for autodetect
                    charset: options.charset,   // Defaults false for autodetect
                    proxy: options.proxy,       // Proxy to pass to the w3c library
                    callback: function (res) {

                        flen = files.length;

                        if (!res.messages) {
                            ++retryCount;
{'fraction_non_alphanumeric': 0.10946103787752377, 'fraction_numerical': 0.005339562823293843, 'mean_word_length': 1.475118728061119, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3361988', 'n_tokens_mistral': 3185, 'n_tokens_neox': 2999, 'n_words': 769}