How to use the htmlhint.HTMLHint.addRule function in htmlhint

To help you get started, we’ve selected a few htmlhint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github learningequality / kolibri / frontend_build / src / htmlhint_custom.js View on Github external
/*
  Custom rules for the HTML linter.
  Custom rule IDs are prefixed with a double dash ('--')
*/
var HTMLHint = require('htmlhint').HTMLHint;

/* helper to convert alternate-style newlines to unix-style */
function clean(val) {
  return val.replace(/\r\n?/g, '\n');
}

/*
  Based on the existing `tag-self-close` rule
*/
HTMLHint.addRule({
  id: '--no-self-close-common-html5-tags',
  description: 'Self-closing HTML5 tags are not valid.',
  init: function(parser, reporter) {
    var self = this;
    var commonTags = parser.makeMap(`a,audio,b,body,button,canvas,caption,center,dir,div,dl,em,font,footer,
      form,h1,h2,h3,h4,h5,h6,head,header,html,iframe,label,li,main,map,menu,nav,object,option,output,p,progress,
      q,script,section,select,span,strong,style,sub,table,tbody,td,textarea,th,thead,time,title,tr,u,ul,var,video`);
    parser.addListener('tagstart', function(event) {
      var tagName = event.tagName.toLowerCase();
      if (event.close && commonTags[tagName]) {
        reporter.error(
          'In : [ ' + event.tagName + ' ] self-closing tags are not valid HTML5.',
          event.line,
          event.col,
          self,
          event.raw
github bezoerb / gulp-htmlhint / index.js View on Github external
htmlhintPlugin.addRule = function (rule) {
  'use strict';
  return HTMLHint.addRule(rule);
};