Skip to content

Commit

Permalink
Add option to only enforce jsx-closing-bracket-location rule to only …
Browse files Browse the repository at this point in the history
…one type of tag (fixes #307)
  • Loading branch information
yannickcr committed Nov 16, 2015
1 parent e4d6320 commit 4787aa0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
6 changes: 3 additions & 3 deletions docs/rules/jsx-closing-bracket-location.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ The first form is a string shortcut corresponding to the `location` values speci
"jsx-closing-bracket-location": [<enabled>, "<location>"]
```

The second form allows you to distinguish between non-empty and self-closing tags. Both properties are optional, and both default to `"tag-aligned"`.
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`.

```js
"jsx-closing-bracket-location": [<enabled>, {
"nonEmpty": "<location>",
"selfClosing": "<location>"
"nonEmpty": "<location>" || false,
"selfClosing": "<location>" || false
}]
```

Expand Down
10 changes: 5 additions & 5 deletions lib/rules/jsx-closing-bracket-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ module.exports = function(context) {
options.selfClosing = config;
} else if (typeof config === 'object') {
// [1, {location: 'something'}] (back-compat)
if (config.hasOwnProperty('location') && typeof config.location === 'string') {
if (config.hasOwnProperty('location')) {
options.nonEmpty = config.location;
options.selfClosing = config.location;
}
// [1, {nonEmpty: 'something'}]
if (config.hasOwnProperty('nonEmpty') && typeof config.nonEmpty === 'string') {
if (config.hasOwnProperty('nonEmpty')) {
options.nonEmpty = config.nonEmpty;
}
// [1, {selfClosing: 'something'}]
if (config.hasOwnProperty('selfClosing') && typeof config.selfClosing === 'string') {
if (config.hasOwnProperty('selfClosing')) {
options.selfClosing = config.selfClosing;
}
}
Expand Down Expand Up @@ -187,10 +187,10 @@ module.exports.schema = [{
type: 'object',
properties: {
nonEmpty: {
enum: ['after-props', 'props-aligned', 'tag-aligned', 'line-aligned']
enum: ['after-props', 'props-aligned', 'tag-aligned', 'line-aligned', false]
},
selfClosing: {
enum: ['after-props', 'props-aligned', 'tag-aligned', 'line-aligned']
enum: ['after-props', 'props-aligned', 'tag-aligned', 'line-aligned', false]
}
},
additionalProperties: false
Expand Down
32 changes: 32 additions & 0 deletions tests/lib/rules/jsx-closing-bracket-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,38 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
].join('\n'),
options: [{location: 'line-aligned'}],
ecmaFeatures: {jsx: true}
}, {
code: [
'<App>',
' <Foo',
' bar',
' >',
' </Foo>',
' <Foo',
' bar />',
'</App>'
].join('\n'),
options: [{
nonEmpty: false,
selfClosing: 'after-props'
}],
ecmaFeatures: {jsx: true}
}, {
code: [
'<App>',
' <Foo',
' bar>',
' </Foo>',
' <Foo',
' bar',
' />',
'</App>'
].join('\n'),
options: [{
nonEmpty: 'after-props',
selfClosing: false
}],
ecmaFeatures: {jsx: true}
}],

invalid: [{
Expand Down

0 comments on commit 4787aa0

Please sign in to comment.