Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit c9ec607

Browse files
committed
Convert to es6 modules
1 parent a331196 commit c9ec607

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ $ npm install --save-dev gulp-w3c-html-validator
2020
Create a task in your **gulpfile.js**:
2121
```javascript
2222
// Imports
23-
const gulp = require('gulp');
24-
const htmlValidator = require('gulp-w3c-html-validator');
23+
import gulp from 'gulp';
24+
import htmlValidator from 'gulp-w3c-html-validator';
2525

2626
// Tasks
2727
const task = {
2828
validateHtml() {
2929
return gulp.src('target/**/*.html')
30-
.pipe(htmlValidator())
30+
.pipe(htmlValidator.analyzer())
3131
.pipe(htmlValidator.reporter());
3232
},
3333
};
@@ -43,8 +43,8 @@ and `messages` (Array).
4343
### Example usage
4444
```javascript
4545
// Import
46-
const htmlValidator = require('gulp-w3c-html-validator');
47-
const through2 = require('through2');
46+
import htmlValidator from 'gulp-w3c-html-validator';
47+
import through2 from 'through2';
4848

4949
// Tasks
5050
const task = {
@@ -55,7 +55,7 @@ const task = {
5555
throw Error('HTML validation error(s) found');
5656
};
5757
return gulp.src('target/**/*.html')
58-
.pipe(htmlValidator())
58+
.pipe(htmlValidator.analyzer())
5959
.pipe(through2.obj(handleFile)); //custom reporter
6060
},
6161
};
@@ -89,7 +89,7 @@ const task = {
8989
validateHtml() {
9090
const ignoreDuplicateIds = (type, message) => !/^Duplicate ID/.test(message);
9191
return gulp.src('target/**/*.html')
92-
.pipe(htmlValidator({ verifyMessage: ignoreDuplicateIds })) //custom function
92+
.pipe(htmlValidator.analyzer({ verifyMessage: ignoreDuplicateIds })) //custom function
9393
.pipe(htmlValidator.reporter());
9494
},
9595
};

html-validator.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44
// MIT License
55

66
// Imports
7-
const color = require('ansi-colors');
8-
const PluginError = require('plugin-error');
9-
const log = require('fancy-log');
10-
const through2 = require('through2');
11-
const w3cjs = require('w3cjs');
7+
import color from 'ansi-colors';
8+
import PluginError from 'plugin-error';
9+
import log from 'fancy-log';
10+
import through2 from 'through2';
11+
import w3cjs from 'w3cjs';
1212

1313
// Setup
1414
const pluginName = 'gulp-w3c-html-validator';
1515

