Skip to content

Commit

Permalink
- In the process of finding good HTML Linting software.
Browse files Browse the repository at this point in the history
- Need to remove plugins that dont work as expected.
  • Loading branch information
John Miller committed Dec 26, 2015
1 parent 42f530f commit 1309c6c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 24 deletions.
8 changes: 8 additions & 0 deletions .htmllintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"doctype-first": "none",
"line-end-style": "none",
"spec-char-escape": true,
"id-no-dup": true,
"class-style": "none",
"attr-name-style": "none"
}
3 changes: 3 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"type": "git",
"url": "https://github.com/OfficeDev/Office-UI-Fabric"
},
"dependencies": {
"htmltidy": "https://github.com/battletoilet/gulp-htmltidy.git"
},
"private": false,
"ignore": [
"node_modules",
Expand Down
47 changes: 26 additions & 21 deletions gulp/FabricComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,37 @@ gulp.task('FabricComponents-copyAssets', function () {
.pipe(gulp.dest(Config.paths.distComponents));
});


function htmllintReporter(filepath, issues) {
if (issues.length > 0) {
issues.forEach(function (issue) {
gulputil.log(gulputil.colors.cyan('[gulp-htmllint] ') + gulputil.colors.white(filepath + ' [' + issue.line + ',' + issue.column + ']: ') + gulputil.colors.red('(' + issue.code + ') ' + issue.msg));
});

process.exitCode = 1;
}
}

gulp.task('FabricComponents-copyAndParseHTML', function () {

// Copy all Components files.
return gulp.src(Config.paths.componentsPath + '/**/*.html')
// Run HTML Tidy
.pipe(Plugins.htmllint({
config: {
'doctype-first': false,
'line-end-style': false,
'spec-char-escape': true,
'id-no-dup': true,
'class-style': false,
'attr-name-style': false
}
}, htmllintReporter))
// .pipe(Plugins.htmllint({config: Config.htmlLintPath}, ErrorHandling.handlHTMLLintError))
.pipe(Plugins.verifyHTML({
showErrors: true,
showWarnings: true,
"doctype": "omit",
"drop-empty-elements": false,
"drop-empty-paras": false,
}, function(err, html) {
var newError = '';
// console.log(err);

newError = err.replace('About this fork of Tidy: http://w3c.github.com/tidy-html5/', '');
newError = newError.replace('Bug reports and comments: https://github.com/w3c/tidy-html5/issues/', '');
newError = newError.replace('Or send questions and comments to [email protected]', '');
newError = newError.replace('Latest HTML specification: http://dev.w3.org/html5/spec-author-view/', '');
newError = newError.replace('HTML language reference: http://dev.w3.org/html5/markup/', '');
newError = newError.replace('Validate your HTML5 documents: http://validator.w3.org/nu/', '');
newError = newError.replace('Lobby your company to join the W3C: http://www.w3.org/Consortium', '');

if(newError.indexOf("\n") > -1) {
console.log("Found error");
}

console.log(newError);

}))
.on('error', ErrorHandling.onErrorInPipe)
.pipe(Plugins.changed(Config.paths.distComponents))
.on('error', ErrorHandling.onErrorInPipe)
Expand Down
6 changes: 3 additions & 3 deletions gulp/gulpPlugins/GulpVerifyHTML.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var gutil = require('gulp-util');
var through = require('through2');
var tidy = require("tidy-html5").tidy_html5;
var tidy = require("htmltidy").tidy;

const PLUGIN_NAME = 'GulpVerifyHTML';

var VerifyHTML = function(options) {
var VerifyHTML = function(options, callback) {

return through.obj(function (fileChunk, enc, cb) {
if (!options) {
Expand All @@ -21,7 +21,7 @@ var VerifyHTML = function(options) {
return cb();
}

var result = tidy(fileChunk.contents, options);
var result = tidy(fileChunk.contents, options, callback);

fileChunk.contents = new Buffer(String(result));
this.push(fileChunk);
Expand Down
3 changes: 3 additions & 0 deletions gulp/modules/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ var Config = function() {
//Debug Mode
this.debugMode = false;

// HTML Linting Configuration path
this.htmlLintPath = '.htmllintrc';

// Define paths.
this.distPath = 'dist';
this.srcPath = 'src';
Expand Down
11 changes: 11 additions & 0 deletions gulp/modules/ErrorHandling.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var path = require('path');
var gulputil = require('gulp-util');

var ErrorHandling = function() {
this.onErrorInPipe = function(error) {
console.log(error);
Expand All @@ -7,6 +9,15 @@ var ErrorHandling = function() {
console.log(error);
console.log("Html error occured");
}
this.handlHTMLLintError = function(filepath, issues) {
if (issues.length > 0) {
issues.forEach(function (issue) {
gulputil.log(gulputil.colors.cyan('[gulp-htmllint] ') + gulputil.colors.white(filepath + ' [' + issue.line + ',' + issue.column + ']: ') + gulputil.colors.red('(' + issue.code + ') ' + issue.msg));
});

process.exitCode = 1;
}
}
}

module.exports = new ErrorHandling();
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"gulp-wrap": "^0.11.0",
"gulp-zip": "^3.0.2",
"htmltidy": "0.0.6",
"htmltidy2": "^0.1.4",
"lodash": "^3.10.1",
"merge-stream": "^1.0.0",
"pretty-hrtime": "0.2.2",
Expand Down

0 comments on commit 1309c6c

Please sign in to comment.