Skip to content
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

Merged
merged 26 commits into from
Feb 7, 2019

Conversation

CodHeK
Copy link
Contributor

@CodHeK CodHeK commented Feb 6, 2019

Closes #873

Copy link
Collaborator

@saschanaz saschanaz left a 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.

src/w3c/defaults.js Outdated Show resolved Hide resolved
@CodHeK
Copy link
Contributor Author

CodHeK commented Feb 6, 2019

@saschanaz updated the src/core/default.js file

@CodHeK CodHeK changed the title added linter for checking charset is utf-8 feat(core/linter-rules): added linter for checking charset is utf-8 Feb 6, 2019
@saschanaz
Copy link
Collaborator

Those failing tests don't know about the new linter, maybe we can add one for each of them.

@CodHeK
Copy link
Contributor Author

CodHeK commented Feb 6, 2019

@saschanaz I don't get why travis-ci isin't passing ... could you please help me out with this .

tests/spec/w3c/defaults-spec.js Outdated Show resolved Hide resolved
@saschanaz
Copy link
Collaborator

Run npm run lint -- --fix and those errors will disappear.

src/core/linter-rules/check-charset.js Outdated Show resolved Hide resolved
src/core/linter-rules/check-charset.js Outdated Show resolved Hide resolved
src/core/linter-rules/check-charset.js Outdated Show resolved Hide resolved
src/core/linter-rules/check-charset.js Outdated Show resolved Hide resolved
tests/spec/core/linter-rules/check-charset-spec.js Outdated Show resolved Hide resolved
@CodHeK
Copy link
Contributor Author

CodHeK commented Feb 6, 2019

@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);
Copy link
Collaborator

@saschanaz saschanaz Feb 6, 2019

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.

Copy link
Collaborator

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)

Copy link
Member

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]?

Copy link
Collaborator

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.

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Author error maybe?

@CodHeK
Copy link
Contributor Author

CodHeK commented Feb 6, 2019 via email

@CodHeK
Copy link
Contributor Author

CodHeK commented Feb 6, 2019 via email

@saschanaz
Copy link
Collaborator

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.

@CodHeK
Copy link
Contributor Author

CodHeK commented Feb 6, 2019

@saschanaz what exactly should the linter return ( the object returned when utf8 is not present ) ?

src/core/linter-rules/check-charset.js Outdated Show resolved Hide resolved
src/core/linter-rules/check-charset.js Outdated Show resolved Hide resolved
Copy link
Contributor

@marcoscaceres marcoscaceres left a 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/linter-rules/check-charset.js Show resolved Hide resolved
@@ -24,6 +26,7 @@ export const coreDefaults = {
"check-punctuation": false,
"local-refs-exist": true,
"check-internal-slots": false,
"check-charset": true,
Copy link
Contributor

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.

@@ -15,6 +15,7 @@ describe("W3C — Defaults", () => {
"local-refs-exist": true,
"check-punctuation": false,
"check-internal-slots": false,
"check-charset": true,
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (utfExists === true && metas.length === 1) {
if (utfExists && metas.length === 1) {

Copy link
Contributor

@marcoscaceres marcoscaceres left a 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 👍

@CodHeK
Copy link
Contributor Author

CodHeK commented Feb 6, 2019

Be sure to revert changes to the .map file too!

Starting to look pretty good 👍

@marcoscaceres .map file ?

@@ -51,6 +52,7 @@ describe("W3C — Defaults", () => {
"check-punctuation": false,
"fake-linter-rule": "foo",
"check-internal-slots": true,
"check-charset": true,
Copy link
Contributor Author

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 ...

Copy link
Contributor

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.

Copy link
Contributor Author

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!

Copy link
Collaborator

@saschanaz saschanaz left a 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.`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param {Object} config The ReSpec config.
* @param {Object} conf The ReSpec config.

Copy link
Contributor

@marcoscaceres marcoscaceres left a 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

marcoscaceres
marcoscaceres previously approved these changes Feb 7, 2019
Copy link
Contributor

@marcoscaceres marcoscaceres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM1. @saschanaz ?

@marcoscaceres
Copy link
Contributor

@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:

git pull
git checkout develop builds/respec-w3c-common.js.map
git commit -b "revert changes" builds/respec-w3c-common.js.map

@marcoscaceres marcoscaceres dismissed their stale review February 7, 2019 07:03

Waiting on builds/respec-w3c-common.js.map fix

Copy link
Contributor

@marcoscaceres marcoscaceres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, looking good.

@marcoscaceres marcoscaceres merged commit bd99374 into speced:develop Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants