-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplugin.html-validate.table.js
More file actions
50 lines (43 loc) · 1.35 KB
/
plugin.html-validate.table.js
File metadata and controls
50 lines (43 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const { Rule } = require('html-validate');
const { nodeIgnore } = require('./plugin.html-validate.utils');
/**
* @typedef { import('html-validate').DOMReadyEvent } DOMReadyEvent
*/
/**
* Lint `table` should be wrapped with `.table-responsive`.
*/
class TableResponsiveRequired extends Rule {
/**
* @param {object} options - plugin options
*/
constructor(options) {
super({ ignore: null, ...options });
this.domReady = this.domReady.bind(this);
}
/**
* Setup plugin events.
*/
setup() {
this.on('dom:ready', this.domReady);
}
/**
* Lint html document.
* @param {DOMReadyEvent.document} document - document object
*/
domReady({ document }) {
const tables = document.querySelectorAll('table');
const ignores = this.options.ignore ? document.querySelectorAll(this.options.ignore) : [];
tables.forEach((table) => {
if (nodeIgnore(table, ignores)) {
return;
}
if (!(table.parent && table.parent.classList.contains('table-responsive'))) {
this.report(table, '<table> required `<div class="table-responsive">` parent.');
}
});
}
}
module.exports = { TableResponsiveRequired };
module.exports.rules = {
'pitcher/table-responsive-required': TableResponsiveRequired,
};