1616
// Gulp plugin
17-
const plugin = {
17+
const htmlValidator = {
18+
19+
setW3cCheckUrl: w3cjs.setW3cCheckUrl,
1820

1921
handleMessages(file) {
2022
const text = {
@@ -69,10 +71,10 @@ const plugin = {
6971
file.w3cjs.messages.forEach(processMessage);
7072
},
7173

72-
htmlValidator(options) {
74+
analyzer(options) {
7375
options = options || {};
7476
if (typeof options.url === 'string')
75-
w3cjs.setW3cCheckUrl(options.url);
77+
htmlValidator.setW3cCheckUrl(options.url);
7678
const transform = (file, encoding, done) => {
7779
const handleValidation = (error, response) => {
7880
if (error)
@@ -85,7 +87,7 @@ const plugin = {
8587
messages: filteredMessages,
8688
unfiltered: response.messages,
8789
};
88-
plugin.handleMessages(file);
90+
htmlValidator.handleMessages(file);
8991
done(null, file);
9092
};
9193
const w3cjsOptions = {
@@ -114,7 +116,4 @@ const plugin = {
114116

115117
};
116118

117-
// Module loading
118-
module.exports = plugin.htmlValidator;
119-
module.exports.reporter = plugin.reporter;
120-
module.exports.setW3cCheckUrl = w3cjs.setW3cCheckUrl;
119+
export { htmlValidator };

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "gulp-w3c-html-validator",
33
"version": "2.0.1",
44
"license": "MIT",
5+
"type": "module",
56
"description": "Gulp plugin to validate HTML using the W3C Markup Validation Service",
67
"main": "html-validator.js",
78
"repository": "github:center-key/gulp-w3c-html-validator",

spec/mocha.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Mocha Specification Cases
22

33
// Imports
4-
const fs = require('fs');
5-
const should = require('should');
6-
const Vinyl = require('vinyl');
4+
import { readdirSync, readFileSync } from 'fs';
5+
import should from 'should';
6+
import Vinyl from 'vinyl';
77

88
// Plugin
9-
const htmlValidator = require('../html-validator.js');
9+
import { htmlValidator } from '../html-validator.js';
1010
console.log(' Input HTML files for validation:');
11-
fs.readdirSync('spec/html').forEach(file => console.log(' spec/html/' + file));
11+
readdirSync('spec/html').forEach(file => console.log(' spec/html/' + file));
1212

1313
////////////////////////////////////////////////////////////////////////////////////////////////////
1414
describe('The gulp-w3c-html-validator plugin', () => {
@@ -19,10 +19,10 @@ describe('The gulp-w3c-html-validator plugin', () => {
1919
path: 'spec/html/valid.html',
2020
cwd: 'spec/',
2121
base: 'spec/html/',
22-
contents: fs.readFileSync('spec/html/valid.html')
22+
contents: readFileSync('spec/html/valid.html')
2323
};
2424
const mockFile = new Vinyl(vinylOptions);
25-
const stream = htmlValidator();
25+
const stream = htmlValidator.analyzer();
2626
const handleFileFromStream = (file) => {
2727
should.exist(file);
2828
file.w3cjs.success.should.equal(true);
@@ -51,10 +51,10 @@ describe('The gulp-w3c-html-validator plugin', () => {
5151
path: 'spec/html/invalid.html',
5252
cwd: 'spec/',
5353
base: 'spec/html/',
54-
contents: fs.readFileSync('spec/html/invalid.html')
54+
contents: readFileSync('spec/html/invalid.html')
5555
};
5656
const mockFile = new Vinyl(vinylOptions);
57-
const stream = htmlValidator();
57+
const stream = htmlValidator.analyzer();
5858
const handleFileFromStream = (file) => {
5959
should.exist(file);
6060
file.w3cjs.success.should.equal(false);
@@ -89,12 +89,12 @@ describe('The verifyMessage option', () => {
8989
path: 'spec/html/invalid.html',
9090
cwd: 'spec/',
9191
base: 'spec/html/',
92-
contents: fs.readFileSync('spec/html/invalid.html')
92+
contents: readFileSync('spec/html/invalid.html')
9393
};
9494
const mockFile = new Vinyl(vinylOptions);
9595
const ignore = /^Element .blockquote. not allowed as child of element/;
9696
const verifyMessage = (type, message) => !ignore.test(message);
97-
const stream = htmlValidator({ verifyMessage: verifyMessage, skipWarnings: true });
97+
const stream = htmlValidator.analyzer({ verifyMessage: verifyMessage, skipWarnings: true });
9898
const handleFileFromStream = (file) => {
9999
should.exist(file);
100100
file.w3cjs.success.should.equal(true);
@@ -131,7 +131,7 @@ describe('The htmlValidator.reporter() function', () => {
131131
path: 'spec/html/valid.html',
132132
cwd: 'spec/',
133133
base: 'spec/html/',
134-
contents: fs.readFileSync('spec/html/valid.html')
134+
contents: readFileSync('spec/html/valid.html')
135135
};
136136
const mockFile = new Vinyl(vinylOptions);
137137
const stream = htmlValidator.reporter();
@@ -145,7 +145,7 @@ describe('The htmlValidator.reporter() function', () => {
145145
path: 'spec/html/invalid.html',
146146
cwd: 'spec/',
147147
base: 'spec/html/',
148-
contents: fs.readFileSync('spec/html/invalid.html')
148+
contents: readFileSync('spec/html/invalid.html')
149149
};
150150
const mockFile = new Vinyl(vinylOptions);
151151
mockFile.w3cjs = {
@@ -154,7 +154,7 @@ describe('The htmlValidator.reporter() function', () => {
154154
};
155155
const stream = htmlValidator.reporter();
156156
const writeToStream = () => stream.write(mockFile);
157-
(writeToStream).should.throw(/HTML validation failed/);
157+
writeToStream.should.throw(/HTML validation failed/);
158158
stream.end();
159159
return stream;
160160
});

0 commit comments

Comments
 (0)