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

js-a11y/lang not recognizing script subtag #669

Closed
imtsuki opened this issue Mar 10, 2020 · 2 comments
Closed

js-a11y/lang not recognizing script subtag #669

imtsuki opened this issue Mar 10, 2020 · 2 comments
Assignees

Comments

@imtsuki
Copy link
Contributor

imtsuki commented Mar 10, 2020

According to the documentation for lang attribute on MDN, a valid HTML lang attribute is composed of three parts:

language-[script]-[region]

where the script subtag defines the writing system used for the language, and is always 4 characters long, with the first letter capitalized. This subtag is particularly useful as there are two different writing systems in Chinese: simplified (Hans) and traditional (Hant).

For example, I can have each of the following valid lang attributes:

  • zh-CN
  • zh-Hant
  • zh-Hans-CN

But now the js-a11y/lang rule is rejecting the last two.

Reference:

@imtsuki
Copy link
Contributor Author

imtsuki commented Mar 10, 2020

I did some investigation. There are actually three languages defined here:

https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/7bcea2006f1d79b399e4aaec82e9cbbbe6ef8cc4/src/util/attributes/ISO.json#L262-L264

But the indexOf('-') here accidentally breaks the last two pairs, which causes the problem:

https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/7bcea2006f1d79b399e4aaec82e9cbbbe6ef8cc4/src/rules/lang.js#L54-L56

@ljharb
Copy link
Member

ljharb commented Mar 10, 2020

ah, maybe it should be lastIndexOf? or something more precise :-) want to make a PR?

jessebeach added a commit that referenced this issue Jun 15, 2020
Fixes #669: use the `language-tags` package to check the `lang` rule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants