Skip to content

Commit 440f593

Browse files
bebehrcoliff
andauthored
fix(spec-char-escape): remove ampersand from spec-char-escape (#1504)
Ampersand is acceptable in HTML text, e. g. see: W3C validator fix #1382 Co-authored-by: Christian Oliff <[email protected]>
1 parent 568071d commit 440f593

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

docs/user-guide/rules/spec-char-escape.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ Level: `error`
1212
1. true: enable rule
1313
2. false: disable rule
1414

15-
The following pattern are **not** considered violations:
15+
The following patterns are **not** considered violations:
1616

1717
<!-- prettier-ignore -->
1818
```html
1919
<span>aaa&gt;bbb&lt;ccc</span>
20+
<span>Steinway &amp; Sons, Q&amp;A</span>
21+
<span>Steinway & Sons, Q&A</span>
2022
```
2123

2224
The following pattern is considered violation:

src/core/rules/spec-char-escape.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ export default {
66
init(parser, reporter) {
77
parser.addListener('text', (event) => {
88
const raw = event.raw
9-
// TODO: improve use-cases for &
10-
const reSpecChar = /([<>])|( \& )/g
9+
const reSpecChar = /([<>])/g
1110
let match
1211

1312
while ((match = reSpecChar.exec(raw))) {

test/rules/spec-char-escape.spec.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@ describe(`Rules: ${ruleId}`, () => {
2121
expect(messages[2].col).toBe(4)
2222
})
2323

24-
it('Special characters: & should result in an error', () => {
25-
const code = '<p>Steinway & Sons</p>'
24+
it('Special characters: normal & should not result in an error', () => {
25+
const code = '<p>Steinway & Sons Q&A</p>'
2626
const messages = HTMLHint.verify(code, ruleOptions)
27-
expect(messages.length).toBe(1)
28-
expect(messages[0].rule.id).toBe(ruleId)
29-
expect(messages[0].line).toBe(1)
30-
expect(messages[0].col).toBe(12)
27+
expect(messages.length).toBe(0)
3128
})
3229

3330
it('Normal text should not result in an error', () => {

0 commit comments

Comments
 (0)