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

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

Open
prashantkoshta opened this issue Mar 22, 2015 · 4 comments · May be fixed by mryvlin/grunt-w3c-validation#1
Open

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

prashantkoshta opened this issue Mar 22, 2015 · 4 comments · May be fixed by mryvlin/grunt-w3c-validation#1

Comments

@prashantkoshta
Copy link

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
Copy link

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
Copy link

icn2you commented Jun 22, 2015

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
Copy link

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
Copy link

icn2you commented Jul 6, 2015

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. =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants