Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: htmlhint/HTMLHint
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.15.0
Choose a base ref
...
head repository: htmlhint/HTMLHint
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.15.1
Choose a head ref
  • 2 commits
  • 5 files changed
  • 2 contributors

Commits on Jun 11, 2021

  1. fix: Unexpected behavior of the html lang require rule (#655)

    * fix(rules): html-lang-require rule should be applied only for HTML tag
    
    * fix(rules): html-lang-require rule show false result in valid cases because of reusing of the RegExp object which keeps the state after previous check
    baleyko authored Jun 11, 2021

    Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    068645e View commit details
  2. chore(release): 0.15.1 [skip ci]

    ## [0.15.1](v0.15.0...v0.15.1) (2021-06-11)
    
    ### Bug Fixes
    
    * Unexpected behavior of the html lang require rule ([#655](#655)) ([068645e](068645e))
    semantic-release-bot committed Jun 11, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2cd48bd View commit details
Showing with 42 additions and 23 deletions.
  1. +7 −0 CHANGELOG.md
  2. +1 −1 package-lock.json
  3. +1 −1 package.json
  4. +22 −20 src/core/rules/html-lang-require.ts
  5. +11 −1 test/rules/html-lang-require.spec.js
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [0.15.1](https://github.com/htmlhint/HTMLHint/compare/v0.15.0...v0.15.1) (2021-06-11)


### Bug Fixes

* Unexpected behavior of the html lang require rule ([#655](https://github.com/htmlhint/HTMLHint/issues/655)) ([068645e](https://github.com/htmlhint/HTMLHint/commit/068645e9111f42adfa0fae0e32e236d88052541c))

# [0.15.0](https://github.com/htmlhint/HTMLHint/compare/v0.14.2...v0.15.0) (2021-06-10)


2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "htmlhint",
"version": "0.15.0",
"version": "0.15.1",
"description": "The Static Code Analysis Tool for your HTML",
"repository": {
"type": "git",
42 changes: 22 additions & 20 deletions src/core/rules/html-lang-require.ts
Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@ const langtag =
`(-${privateUse})?` +
')'
const languageTag = `(${grandfathered}|${langtag}|${privateUse2})`
const LANG_VALIDITY_PATTERN = new RegExp(languageTag, 'g')

export default {
id: 'html-lang-require',
@@ -33,33 +32,36 @@ export default {
const tagName = event.tagName.toLowerCase()
const mapAttrs = parser.getMapAttrs(event.attrs)
const col = event.col + tagName.length + 1
const langValidityPattern = new RegExp(languageTag, 'g')

if (tagName === 'html' && 'lang' in mapAttrs) {
if (!mapAttrs['lang']) {
if (tagName === 'html') {
if ('lang' in mapAttrs) {
if (!mapAttrs['lang']) {
reporter.warn(
'The lang attribute of <html> element must have a value.',
event.line,
col,
this,
event.raw
)
} else if (!langValidityPattern.test(mapAttrs['lang'])) {
reporter.warn(
'The lang attribute value of <html> element must be a valid BCP47.',
event.line,
col,
this,
event.raw
)
}
} else {
reporter.warn(
'The lang attribute of <html> element must have a value.',
event.line,
col,
this,
event.raw
)
} else if (!LANG_VALIDITY_PATTERN.test(mapAttrs['lang'])) {
reporter.warn(
'The lang attribute value of <html> element must be a valid BCP47.',
'An lang attribute must be present on <html> elements.',
event.line,
col,
this,
event.raw
)
}
} else {
reporter.warn(
'An lang attribute must be present on <html> elements.',
event.line,
col,
this,
event.raw
)
}
})
},
12 changes: 11 additions & 1 deletion test/rules/html-lang-require.spec.js
Original file line number Diff line number Diff line change
@@ -8,6 +8,11 @@ const ruleOptions = {}
ruleOptions[ruldId] = true

describe(`Rules: ${ruldId}`, () => {
it('All the rest(non HTML) tags should not result in an error', () => {
const code = '<html lang="en-EN"><body><p></p></body></html>'
const messages = HTMLHint.verify(code, ruleOptions)
expect(messages.length).to.be(0)
})
it('HTML tag have no a lang attribute should result in an error', () => {
const code = '<html></html>'
const messages = HTMLHint.verify(code, ruleOptions)
@@ -23,9 +28,14 @@ describe(`Rules: ${ruldId}`, () => {
const messages = HTMLHint.verify(code, ruleOptions)
expect(messages.length).to.be(1)
})
it('HTML tag have an non emtpy and valid lang attribute should not result in an error', () => {
it('HTML tag have an non emtpy and valid(en-EN) lang attribute should not result in an error', () => {
const code = '<html lang="en-EN"></html>'
const messages = HTMLHint.verify(code, ruleOptions)
expect(messages.length).to.be(0)
})
it('HTML tag have an non emtpy and valid(en) lang attribute should not result in an error', () => {
const code = '<html lang="en"></html>'
const messages = HTMLHint.verify(code, ruleOptions)
expect(messages.length).to.be(0)
})
})