-
-
Notifications
You must be signed in to change notification settings - Fork 389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core/linter-rules): added linter for checking charset is utf-8 #2075
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please remove builds/respec-w3c-common.js.map, as we only generate them when versioning.
@saschanaz updated the |
Those failing tests don't know about the new linter, maybe we can add one for each of them. |
@saschanaz I don't get why travis-ci isin't passing ... could you please help me out with this . |
Co-Authored-By: CodHeK <[email protected]>
Run |
@saschanaz made the changes you asked! |
const metas = doc.querySelectorAll("meta[charset]"); | ||
const val = []; | ||
for (let i = 0; i < metas.length; i++) { | ||
val.push(metas[i].outerHTML); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can push meta.getAttribute("charset")
instead? Then we can skip charset=
part in getCharset
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we prefer for-of loop: for (const meta of metas)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Why would there be multiple meta[charset]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sidvishnoi No reason, it would always be by accident.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sidvishnoi just considering a hypothetical case, cases wherein if someone just copied html from some other source, yet very rare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Author error maybe?
Oh, okay so should I change the variable name ?
|
Okay, so I’ll get rid of the regex and use getAttribute and check if utf-8 exists in the val array ?
|
That would work. |
@saschanaz what exactly should the linter return ( the object returned when utf8 is not present ) ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of little things.
src/core/defaults.js
Outdated
@@ -24,6 +26,7 @@ export const coreDefaults = { | |||
"check-punctuation": false, | |||
"local-refs-exist": true, | |||
"check-internal-slots": false, | |||
"check-charset": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially set this to false, so we can “beta test” it.
tests/spec/w3c/defaults-spec.js
Outdated
@@ -15,6 +15,7 @@ describe("W3C — Defaults", () => { | |||
"local-refs-exist": true, | |||
"check-punctuation": false, | |||
"check-internal-slots": false, | |||
"check-charset": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above. Set it to flase by default. We will enable it after we test it out a bit.
const utfExists = val.includes("utf-8"); | ||
|
||
//only a single meta[charset] and is set to utf-8, correct case | ||
if (utfExists === true && metas.length === 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (utfExists === true && metas.length === 1) { | |
if (utfExists && metas.length === 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be sure to revert changes to the .map file too!
Starting to look pretty good 👍
@marcoscaceres .map file ? |
tests/spec/w3c/defaults-spec.js
Outdated
@@ -51,6 +52,7 @@ describe("W3C — Defaults", () => { | |||
"check-punctuation": false, | |||
"fake-linter-rule": "foo", | |||
"check-internal-slots": true, | |||
"check-charset": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcoscaceres should this be set to true
? the karma test failed for this case ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one should be false, to match core/defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcoscaceres done, sent a PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please do git checkout develop builds/*
, this will restore builds/respec-w3c-common.js.map as the original state.
const meta = { | ||
en: { | ||
description: `Document must only contain one \`<meta>\` tag with charset set to 'utf-8'`, | ||
howToFix: `Add this line in your document \`<head>\` section - \`<meta charset="utf-8" />\` or set charset to "utf-8" if not set already.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
howToFix: `Add this line in your document \`<head>\` section - \`<meta charset="utf-8" />\` or set charset to "utf-8" if not set already.`, | |
howToFix: `Add this line in your document \`<head>\` section - \`<meta charset="utf-8" />\` or set charset to "utf-8" if not set already.`, |
* Runs linter rule. | ||
* | ||
* @param {Object} config The ReSpec config. | ||
* @param {Document} doc The document to be checked. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param {Document} doc The document to be checked. | |
* @param {Document} doc The document to be checked. |
/** | ||
* Runs linter rule. | ||
* | ||
* @param {Object} config The ReSpec config. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param {Object} config The ReSpec config. | |
* @param {Object} conf The ReSpec config. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the only thing left to do is remove the changes to builds/respec-w3c-common.js.map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM1. @saschanaz ?
@CodHeK, I'm still seeing a mode change on builds/respec-w3c-common.js.map? Make sure you revert all changes to that file. Hopefully this will fix it:
|
Waiting on builds/respec-w3c-common.js.map fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, looking good.
Closes #873