-
-
Notifications
You must be signed in to change notification settings - Fork 406
feat: New rule: tag-no-obsolete
#1660
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
"msapplication", | ||
"nocolor", | ||
"nodir", | ||
"noembed", | ||
"nomix", | ||
"noopener", | ||
"npmjs", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Rule } from '../types' | ||
|
||
// List of obsolete HTML5 tags | ||
const OBSOLETE_TAGS = [ | ||
'applet', | ||
'acronym', | ||
'bgsound', | ||
'dir', | ||
'frame', | ||
'frameset', | ||
'noframes', | ||
'isindex', | ||
'keygen', | ||
'listing', | ||
'menuitem', | ||
'nextid', | ||
'noembed', | ||
'plaintext', | ||
'rb', | ||
'rtc', | ||
'strike', | ||
'xmp', | ||
'basefont', | ||
'big', | ||
'blink', | ||
'center', | ||
'font', | ||
'marquee', | ||
'multicol', | ||
'nobr', | ||
'spacer', | ||
'tt', | ||
] | ||
|
||
export default { | ||
id: 'tag-no-obsolete', | ||
description: 'Disallows the use of obsolete HTML5 tags.', | ||
init(parser, reporter, _options) { | ||
parser.addListener('tagstart,tagend', (event) => { | ||
const tagName = event.tagName.toLowerCase() | ||
|
||
if (OBSOLETE_TAGS.includes(tagName)) { | ||
reporter.error( | ||
`The tag [ ${event.tagName} ] is obsolete in HTML5 and should not be used.`, | ||
event.line, | ||
event.col, | ||
this, | ||
event.raw | ||
) | ||
} | ||
}) | ||
}, | ||
} as Rule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const HTMLHint = require('../../dist/htmlhint.js').HTMLHint | ||
|
||
const ruleId = 'tag-no-obsolete' | ||
const ruleOptions = {} | ||
|
||
ruleOptions[ruleId] = true | ||
|
||
describe(`Rules: ${ruleId}`, () => { | ||
it('Obsolete HTML5 tags should result in an error', () => { | ||
const code = | ||
'<center>Centered text</center><font color="red">Red text</font><marquee>Scrolling text</marquee>' | ||
const messages = HTMLHint.verify(code, ruleOptions) | ||
expect(messages.length).toBe(6) // 3 opening tags + 3 closing tags | ||
messages.forEach((msg) => expect(msg.rule.id).toBe(ruleId)) | ||
}) | ||
|
||
it('Non-obsolete HTML5 tags should not result in an error', () => { | ||
const code = '<div>Content</div><span>Text</span><p>Paragraph</p>' | ||
const messages = HTMLHint.verify(code, ruleOptions) | ||
expect(messages.length).toBe(0) | ||
}) | ||
|
||
it('Mixed case obsolete tags should still be detected', () => { | ||
const code = '<CENTER>Centered</CENTER><Font>Styled</Font>' | ||
const messages = HTMLHint.verify(code, ruleOptions) | ||
expect(messages.length).toBe(4) // 2 opening tags + 2 closing tags | ||
messages.forEach((msg) => expect(msg.rule.id).toBe(ruleId)) | ||
}) | ||
|
||
it('Self-closing obsolete tags should be detected', () => { | ||
const code = '<br><hr><img src="test.jpg"><spacer>' | ||
const messages = HTMLHint.verify(code, ruleOptions) | ||
expect(messages.length).toBe(1) // Only spacer is obsolete | ||
messages.forEach((msg) => expect(msg.rule.id).toBe(ruleId)) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
id: tag-no-obsolete | ||
title: tag-no-obsolete | ||
description: Disallows the use of obsolete HTML5 tags that are no longer supported in modern browsers. | ||
sidebar: | ||
badge: New | ||
hidden: true | ||
--- | ||
|
||
import { Badge } from '@astrojs/starlight/components'; | ||
|
||
Disallows the use of obsolete HTML5 tags. | ||
|
||
Level: <Badge text="Error" variant="danger" /> | ||
|
||
## Config value | ||
|
||
- `true`: enable rule | ||
- `false`: disable rule | ||
|
||
## Description | ||
|
||
This rule prevents the use of HTML tags that have been deprecated and are considered obsolete in HTML5. These tags are no longer supported by modern browsers and should be replaced with appropriate alternatives. | ||
|
||
### Obsolete tags include: | ||
|
||
- `applet`, `acronym`, `bgsound`, `dir`, `frame`, `frameset`, `noframes` | ||
- `isindex`, `keygen`, `listing`, `menuitem`, `nextid`, `noembed` | ||
- `plaintext`, `rb`, `rtc`, `strike`, `xmp`, `basefont`, `big` | ||
- `blink`, `center`, `font`, `marquee`, `multicol`, `nobr`, `spacer`, `tt` | ||
|
||
### The following patterns are **not** considered rule violations | ||
|
||
```html | ||
<div>Content</div> | ||
<span>Text</span> | ||
<p>Paragraph</p> | ||
``` | ||
|
||
### The following patterns are considered rule violations: | ||
|
||
```html | ||
<center>Centered text</center> | ||
<font color="red">Red text</font> | ||
<marquee>Scrolling text</marquee> | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.