praveenvijayan / grunt-html-validation

W3C html validaton grunt plugin. Validate all files in a directory automatically.
MIT License
75 stars 39 forks source link

Loading "html_validation.js" tasks...ERROR and exit.... #74

Open prashantkoshta opened 9 years ago

prashantkoshta commented 9 years ago

Getting following error - C:\sample2>grunt

Local Npm module "grunt-install-dependencies" not found. Is it installed? Loading "html_validation.js" tasks...ERROR TypeError: Cannot assign to read only property 'name' of function () {

    // Merge task-specific and/or target-specific options with these defa

ults. va...... } Warning: Task "css-validation" not found. Use --force to continue.

This what i have in Gruntfile.js

module.exports = function(grunt) {

// Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'),

    'html-validation': {
        options: {
            reset: grunt.option('reset') || false,
            stoponerror: false,
            /*remotePath: "http://decodize.com/",
            remoteFiles: ["html/moving-from-wordpress-to-octopress/",
                            "css/site-preloading-methods/"], //or 
            remoteFiles: "validation-files.json", // JSON file contains array of page paths. 
            relaxerror: ["Bad value X-UA-Compatible for attribute http-equiv on element meta."] //ignores these errors */
        },
        files: {
            src: [
                'src/index.html',
                ]
        }
    },

    'css-validation': {
        options: {
            reset: grunt.option('reset') || false,
            stoponerror:false,
            relaxerror: [],
            profile: 'css3', // possible profiles are: none, css1, css2, css21, css3, svg, svgbasic, svgtiny, mobile, atsc-tv, tv 
            medium: 'all', // possible media are: all, aural, braille, embossed, handheld, print, projection, screen, tty, tv, presentation 
            warnings: '0' // possible warnings are: 2 (all), 1 (normal), 0 (most important), no (no warnings) 
          },
          files: {
            src: ['src/css/*.css']
          }
    }

});

grunt.loadNpmTasks('grunt-w3c-validation');
grunt.registerTask("default", ["html-validation"]);
grunt.registerTask("default", ["css-validation"]);

};

jrauschenbusch commented 9 years ago

Same issue here for https://github.com/mryvlin/grunt-w3c-validation. It's because of the 'use strict' in file html_validation.js in combination with the the first line of function getValidate. In strict mode, you are not allowed to overwrite a function name.

'use strict';

module.exports = function (grunt) {

   ...

   var htmlValidation = 'html-validation';
   var cssValidation = 'css-validation';

   ...

   var validate = function() {
      ...
   }

   ...

   function getValidate(validationType){
      validate.name = validationType;
      return validate;
   }

   grunt.registerMultiTask(htmlValidation, 'HTML W3C validation.', getValidate(htmlValidation));
   grunt.registerMultiTask(cssValidation, 'CSS W3C validation.', getValidate(cssValidation));
};

It could be fixed by replacing the function getValidate with:

    function getValidate(validationType) {
        return function () {
            this.name = validationType || validate.name;
            validate.apply(this, arguments);
        };
    }
icn2you commented 9 years ago

I applied the above fix and eliminated the task-not-found error; however, I am now receiving an unexpected token error:

Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: /Users/icn2you/Dropbox/Courses/Udacity/Nanodegrees/FEWD/Projects/portfolio/project1/Gruntfile.js:72
>>     html-validation: {
>>         ^
>> Unexpected token -
Warning: Task "default" not found. Use --force to continue.

The tasks in my Gruntfile.js are configured as follow. With some slight modification, I cut and pasted the task configuration from https://www.npmjs.com/package/grunt-w3c-validation.

    /* Validate HTML to HTML5 standard. */
    html-validation: {
      options: {
        reset: grunt.option('reset') || false,
        stoponerror: false,
        relaxerror: ["Bad value X-UA-Compatible for attribute http-equiv on element meta."]
      },
      files: {
          src: ['src/*.html']
      }
    },

    /* Validate CSS to CSS3 standard. */
    css-validation: {
      options: {
        reset: grunt.option('reset') || false,
        stoponerror:false,
        relaxerror: [],
        profile: 'css3',
        medium: 'all',
        warnings: '0'
      },
      files: {
        src: ['src/styles/*.css']
      }
    },

Sorry if this is a trivial error, and I just can't see it. I'm weary! Thanks in advance for any help you can offer.

jrauschenbusch commented 9 years ago

Hi @icn2you,

according to your console output there is a syntax error in line 72 in your Gruntfile.js. In JavaScript a valid identifier (-> valid variable names) cannot contain a hyphen symbol (see http://docstore.mik.ua/orelly/webprog/jscript/ch02_07.htm). The same rule applies to keys of key/value pairs in object literals. But you can use quoted property names in an object literal to circumvent this restriction like:

{ 'html-validation' : { ... } }

or

{ "html-validation" : { ... } }

Hope this information will help you to solve your problem.

icn2you commented 9 years ago

I'm grateful for your help @jrauschenbusch; thank you.

Please pardon my ignorance of JS. It will be short-lived I assure you! I am a bit surprised the developer wasn't aware of this issue.

My best to you always. =)