Skip to content

Commit 4c94f32

Browse files
committed
Update self-closing-comp to check html tags by default
1 parent e84af68 commit 4c94f32

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

docs/rules/self-closing-comp.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ var Profile = <Hello name="John"><img src="picture.png" /></Hello>;
2222

2323
## Rule Options
2424

25-
The rule can take one argument to select types of tags, which should be self-closed when this is possible. By default only custom components tags should be self-closed.
25+
The rule can take one argument to select types of tags, which should be self-closed when this is possible. By default custom components tags and html tags should be self-closed.
2626

2727
```js
2828
...
2929
"self-closing-comp": ["error", {
3030
"component": true,
31-
"html": false
31+
"html": true
3232
}]
3333
...
3434
```

lib/rules/self-closing-comp.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = {
2424
type: 'boolean'
2525
},
2626
html: {
27-
default: false,
27+
default: true,
2828
type: 'boolean'
2929
}
3030
},
@@ -55,7 +55,7 @@ module.exports = {
5555
}
5656

5757
function isShouldBeSelfClosed(node) {
58-
var configuration = context.options[0] || {component: true};
58+
var configuration = context.options[0] || {component: true, html: true};
5959
return (
6060
configuration.component && isComponent(node) ||
6161
configuration.html && isTagName(node.name.name)

tests/lib/rules/self-closing-comp.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ ruleTester.run('self-closing-comp', rule, {
2727

2828
valid: [
2929
{
30-
code: 'var contentContainer = <div className="content"></div>;',
31-
parserOptions: parserOptions
32-
}, {
3330
code: 'var HelloJohn = <Hello name="John" />;',
3431
parserOptions: parserOptions
3532
}, {
@@ -50,10 +47,6 @@ ruleTester.run('self-closing-comp', rule, {
5047
}, {
5148
code: 'var HelloJohn = <Hello name="John">&nbsp;</Hello>;',
5249
parserOptions: parserOptions
53-
}, {
54-
code: 'var contentContainer = <div className="content"></div>;',
55-
options: [],
56-
parserOptions: parserOptions
5750
}, {
5851
code: 'var HelloJohn = <Hello name="John" />;',
5952
options: [],
@@ -113,6 +106,19 @@ ruleTester.run('self-closing-comp', rule, {
113106

114107
invalid: [
115108
{
109+
code: 'var contentContainer = <div className="content"></div>;',
110+
parserOptions: parserOptions,
111+
errors: [{
112+
message: 'Empty components are self-closing'
113+
}]
114+
}, {
115+
code: 'var contentContainer = <div className="content"></div>;',
116+
options: [],
117+
parserOptions: parserOptions,
118+
errors: [{
119+
message: 'Empty components are self-closing'
120+
}]
121+
}, {
116122
code: 'var HelloJohn = <Hello name="John"></Hello>;',
117123
parserOptions: parserOptions,
118124
errors: [{

0 commit comments

Comments
 (0)