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

Add validateValues option to require-lang-attribute rule #2478

Conversation

judithhinlung
Copy link
Collaborator

This PR fixes #2477.

Background

Currently, the require-lang-attribute rule checks for the presence of the lang attribute but not whether its value is valid. This issue proposes updating the rule so that, if the lang attribute contains a text value, check that its value is a known IETF's BCP 47 language tag. When this attribute is properly assigned, both assistive technologies and conventional user agents will be able to render text more accurately.

Reference: lang - HTML: HyperText Markup Language - MDN Web Docs

Allowed:

# examples
<html lang="en"></html>
<html lang="en-US"></html>
<html lang={{lang}}></html>

Forbidden:

# examples
<html></html>
<html lang=""></html>
<html lang="abracadabra"></Html>

Testing

Test Suites: 136 passed, 136 total
Tests: 5 skipped, 7478 passed, 7483 total
Snapshots: 981 passed, 981 total
Time: 95.504 s
Ran all test suites.
✨ Done in 101.16s.

@judithhinlung judithhinlung marked this pull request as draft April 19, 2022 18:25
@bmish
Copy link
Member

bmish commented Apr 19, 2022

It looks like this is a breaking change right now? If so, we would want to hide this behavior behind an option requireValidValue (default false), and then wait until the next major release (#2319) to enable it by default.

@judithhinlung judithhinlung marked this pull request as ready for review April 20, 2022 21:30
@bmish bmish mentioned this pull request Apr 21, 2022
@bmish bmish changed the title Update require-lang-attribute rule to validate attribute values Add validateValues option to require-lang-attribute rule Apr 21, 2022
],
});

generateRuleTests({
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I think we probably want to avoid having an additional generateRuleTests call. Instead, we should pass config to specific test cases.

@@ -29,7 +29,7 @@ This rule **forbids** the following:
```

```hbs
<html lang=""></html>
<html lang=''></html>
Copy link
Member

Choose a reason for hiding this comment

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

Usually we use double quotes in HTML, so probably avoid changing this?

## Configuration

- boolean -- if `true`, default configuration is applied
(`validateValues: false`), see below for details
Copy link
Member

Choose a reason for hiding this comment

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

Let's avoid repeating the default value here.

Suggested change
(`validateValues: false`), see below for details


- object -- containing the following property:
- boolean -- `validateValues` -- if `true`, the rule checks whether the value in the `lang` attribute is a known IETF's BCP 47 language tag
(default: `false`)
Copy link
Member

Choose a reason for hiding this comment

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

We could indicate here that we should enable this by default in the next major release as a reminder:

Suggested change
(default: `false`)
(default: `false`) (TODO: enable by default in next major release)

@@ -50,3 +52,76 @@ generateRuleTests({
},
],
});

generateRuleTests({
Copy link
Member

Choose a reason for hiding this comment

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

Note that we want to test validateValues being explicitly true, explicitly false, and the default behavior when it's not specified at all. And we want to make it clear when we're testing each of these and make sure so that it will be easy to update the test cases when we change the default value to true in the next major release.

good: [
'<html lang="en"></html>',
'<html lang="en-US"></html>',
'<html lang={{lang}}></html>',
Copy link
Member

@bmish bmish Apr 22, 2022

Choose a reason for hiding this comment

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

We need to make sure we have a test for the default behavior of allowing invalid values when an option isn't specified.

Suggested change
'<html lang={{lang}}></html>',
'<html lang={{lang}}></html>',
'<html lang="hurrah"></html>' // allows invalid value when `validateValues` option defaults to `false`

Copy link
Member

@bmish bmish left a comment

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal to update require-lang-attribute rule with value validation
2 participants