Skip to content

Commit

Permalink
Fix the behavior of the boolean "attributes"
Browse files Browse the repository at this point in the history
  • Loading branch information
fatfisz committed Jun 11, 2017
1 parent 7b9d9ad commit 65135b8
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/rules/jsx-curly-spacing.js
Expand Up @@ -239,11 +239,23 @@ module.exports = {
* @returns {void}
*/
function validateBraceSpacing(node) {
// Only validate attributes
if (node.parent.type === 'JSXElement') {
var config;
switch (node.parent.type) {
case 'JSXAttribute':
case 'JSXOpeningElement':
config = attributesConfig;
break;

case 'JSXElement':
return;

default:
return;
}
if (config === null) {
return;
}
var config = attributesConfig;

var first = context.getFirstToken(node);
var last = sourceCode.getLastToken(node);
var second = context.getTokenAfter(first, {includeComments: true});
Expand Down
130 changes: 130 additions & 0 deletions tests/lib/rules/jsx-curly-spacing.js
Expand Up @@ -42,6 +42,38 @@ ruleTester.run('jsx-curly-spacing', rule, {
].join('\n')
}, {
code: '<App foo={{ bar: true, baz: true }} />;'
}, {
code: '<App foo={bar} />;',
options: [{attributes: true}]
}, {
code: [
'<App foo={',
'bar',
'} />;'
].join('\n'),
options: [{attributes: true}]
}, {
code: '<App foo={{ bar: true, baz: true }} />;',
options: [{attributes: true}]
}, {
code: '<App foo={bar} />;',
options: [{attributes: false}]
}, {
code: [
'<App foo={',
'bar',
'} />;'
].join('\n'),
options: [{attributes: false}]
}, {
code: '<App foo={{ bar: true, baz: true }} />;',
options: [{attributes: false}]
}, {
code: '<App foo={ bar } />;',
options: [{attributes: false}]
}, {
code: '<App foo={ { bar: true, baz: true } } />;',
options: [{attributes: false}]
}, {
code: '<App foo={bar} />;',
options: [{when: 'never'}]
Expand Down Expand Up @@ -281,6 +313,24 @@ ruleTester.run('jsx-curly-spacing', rule, {
}, {
message: 'There should be no space before \'}\''
}]
}, {
code: '<App foo={ bar } />;',
output: '<App foo={bar} />;',
options: [{attributes: true}],
errors: [{
message: 'There should be no space after \'{\''
}, {
message: 'There should be no space before \'}\''
}]
}, {
code: '<App foo={ { bar: true, baz: true } } />;',
output: '<App foo={{ bar: true, baz: true }} />;',
options: [{attributes: true}],
errors: [{
message: 'There should be no space after \'{\''
}, {
message: 'There should be no space before \'}\''
}]
}, {
code: '<App foo={ bar } />;',
output: '<App foo={bar} />;',
Expand Down Expand Up @@ -413,6 +463,86 @@ ruleTester.run('jsx-curly-spacing', rule, {
}, {
message: 'A space is required before \'}\''
}]
}, {
code: '<App foo={ bar } />;',
output: '<App foo={bar} />;',
options: [{attributes: true, when: 'never'}],
errors: [{
message: 'There should be no space after \'{\''
}, {
message: 'There should be no space before \'}\''
}]
}, {
code: [
'<App foo={',
'bar',
'} />;'
].join('\n'),
output: '<App foo={bar} />;',
options: [{attributes: true, when: 'never', allowMultiline: false}],
errors: [{
message: 'There should be no newline after \'{\''
}, {
message: 'There should be no newline before \'}\''
}]
}, {
code: '<App foo={ { bar: true, baz: true } } />;',
output: '<App foo={{ bar: true, baz: true }} />;',
options: [{attributes: true, when: 'never', spacing: {objectLiterals: 'never'}}],
errors: [{
message: 'There should be no space after \'{\''
}, {
message: 'There should be no space before \'}\''
}]
}, {
code: '<App foo={{ bar: true, baz: true }} />;',
output: '<App foo={ { bar: true, baz: true } } />;',
options: [{attributes: true, when: 'never', spacing: {objectLiterals: 'always'}}],
errors: [{
message: 'A space is required after \'{\''
}, {
message: 'A space is required before \'}\''
}]
}, {
code: '<App foo={bar} />;',
output: '<App foo={ bar } />;',
options: [{attributes: true, when: 'always'}],
errors: [{
message: 'A space is required after \'{\''
}, {
message: 'A space is required before \'}\''
}]
}, {
code: [
'<App foo={',
'bar',
'} />;'
].join('\n'),
output: '<App foo={ bar } />;',
options: [{attributes: true, when: 'always', allowMultiline: false}],
errors: [{
message: 'There should be no newline after \'{\''
}, {
message: 'There should be no newline before \'}\''
}]
}, {
code: '<App foo={ { bar: true, baz: true } } />;',
output: '<App foo={{ bar: true, baz: true }} />;',
options: [{attributes: true, when: 'always', spacing: {objectLiterals: 'never'}}],
errors: [{
message: 'There should be no space after \'{\''
}, {
message: 'There should be no space before \'}\''
}]
}, {
code: '<App foo={{ bar: true, baz: true }} />;',
output: '<App foo={ { bar: true, baz: true } } />;',
options: [{attributes: true, when: 'always', spacing: {objectLiterals: 'always'}}],
errors: [{
message: 'A space is required after \'{\''
}, {
message: 'A space is required before \'}\''
}]
}, {
code: '<App foo={ bar } />;',
output: '<App foo={bar} />;',
Expand Down

0 comments on commit 65135b8

Please sign in to comment.