Skip to content

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 2 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"msapplication",
"nocolor",
"nodir",
"noembed",
"nomix",
"noopener",
"npmjs",
Expand Down
6 changes: 4 additions & 2 deletions dist/core/rules/index.js

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

1 change: 1 addition & 0 deletions src/core/rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export { default as spaceTabMixedDisabled } from './space-tab-mixed-disabled'
export { default as specCharEscape } from './spec-char-escape'
export { default as srcNotEmpty } from './src-not-empty'
export { default as styleDisabled } from './style-disabled'
export { default as tagNoObsolete } from './tag-no-obsolete'
export { default as tagnameLowercase } from './tagname-lowercase'
export { default as tagnameSpecialChars } from './tagname-specialchars'
export { default as tagPair } from './tag-pair'
Expand Down
53 changes: 53 additions & 0 deletions src/core/rules/tag-no-obsolete.ts
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
1 change: 1 addition & 0 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface Ruleset {
'spec-char-escape'?: boolean
'src-not-empty'?: boolean
'style-disabled'?: boolean
'tag-no-obsolete'?: boolean
'tag-pair'?: boolean
'tag-self-close'?: boolean
'tagname-lowercase'?: boolean
Expand Down
36 changes: 36 additions & 0 deletions test/rules/tag-no-obsolete.spec.js
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))
})
})
1 change: 1 addition & 0 deletions website/src/content/docs/rules/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ description: A complete list of all the rules for HTMLHint
- [`href-abs-or-rel`](href-abs-or-rel/): An href attribute must be either absolute or relative.
- [`main-require`](main-require/): A document must have at least one `<main>` element in the `<body>` tag.
- [`src-not-empty`](src-not-empty/): The src attribute of an img(script,link) must have a value.
{/* - [`tag-no-obsolete`](tag-no-obsolete/): Disallows the use of obsolete HTML5 tags. */}
- [`tag-pair`](tag-pair/): Tag must be paired.
- [`tag-self-close`](tag-self-close/): Empty tags must be self closed.
- [`tagname-lowercase`](tagname-lowercase/): All HTML element names must be in lowercase.
Expand Down
46 changes: 46 additions & 0 deletions website/src/content/docs/rules/tag-no-obsolete.mdx
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>
```