Skip to content

Commit a9659e9

Browse files
Merge pull request #77 from htmlacademy/fix/req-charset-utf
Adds a property check
2 parents 297f12b + d56ff1b commit a9659e9

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

.eslintrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@
55
},
66
"extends": [
77
"htmlacademy/vanilla"
8-
]
8+
],
9+
"rules": {
10+
"camelcase": [2, {
11+
"ignoreDestructuring": true
12+
}]
13+
}
914
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"eslint": "eslint rules/**/*.js",
8-
"lint": "eslint"
8+
"lint": "npm run eslint"
99
},
1010
"keywords": [],
1111
"author": "",

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)