Skip to content

Commit 4787aa0

Browse files
committed
Add option to only enforce jsx-closing-bracket-location rule to only one type of tag (fixes #307)
1 parent e4d6320 commit 4787aa0

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

docs/rules/jsx-closing-bracket-location.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ The first form is a string shortcut corresponding to the `location` values speci
4141
"jsx-closing-bracket-location": [<enabled>, "<location>"]
4242
```
4343

44-
The second form allows you to distinguish between non-empty and self-closing tags. Both properties are optional, and both default to `"tag-aligned"`.
44+
The second form allows you to distinguish between non-empty and self-closing tags. Both properties are optional, and both default to `"tag-aligned"`. You can also disable the rule for one particular type of tag by setting the value to `false`.
4545

4646
```js
4747
"jsx-closing-bracket-location": [<enabled>, {
48-
"nonEmpty": "<location>",
49-
"selfClosing": "<location>"
48+
"nonEmpty": "<location>" || false,
49+
"selfClosing": "<location>" || false
5050
}]
5151
```
5252

lib/rules/jsx-closing-bracket-location.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ module.exports = function(context) {
3131
options.selfClosing = config;
3232
} else if (typeof config === 'object') {
3333
// [1, {location: 'something'}] (back-compat)
34-
if (config.hasOwnProperty('location') && typeof config.location === 'string') {
34+
if (config.hasOwnProperty('location')) {
3535
options.nonEmpty = config.location;
3636
options.selfClosing = config.location;
3737
}
3838
// [1, {nonEmpty: 'something'}]
39-
if (config.hasOwnProperty('nonEmpty') && typeof config.nonEmpty === 'string') {
39+
if (config.hasOwnProperty('nonEmpty')) {
4040
options.nonEmpty = config.nonEmpty;
4141
}
4242
// [1, {selfClosing: 'something'}]
43-
if (config.hasOwnProperty('selfClosing') && typeof config.selfClosing === 'string') {
43+
if (config.hasOwnProperty('selfClosing')) {
4444
options.selfClosing = config.selfClosing;
4545
}
4646
}
@@ -187,10 +187,10 @@ module.exports.schema = [{
187187
type: 'object',
188188
properties: {
189189
nonEmpty: {
190-
enum: ['after-props', 'props-aligned', 'tag-aligned', 'line-aligned']
190+
enum: ['after-props', 'props-aligned', 'tag-aligned', 'line-aligned', false]
191191
},
192192
selfClosing: {
193-
enum: ['after-props', 'props-aligned', 'tag-aligned', 'line-aligned']
193+
enum: ['after-props', 'props-aligned', 'tag-aligned', 'line-aligned', false]
194194
}
195195
},
196196
additionalProperties: false

tests/lib/rules/jsx-closing-bracket-location.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,38 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
312312
].join('\n'),
313313
options: [{location: 'line-aligned'}],
314314
ecmaFeatures: {jsx: true}
315+
}, {
316+
code: [
317+
'<App>',
318+
' <Foo',
319+
' bar',
320+
' >',
321+
' </Foo>',
322+
' <Foo',
323+
' bar />',
324+
'</App>'
325+
].join('\n'),
326+
options: [{
327+
nonEmpty: false,
328+
selfClosing: 'after-props'
329+
}],
330+
ecmaFeatures: {jsx: true}
331+
}, {
332+
code: [
333+
'<App>',
334+
' <Foo',
335+
' bar>',
336+
' </Foo>',
337+
' <Foo',
338+
' bar',
339+
' />',
340+
'</App>'
341+
].join('\n'),
342+
options: [{
343+
nonEmpty: 'after-props',
344+
selfClosing: false
345+
}],
346+
ecmaFeatures: {jsx: true}
315347
}],
316348

317349
invalid: [{

0 commit comments

Comments
 (0)