praveenvijayan / grunt-html-validation Goto Github PK
View Code? Open in Web Editor NEWW3C html validaton grunt plugin. Validate all files in a directory automatically.
License: MIT License
W3C html validaton grunt plugin. Validate all files in a directory automatically.
License: MIT License
I'm using grunt-html-validation with grunt-este-watch.
esteWatch: {
options: {
dirs: ['source/**/']
},
slim: function(filepath) {
if(filepath.match("source\/")) {
grunt.config(['validation', 'options', 'remoteFiles'], [RegExp.rightContext.replace(/.slim/, '')]);
return ['validation']
}
}
}
Then, first validation work fine.
But, from the second time is not work fine. I've got below message every after validation.
Warning: undefined is not a valid uri or options object.
The Repository, Homepage, and Bugs links still point to https://github.com/praveen/grunt-html-validation , which is a 404.
If you want to avoid validation-report.json
file to be generated you just need to set options.reportpath
to false
.
I wish we could do the same thing with options.path
.
I am unable to get it to work at all. I am trying to use it in ng-boilerplate. I get:
"Warning: must provide an include pattern"
related to the files: section.
I have tried:
files: {
src: ['<%=app_files.atpl%>', '<%=app_files.ctpl%>']
},
and
files: {
src: ['src/app/home/*.html']
},
and
files: {
src: ['src/app/home/home.html']
},
but can't get past the error.
What should be entered here?
The docs need to be corrected/clearer, please. The overview says "In your project's Gruntfile, add a section named html_validation ..." but that's wrong, apparently. It should be "validation" as per the sample. What is this: "your_target:" and how is it used? What are the correct possibilities for files.src? The yeoman example doesn't help those of us not using it.
Thanks.
Is there any way to tell the validator to skip over php tags? The project I'm currently working on relies heavily on php includes for factorization, but the files are otherwise 99% html.
The validator runs flawless on php files, I just need it to ignore whatever is between
Any ideas?
Hi.
I was trying to automate my rss.xml validation through this plugin but it doesn't work right.
Are XML files supported? An example is this which passes the W3C online validator.
validation: {
options: {
charset: "utf-8",
reportpath: false,
reset: true
},
html: {
options: {
doctype: "HTML5"
},
src: ["_site/**/*.html"]
},
xml: {
options: {
doctype: "XML"
},
src: ["_site/**/*.xml"]
}
},
Output:
C:\Users\xmr\Desktop\mpc-hc.org>grunt validation:xml
Running "validation:xml" (validation) task
Validation started for.. _site/rss.xml
1=> "delimiter \">\" invalid: only name, \"#IMPLIED\" and parameter separators a
re allowed" Line no: 2
2=> "cannot continue because of previous errors" Line no: 2
No of errors: 2
Validation started for.. _site/sitemap.xml
1=> "delimiter \">\" invalid: only name, \"#IMPLIED\" and parameter separators a
re allowed" Line no: 3
2=> "cannot continue because of previous errors" Line no: 3
No of errors: 2
Done, without errors.
Thanks in advance.
I'm on a mac and I find it very useful when I get a sound notification from the terminal when a warning/error occurs because I'm not always looking at the terminal or it is minimised. For example Sass:
That doesn't happen with this plugin when I have a validation error...
...and you can see that the task is not aborted which I think that's why there's no sound notification.
Here's my Grunt setup:
validation: {
options: {
reset: true,
stoponerror: true,
failHard: true
},
files: {
src: ['dev/{,*/}*.html']
}
}
So is there something wrong with my setup? Or is this an issue with the plugin?
what the hell with Validated skipping.._tempvlidation.html ? :)
my remote files are skipped for no reasons, anyone know why ?
Please allow an option to return a non-zero status if validation is not passed.
Presently I need to use this ugly hack to determine if validation passed of failed in a continuous integration environment.
https://github.com/fulldecent/Chart.js/blob/427d846b3544fe325b0ab8a332bf5d7e1af4ba2a/.travis.yml
w3c-validation fork plugin does not work. grunt and my editor throw syntax errors because of the - in the plugin names. I was using the original html-validation plugin without problems. This is my config stanza.
html-validation: {
options: {
reset: grunt.option('reset') || false,
stoponerror: false,
relaxerror: ["Bad value X-UA-Compatible for attribute http-equiv on element meta."] //ignores these errors
},
files: {
src: '*.html'
}
}
This is the error message:
Loading "Gruntfile.js" tasks...ERROR
SyntaxError: Unexpected token -
Task works great, love it. However, I noticed, today, that it appeared that the task was failing to reach the W3C service due to what looked like network issues...the console output kept telling me the network was unavailable, 1st try, 2nd try and so forth before skipping each file.
Come to find out, my IP address has being blocked by the service itself due to too many validation requests, or what the W3C considered "unreasonable"
Is there any way around this apart from simply letting the block expire each time it happens?
Hi:
I use 'watch' to monitor files save status.
every time I save file, grunt will trigger the HTML validator to valide my HTML file.
but if my html file pass valifdation, I write some wrong code and try again, validator did nothing.
For example:
wrong html code -> validator output error message.
non-error html code -> validator output sucessful message.
wrong html code -> validator output nothing!
my console shows as follows:
Running "validation:normal" (validation) task // but my HTML code has some Error@@!
Running "watch:sass" (watch) task
Completed in 0.684s at Fri Jun 20 2014 18:33:50 GMT+0800 (CST) - Waiting...
Thank you for your attention :)
Hank
The utility needs some work but I don't have the time to search through the code loops:
Looping issue is caused when called in this manner:
// -----------------------------------
//
// TASK: validation [Validate the html]
//
// -----------------------------------
validation: {
options: {
reset: true,
},
files: {
src: ["_site/**/*.html"]
}
},
When using the wrapfile option I always encounter the following error after the last validated file:
Fatal error: Unable to read "undefined" file (Error code: ENOENT).
This is due to the code on L275:
w3cjs_options.input = wrapfile.replace("<!-- CONTENT -->", grunt.file.read(files[counter]));
Changing L265:
if (options.wrapfile) {
Into
if (options.wrapfile && files[counter]) {
Will fix this, but I think this is more a workaround and not the best fix. What do you think?
Running "validation:dist" (validation) task
Validation started for.. src/index.html
1=> "An a start tag seen but an element of the same type was already open." Line no: 321
2=> "Stray end tag a." Line no: 324
No of errors: 2
Running "htmlmin:dist" (htmlmin) task
File dist/index.html created.
Running "cssmin:dist" (cssmin) task
File dist/main.css created.
Hello
For about two days I'm constantly getting an error:
Network error re-validating.. 1
and it skips the file after three attempts.
This occurs on two different machines in two different networks (so I doubt it's a local issue)
Nothing changed in my task options.
I have set up my grunt file as so...
validation: {
options: {
reset: true
},
indexHtml: {
src: 'app/views/index.html'
},
homeHtml: {
src: 'app/views/home.html'
}
}
but if I have a task list like this:
grunt.registerTask('dev', ['clear', 'jshint', 'validation', 'concat']);
the expected behaviour would be that index.html should be validated then home.html, however the validation exits after the first indexHtml task, and the homeHtml task isn't run.
The following task list also fails after the first file (index.html),
grunt.registerTask('dev', ['clear', 'jshint', 'validation:indexHtml', 'validation:homeHtml', 'concat']);
so, this may be related to my previous issue #25
If I use grunt-watch, I am able to call the indexHtml and homeHtml as they are changed, if I watch both of the files separately.
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"]);
};
If i create my task with the following json structure;
{
"options": {
"reportpath": false,
"stoponerror": false,
"path": "_Build/Shared Files/Temp/vaidation.json",
"failHard": true
},
"Accordion": {
"files": {
"src": "Accordion/preview/index.html"
}
},
"Blank": {
"files": {
"src": "Blank/preview/index.html"
}
},
"Chart": {
"files": {
"src": "Chart/preview/index.html"
}
},
"Figure": {
"files": {
"src": "Figure/preview/index.html"
}
}
}
It only runs the validation on the first task and then skips over the rest;
Running "validation:Accordion" (validation) task
Validation started for.. _Stream/Stream Templates/Accordion/preview/index.html
Validation successful..
Running "validation:Blank" (validation) task
Running "validation:Chart" (validation) task
Running "validation:Figure" (validation) task
Done, without errors.
The reason my json is like this is because i need separate watches that can run independently e.g. validation:Blank
Support for remote page validation
Hello,
I'm trying to validate a series of HTML files which contain mustache templates. The file isn't exactly HTML, as it simply contains a bunch of script elements with type text/template
, but I'd still like to validate the contents of that. Is there a way I can specify that I'm validating HTML5 document fragments?
Thanks,
Evan
I have installed the grunt-w3c-validation and used against my css file and it picks up some errors. I use the same css code and paste it on https://jigsaw.w3.org/css-validator and it came out correct. I have found that grunt-w3c-validation validator uses old validator and therefore shows errors. It needs to be aligned with w3c validator.
Cheers
Just install 0.1.16 for the first time.
It fails all time, even tested on a simple empty html 5 document.
There's no use of indexOf anywere.
$ grunt html-validation
Running "html-validation:files" (html-validation) task
Warning: Object # has no method 'indexOf' Use --force to continue.
Aborted due to warnings.
grunt settings in grunt file
"html-validation":{
options:{
reset: true,
stoponerror: false,
},
files:[{
expand:true,
cwd:'files/',
src:[
'foobar.html'
],
dest:'files/'
}]
},
Strange bug, some other grunt plugins stop working when preceeded by validation. They run, but don't seem to see their input files. It starts after v0.1.13.
I made a simple example using imagemin, but saw it also with aws_s3, and some mocha tests.
Can anyone else run my example and see if it happens to them as well?
Hi,
I've got this error using grunt-html-validation.
I'm using Yeoman and generator-angular.
I'm behind a corporate proxy.
Error: connect ETIMEDOUT
at errnoException (net.js:901:11)
at Object.afterConnect as oncomplete
Any idea ? Is it me ?
cm-mbp:test callumacrae$ grunt validation
Running "validation:files" (validation) task
Validated skipping..app/index.html
Validated skipping..app/test.html
The text is green, but it isn't validating the files, even when I change the files. Any ideas why?
{
"filename": "dist/docs/book_liberation_manifesto/Book_Liberation_Manifesto.html",
"error": []
},
{
"filename": "dist/docs/book_liberation_manifesto/Book_Liberation_Manifesto.html",
"error": []
},
{
"filename": "dist/docs/documentation/documentation.html",
"error": [
{
"lastLine": 28,
"lastColumn": 39,
....
Looks like the W3C are throwing a new warning out when using their service:
1=> "This interface to HTML5 document checking is deprecated. Use the Nu Html Checker at https://validator.w3.org/nu/ directly instead." Line no: undefined
No of errors: 1
Might be a good idea to update the plugin to use https://validator.w3.org/nu/
Relax error works fine for me for these:
"Attribute <br is not serializable as XML 1.0."
"No space between attributes."
But not this line...
"Element tags-input not allowed as child of element div in this context. (Suppressing further errors from this subtree.)"
Thought it might be something to do with your matching algorithm, maybe given the two full-stops?
Lots of things can be validated. It'd be less ambiguous, and more consistent, if this task were called 'htmlvalidation'.
The following relax rule didn't seem to work.
"& did not start a character reference. (& probably should have been escaped as &.)"
It appears that this task doesn't sync up with other grunt tasks. That is, the validator seems to be fired asynchronously for each file, but the task as a whole doesn't block until all validations are done. This allows other grunt tasks to execute while the validations are still running. This means the console output from grunt is threaded with output from other tasks.
Not to mention that the 'validated file' messages are not synced properly with the 'done, without errors' messages.
stoponerror
stops the validation of additional files
failHard
stops any further grunt tasks from executing
Given both stoponerror
and failHard
are true
When multiple files have errors
Then I should see the errors output for the first file
And no further grunt tasks should be executed
Actual:
I see the error output for the first file
But additional grunt tasks continue executing.
It appears that the presence of stoponerror=true
breaks the failHard
behavior.
Thanks for making this cool grunt plugin!
I was wondering if anyone knew of any good HTML reporters which help visualize the generated JSON data?
Hey folks,
I want to validate a folder which is not yet existing. I cannot skip this message, except to quit the Grunt task:
PATH:- No file is specified in the path!
My conf:
validation: {
options: {
failHard: false,
stoponerror: false,
reset: false,
},
notExistingFolder: {
src: [
'./src/notExistingFolder/**/*.html',
]
}
},
In the future of the project there will be some html
files.
Ability to pass relax options (sort of like JS Hint) to disable certain validation notices.
Works fine on default doctype but if i set it to HTML5 it fails with this message:
"delimiter ">" invalid: only name, "#IMPLIED" and parameter separators are allowed" Line no: 1
My first line is just this:
Will this plugin validate the outputted html files from an Ember app using handlebars?
We're looking at using this in Bootstrap, FYI: twbs/bootstrap#9396
Obviously one could run a watch task to trigger a forced (--reset=true) re-validation of a file but this is not the best approach and makes things less flexible.
I propose that the existing "validation cache" file store a hash of the file to be used for comparison to detect if a files content has changed. If so, re-validate it.
For those with performance worries, it could be an option:
"revalidationCacheCheck: true"
BTW, consider renaming the option "reset" to "alwaysRevalidate" to avoid some first run problems a lot of people seem to be having.
This docco page:
https://github.com/praveenvijayan/grunt-html-validation
Has no info about where to get an explanation for the meaning of a rule violation. In contrast the csslint plugin does have this info.
Would be good to know.
Do I just go to the W3C validation service and look there?
It would be nice if there was an option to ignore all warnings. At present warnings like this:
"The date input type is not supported in all browsers. Please be sure to test, and consider using a polyfill."
Cause the task to think there was an error and thus return fail (assuming failHard is on). I know this can be added to the relaxerror option, but it feels like warnings from the validation service should not be considered errors. An option like ignoreWarnings: true
would be nice or even better, if warning are shown but do not cause it to fail - even when failHard is true.
Thanks!
We are getting "Consider using h1 elements as top-level headings only (all h1 elements are treated as top-level headings by many screen readers and other tools).".
Even though I add this in relaxerror
, I still get the warnings.
validation: {
options: {
charset: 'utf-8',
doctype: 'HTML5',
failHard: true,
reset: true,
relaxerror: [
'Attribute ontouchstart not allowed on element body at this point.',
'Bad value X-UA-Compatible for attribute http-equiv on element meta.',
'Consider using h1 elements as top-level headings only (all h1 elements are treated as top-level headings by many screen readers and other tools).'
]
},
files: {
src: '_site/**/*.html'
}
},
Is this because this isn't really an error but a help message? Is there any way to suppress this kind of errors?
I just came across a regex issue on ignoring XML error reports on Bad value 6d0a884808fd72fcdbac270585981015metadata3320 for attribute id on element metadata: Not a valid XML 1.0 name.
The regex used: Bad value [\w]+ for attribute id on element metadata: Not a valid XML 1.0 name.
The regex that actually worked: Bad value [A-Za-z0-9]+ for attribute id on element metadata: Not a valid XML 1.0 name.
In terms of regex, both should actually be equally usable, but unfortunately are not. I guess it's a slash issue?
I have a grunt task list something like this:
grunt.registerTask('dev', ['jshint', 'validation', 'concat', 'watch']);
but 'validation' quits the task list, so concat and watch don't get called, even if there are no reported errors. Am not sure if there is an option flag or something else I'm missing?
https://www.npmjs.org/package/chalk
Also make use of grunt.log
/grunt.fail
in more places instead of console.log
.
I was confused by "Validated skipping" for valid files, had to check the source to see whether those files were being excluded...
I think "Validated" or "Validated completed for" or something similar would be more clear.
Edit: Didn't realize this is only shown for already validated files, makes sense now.
Hey there, first of all this is a great idea for a plugin. However we need to fix some stuff up.
I'm gonna PR a test update.
I'm unclear about how to specify which files to validate, and how validation-status.json works.
I want to validate all index.html files in directories under my/path. For example: my/path/dir1/index.html, my/path/dir2/index.html and my/path/dir3/index.html.
My Gruntfile.js has this:
files: {
src: ['my/path/**/index.html']
},
options: {
reset: true
}
However, only two files in the directories under my/path get validated when I run grunt validation
.
validation-status.json has only this (i.e. only a reference to the first file/subdirectory):
{"my/path/dir1/index.html":true}
What am I missing?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.