Skip to content

Commit d42d1e5

Browse files
author
Ethan Cohen
committed
[fix] - heading-has-content: dangerouslySetInnerHTML should pass
Fixes #64
1 parent efeeb6d commit d42d1e5

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

docs/rules/heading-has-content.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function Foo(props) {
4949
```jsx
5050
<h1>Heading Content!</h1>
5151
<h1><TextWrapper /><h1>
52+
<h1 dangerouslySetInnerHTML={{ __html: 'foo' }} />
5253
```
5354

5455
### Fail

src/rules/heading-has-content.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Rule Definition
88
// ----------------------------------------------------------------------------
99

10-
import { elementType } from 'jsx-ast-utils';
10+
import { elementType, hasProp } from 'jsx-ast-utils';
1111
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader';
1212

1313
const errorMessage =
@@ -49,7 +49,8 @@ module.exports = context => ({
4949
default:
5050
return false;
5151
}
52-
});
52+
}) || hasProp(node.attributes, 'dangerouslySetInnerHTML');
53+
5354

5455
if (isAccessible) {
5556
return;

tests/src/rules/heading-has-content.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ruleTester.run('heading-has-content', rule, {
4141
{ code: '<h1><Bar /></h1>', parserOptions },
4242
{ code: '<h1>{foo}</h1>', parserOptions },
4343
{ code: '<h1>{foo.bar}</h1>', parserOptions },
44+
{ code: '<h1 dangerouslySetInnerHTML={{ __html: "foo" }} />', parserOptions },
4445
],
4546
invalid: [
4647
{ code: '<h1 />', errors: [expectedError], parserOptions },

0 commit comments

Comments
 (0)