Skip to content

Commit 7e079b3

Browse files
committed
Refactor UTF charset rule
1 parent 6e21688 commit 7e079b3

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

rules/req-charset-utf/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
'use strict';
2-
// eslint-disable-next-line camelcase
3-
const dom_utils = require('@linthtml/dom-utils');
2+
const { has_non_empty_attribute, is_tag_node, attribute_has_value } = require('@linthtml/dom-utils');
43

54
module.exports = {
65
name: 'htmlacademy/req-charset-utf',
76
// eslint-disable-next-line camelcase
87
lint(node, rule_config, { report }) {
9-
// eslint-disable-next-line camelcase
10-
if (dom_utils.is_tag_node(node) && node.name === 'meta') {
11-
const hasUtf = node.attributes.some((attribute) => attribute?.value?.chars.toLowerCase() === 'utf-8');
12-
const hasCharset = node.attributes.some((attribute) => attribute.name.chars === 'charset');
8+
if (is_tag_node(node) && node.name === 'meta') {
9+
const hasCharset = has_non_empty_attribute(node, 'charset', true);
10+
const hasUtf = attribute_has_value(node, 'charset', /^utf-8$/i);
1311

1412
if (hasCharset === true && hasUtf === false) {
1513
report({
1614
position: node.loc,
17-
message: '"The attribute charset="" should have a value of \'utf-8\'."',
15+
message: 'The attribute charset should have a value of "utf-8".',
1816
});
1917
}
2018
}

0 commit comments

Comments
 (0)