diff --git a/lib/rules/jsx-curly-spacing.js b/lib/rules/jsx-curly-spacing.js index 7f324824d3..bdf397450c 100644 --- a/lib/rules/jsx-curly-spacing.js +++ b/lib/rules/jsx-curly-spacing.js @@ -36,7 +36,7 @@ module.exports = { basicConfig: { type: 'object', properties: { - spaces: { + when: { enum: SPACING_VALUES }, allowMultiline: { @@ -78,30 +78,30 @@ module.exports = { function normalizeConfig(configOrTrue, defaults, lastPass) { var config = configOrTrue === true ? {} : configOrTrue; - var spaces = config.spaces || defaults.spaces; + var when = config.when || defaults.when; var allowMultiline = has(config, 'allowMultiline') ? config.allowMultiline : defaults.allowMultiline; var spacing = config.spacing || {}; var objectLiteralSpaces = spacing.objectLiterals || defaults.objectLiteralSpaces; if (lastPass) { // On the final pass assign the values that should be derived from others if they are still undefined - objectLiteralSpaces = objectLiteralSpaces || spaces; + objectLiteralSpaces = objectLiteralSpaces || when; } return { - spaces, + when, allowMultiline, objectLiteralSpaces }; } - var DEFAULT_SPACING = SPACING.never; + var DEFAULT_WHEN = SPACING.never; var DEFAULT_ALLOW_MULTILINE = true; var DEFAULT_ATTRIBUTES = true; var sourceCode = context.getSourceCode(); var originalConfig = context.options[0] || {}; var defaultConfig = normalizeConfig(originalConfig, { - spaces: DEFAULT_SPACING, + when: DEFAULT_WHEN, allowMultiline: DEFAULT_ALLOW_MULTILINE }); var attributes = has(originalConfig, 'attributes') ? originalConfig.attributes : DEFAULT_ATTRIBUTES; @@ -261,7 +261,7 @@ module.exports = { } var isObjectLiteral = first.value === second.value; - var spacing = isObjectLiteral ? config.objectLiteralSpaces : config.spaces; + var spacing = isObjectLiteral ? config.objectLiteralSpaces : config.when; if (spacing === SPACING.always) { if (!sourceCode.isSpaceBetweenTokens(first, second)) { reportRequiredBeginningSpace(node, first); diff --git a/tests/lib/rules/jsx-curly-spacing.js b/tests/lib/rules/jsx-curly-spacing.js index c26af8e3be..904ef625d0 100644 --- a/tests/lib/rules/jsx-curly-spacing.js +++ b/tests/lib/rules/jsx-curly-spacing.js @@ -44,207 +44,207 @@ ruleTester.run('jsx-curly-spacing', rule, { code: ';' }, { code: ';', - options: [{spaces: 'never'}] + options: [{when: 'never'}] }, { code: [ ';' ].join('\n'), - options: [{spaces: 'never', spacing: {objectLiterals: 'never'}}] + options: [{when: 'never', spacing: {objectLiterals: 'never'}}] }, { code: ';', - options: [{spaces: 'never', allowMultiline: false}] + options: [{when: 'never', allowMultiline: false}] }, { code: ';', - options: [{spaces: 'never', allowMultiline: true}] + options: [{when: 'never', allowMultiline: true}] }, { code: [ ';' ].join('\n'), - options: [{spaces: 'never', allowMultiline: true}] + options: [{when: 'never', allowMultiline: true}] }, { code: ';', - options: [{spaces: 'never', spacing: {objectLiterals: 'never'}}] + options: [{when: 'never', spacing: {objectLiterals: 'never'}}] }, { code: ';', - options: [{spaces: 'always'}] + options: [{when: 'always'}] }, { code: ';', - options: [{spaces: 'always', allowMultiline: false}] + options: [{when: 'always', allowMultiline: false}] }, { code: ';', - options: [{spaces: 'always', allowMultiline: true}] + options: [{when: 'always', allowMultiline: true}] }, { code: [ ';' ].join('\n'), - options: [{spaces: 'always', allowMultiline: true}] + options: [{when: 'always', allowMultiline: true}] }, { code: ';', - options: [{spaces: 'always', spacing: {objectLiterals: 'never'}}] + options: [{when: 'always', spacing: {objectLiterals: 'never'}}] }, { code: ';', - options: [{attributes: {spaces: 'never'}}] + options: [{attributes: {when: 'never'}}] }, { code: ';', - options: [{attributes: {spaces: 'always'}}] + options: [{attributes: {when: 'always'}}] }, { code: ';', - options: [{attributes: {spaces: 'always', allowMultiline: false}}] + options: [{attributes: {when: 'always', allowMultiline: false}}] }, { code: ';', - options: [{attributes: {spaces: 'never'}}] + options: [{attributes: {when: 'never'}}] }, { code: [ ';' ].join('\n'), - options: [{spaces: 'never'}] + options: [{when: 'never'}] }, { code: ';', - options: [{attributes: {spaces: 'always'}}] + options: [{attributes: {when: 'always'}}] }, { code: [ ';' ].join('\n'), - options: [{attributes: {spaces: 'always'}}] + options: [{attributes: {when: 'always'}}] }, { code: [ ';' ].join('\n'), - options: [{attributes: {spaces: 'always'}}] + options: [{attributes: {when: 'always'}}] }, { code: [ ';' ].join('\n'), - options: [{attributes: {spaces: 'always', allowMultiline: true}}] + options: [{attributes: {when: 'always', allowMultiline: true}}] }, { code: [ ';' ].join('\n'), - options: [{attributes: {spaces: 'never'}}] + options: [{attributes: {when: 'never'}}] }, { code: [ ';' ].join('\n'), - options: [{attributes: {spaces: 'never', allowMultiline: true}}] + options: [{attributes: {when: 'never', allowMultiline: true}}] }, { code: [ '
{/* comment */}
;' ].join('\n'), - options: [{attributes: {spaces: 'never'}}] + options: [{attributes: {when: 'never'}}] }, { code: ';', - options: [{attributes: {spaces: 'never'}}] + options: [{attributes: {when: 'never'}}] }, { code: ';', - options: [{attributes: {spaces: 'always', spacing: {}}}] + options: [{attributes: {when: 'always', spacing: {}}}] }, { code: [ ';' ].join('\n'), - options: [{spaces: 'always', spacing: {}}] + options: [{when: 'always', spacing: {}}] }, { code: [ ';' ].join('\n'), - options: [{attributes: {spaces: 'always', spacing: {}}}] + options: [{attributes: {when: 'always', spacing: {}}}] }, { code: ';', - options: [{attributes: {spaces: 'always', spacing: {objectLiterals: 'never'}}}] + options: [{attributes: {when: 'always', spacing: {objectLiterals: 'never'}}}] }, { code: [ ';' ].join('\n'), - options: [{spaces: 'always', allowMultiline: true}] + options: [{when: 'always', allowMultiline: true}] }, { code: [ ';' ].join('\n'), - options: [{spaces: 'always', spacing: {objectLiterals: 'never'}}] + options: [{when: 'always', spacing: {objectLiterals: 'never'}}] }, { code: ';' }, { code: ';', - options: [{attributes: {spaces: 'never'}}] + options: [{attributes: {when: 'never'}}] }, { code: ';', - options: [{attributes: {spaces: 'always'}}] + options: [{attributes: {when: 'always'}}] }, { code: ';', - options: [{attributes: {spaces: 'always', allowMultiline: false}}] + options: [{attributes: {when: 'always', allowMultiline: false}}] }, { code: [ ';' ].join('\n'), - options: [{attributes: {spaces: 'always'}}] + options: [{attributes: {when: 'always'}}] }, { code: [ ';' ].join('\n'), - options: [{attributes: {spaces: 'always', allowMultiline: true}}] + options: [{attributes: {when: 'always', allowMultiline: true}}] }, { code: [ ';' ].join('\n'), - options: [{attributes: {spaces: 'never'}}] + options: [{attributes: {when: 'never'}}] }, { code: [ ';' ].join('\n'), - options: [{attributes: {spaces: 'never', allowMultiline: true}}] + options: [{attributes: {when: 'never', allowMultiline: true}}] }, { code: ';', - options: [{attributes: {spaces: 'never'}}] + options: [{attributes: {when: 'never'}}] }, { code: ';' }, { code: ';', - options: [{attributes: {spaces: 'never'}}] + options: [{attributes: {when: 'never'}}] }, { code: ';', - options: [{attributes: {spaces: 'always'}}] + options: [{attributes: {when: 'always'}}] }, { code: ';', - options: [{attributes: {spaces: 'always', allowMultiline: false}}] + options: [{attributes: {when: 'always', allowMultiline: false}}] }, { code: ';', - options: [{attributes: {spaces: 'never'}}] + options: [{attributes: {when: 'never'}}] }, { code: ';', - options: [{attributes: {spaces: 'always'}}] + options: [{attributes: {when: 'always'}}] }, { code: [ ';' ].join('\n'), - options: [{attributes: {spaces: 'always'}}] + options: [{attributes: {when: 'always'}}] }, { code: ';', - options: [{attributes: {spaces: 'never'}}] + options: [{attributes: {when: 'never'}}] }, { code: '', - options: [{attributes: {spaces: 'never', spacing: {objectLiterals: 'always'}}}] + options: [{attributes: {when: 'never', spacing: {objectLiterals: 'always'}}}] }, { code: '
{bar}
', - options: [{attributes: {spaces: 'always'}}] + options: [{attributes: {when: 'always'}}] }], invalid: [{ @@ -284,7 +284,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{spaces: 'never'}], + options: [{when: 'never'}], errors: [{ message: 'There should be no space after \'{\'' }, { @@ -297,7 +297,7 @@ ruleTester.run('jsx-curly-spacing', rule, { '} />;' ].join('\n'), output: ';', - options: [{spaces: 'never', allowMultiline: false}], + options: [{when: 'never', allowMultiline: false}], errors: [{ message: 'There should be no newline after \'{\'' }, { @@ -306,7 +306,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{spaces: 'never', spacing: {objectLiterals: 'never'}}], + options: [{when: 'never', spacing: {objectLiterals: 'never'}}], errors: [{ message: 'There should be no space after \'{\'' }, { @@ -319,7 +319,7 @@ ruleTester.run('jsx-curly-spacing', rule, { '} />;' ].join('\n'), output: ';', - options: [{spaces: 'never', allowMultiline: false, spacing: {objectLiterals: 'never'}}], + options: [{when: 'never', allowMultiline: false, spacing: {objectLiterals: 'never'}}], errors: [{ message: 'There should be no newline after \'{\'' }, { @@ -332,7 +332,7 @@ ruleTester.run('jsx-curly-spacing', rule, { '} />;' ].join('\n'), output: ';', - options: [{spaces: 'never', allowMultiline: false, spacing: {objectLiterals: 'always'}}], + options: [{when: 'never', allowMultiline: false, spacing: {objectLiterals: 'always'}}], errors: [{ message: 'There should be no newline after \'{\'' }, { @@ -345,7 +345,7 @@ ruleTester.run('jsx-curly-spacing', rule, { '} />;' ].join('\n'), output: ';', - options: [{spaces: 'always', allowMultiline: false, spacing: {objectLiterals: 'never'}}], + options: [{when: 'always', allowMultiline: false, spacing: {objectLiterals: 'never'}}], errors: [{ message: 'There should be no newline after \'{\'' }, { @@ -358,7 +358,7 @@ ruleTester.run('jsx-curly-spacing', rule, { '} />;' ].join('\n'), output: ';', - options: [{spaces: 'always', allowMultiline: false, spacing: {objectLiterals: 'always'}}], + options: [{when: 'always', allowMultiline: false, spacing: {objectLiterals: 'always'}}], errors: [{ message: 'There should be no newline after \'{\'' }, { @@ -367,7 +367,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{spaces: 'never', spacing: {objectLiterals: 'always'}}], + options: [{when: 'never', spacing: {objectLiterals: 'always'}}], errors: [{ message: 'A space is required after \'{\'' }, { @@ -376,7 +376,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{spaces: 'always'}], + options: [{when: 'always'}], errors: [{ message: 'A space is required after \'{\'' }, { @@ -389,7 +389,7 @@ ruleTester.run('jsx-curly-spacing', rule, { '} />;' ].join('\n'), output: ';', - options: [{spaces: 'always', allowMultiline: false}], + options: [{when: 'always', allowMultiline: false}], errors: [{ message: 'There should be no newline after \'{\'' }, { @@ -398,7 +398,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{spaces: 'always', spacing: {objectLiterals: 'never'}}], + options: [{when: 'always', spacing: {objectLiterals: 'never'}}], errors: [{ message: 'There should be no space after \'{\'' }, { @@ -407,7 +407,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{spaces: 'always', spacing: {objectLiterals: 'always'}}], + options: [{when: 'always', spacing: {objectLiterals: 'always'}}], errors: [{ message: 'A space is required after \'{\'' }, { @@ -416,7 +416,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'never'}}], + options: [{attributes: {when: 'never'}}], errors: [{ message: 'There should be no space after \'{\'' }, { @@ -425,7 +425,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'never', allowMultiline: false}}], + options: [{attributes: {when: 'never', allowMultiline: false}}], errors: [{ message: 'There should be no space after \'{\'' }, { @@ -434,7 +434,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always'}}], + options: [{attributes: {when: 'always'}}], errors: [{ message: 'A space is required after \'{\'' }, { @@ -443,7 +443,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always', allowMultiline: false}}], + options: [{attributes: {when: 'always', allowMultiline: false}}], errors: [{ message: 'A space is required after \'{\'' }, { @@ -452,28 +452,28 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always'}}], + options: [{attributes: {when: 'always'}}], errors: [{ message: 'A space is required before \'}\'' }] }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always'}}], + options: [{attributes: {when: 'always'}}], errors: [{ message: 'A space is required after \'{\'' }] }, { code: ';', output: ';', - options: [{attributes: {spaces: 'never'}}], + options: [{attributes: {when: 'never'}}], errors: [{ message: 'There should be no space after \'{\'' }] }, { code: ';', output: ';', - options: [{attributes: {spaces: 'never'}}], + options: [{attributes: {when: 'never'}}], errors: [{ message: 'There should be no space before \'}\'' }] @@ -484,7 +484,7 @@ ruleTester.run('jsx-curly-spacing', rule, { '} />;' ].join('\n'), output: ';', - options: [{attributes: {spaces: 'never', allowMultiline: false}}], + options: [{attributes: {when: 'never', allowMultiline: false}}], errors: [{ message: 'There should be no newline after \'{\'' }, { @@ -497,7 +497,7 @@ ruleTester.run('jsx-curly-spacing', rule, { '} />;' ].join('\n'), output: ';', - options: [{attributes: {spaces: 'always', allowMultiline: false}}], + options: [{attributes: {when: 'always', allowMultiline: false}}], errors: [{ message: 'There should be no newline after \'{\'' }, { @@ -506,7 +506,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always', spacing: {}}}], + options: [{attributes: {when: 'always', spacing: {}}}], errors: [{ message: 'A space is required after \'{\'' }, { @@ -515,21 +515,21 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always', spacing: {}}}], + options: [{attributes: {when: 'always', spacing: {}}}], errors: [{ message: 'A space is required before \'}\'' }] }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always', spacing: {}}}], + options: [{attributes: {when: 'always', spacing: {}}}], errors: [{ message: 'A space is required after \'{\'' }] }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always', spacing: {objectLiterals: 'never'}}}], + options: [{attributes: {when: 'always', spacing: {objectLiterals: 'never'}}}], errors: [{ message: 'There should be no space after \'{\'' }, { @@ -538,7 +538,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'never'}}], + options: [{attributes: {when: 'never'}}], errors: [{ message: 'There should be no space after \'{\'' }, { @@ -547,7 +547,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'never', allowMultiline: false}}], + options: [{attributes: {when: 'never', allowMultiline: false}}], errors: [{ message: 'There should be no space after \'{\'' }, { @@ -556,7 +556,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always'}}], + options: [{attributes: {when: 'always'}}], errors: [{ message: 'A space is required after \'{\'' }, { @@ -565,7 +565,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always', allowMultiline: false}}], + options: [{attributes: {when: 'always', allowMultiline: false}}], errors: [{ message: 'A space is required after \'{\'' }, { @@ -574,28 +574,28 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always'}}], + options: [{attributes: {when: 'always'}}], errors: [{ message: 'A space is required before \'}\'' }] }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always'}}], + options: [{attributes: {when: 'always'}}], errors: [{ message: 'A space is required after \'{\'' }] }, { code: ';', output: ';', - options: [{attributes: {spaces: 'never'}}], + options: [{attributes: {when: 'never'}}], errors: [{ message: 'There should be no space after \'{\'' }] }, { code: ';', output: ';', - options: [{attributes: {spaces: 'never'}}], + options: [{attributes: {when: 'never'}}], errors: [{ message: 'There should be no space before \'}\'' }] @@ -606,7 +606,7 @@ ruleTester.run('jsx-curly-spacing', rule, { '} />;' ].join('\n'), output: ';', - options: [{attributes: {spaces: 'never', allowMultiline: false}}], + options: [{attributes: {when: 'never', allowMultiline: false}}], errors: [{ message: 'There should be no newline after \'{\'' }, { @@ -619,7 +619,7 @@ ruleTester.run('jsx-curly-spacing', rule, { '} />;' ].join('\n'), output: ';', - options: [{attributes: {spaces: 'always', allowMultiline: false}}], + options: [{attributes: {when: 'always', allowMultiline: false}}], errors: [{ message: 'There should be no newline after \'{\'' }, { @@ -628,7 +628,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'never'}}], + options: [{attributes: {when: 'never'}}], errors: [{ message: 'There should be no space after \'{\'' }, { @@ -641,7 +641,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'never', allowMultiline: false}}], + options: [{attributes: {when: 'never', allowMultiline: false}}], errors: [{ message: 'There should be no space after \'{\'' }, { @@ -654,7 +654,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always'}}], + options: [{attributes: {when: 'always'}}], errors: [{ message: 'A space is required after \'{\'' }, { @@ -667,7 +667,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always', allowMultiline: false}}], + options: [{attributes: {when: 'always', allowMultiline: false}}], errors: [{ message: 'A space is required after \'{\'' }, { @@ -680,7 +680,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always'}}], + options: [{attributes: {when: 'always'}}], errors: [{ message: 'A space is required before \'}\'' }, { @@ -689,7 +689,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'always'}}], + options: [{attributes: {when: 'always'}}], errors: [{ message: 'A space is required after \'{\'' }, { @@ -698,7 +698,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'never'}}], + options: [{attributes: {when: 'never'}}], errors: [{ message: 'There should be no space after \'{\'' }, { @@ -707,7 +707,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: ';', output: ';', - options: [{attributes: {spaces: 'never'}}], + options: [{attributes: {when: 'never'}}], errors: [{ message: 'There should be no space before \'}\'' }, { @@ -722,7 +722,7 @@ ruleTester.run('jsx-curly-spacing', rule, { '} />;' ].join('\n'), output: ';', - options: [{attributes: {spaces: 'never', allowMultiline: false}}], + options: [{attributes: {when: 'never', allowMultiline: false}}], errors: [{ message: 'There should be no newline after \'{\'' }, { @@ -741,7 +741,7 @@ ruleTester.run('jsx-curly-spacing', rule, { '} />;' ].join('\n'), output: ';', - options: [{attributes: {spaces: 'always', allowMultiline: false}}], + options: [{attributes: {when: 'always', allowMultiline: false}}], errors: [{ message: 'There should be no newline after \'{\'' }, { @@ -754,7 +754,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: '', output: '', - options: [{attributes: {spaces: 'never', spacing: {objectLiterals: 'always'}}}], + options: [{attributes: {when: 'never', spacing: {objectLiterals: 'always'}}}], errors: [{ message: 'There should be no space after \'{\'' }, { @@ -775,7 +775,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: '
', output: '
', - options: [{attributes: {spaces: 'always'}}], + options: [{attributes: {when: 'always'}}], errors: [{ message: 'A space is required after \'{\'' }, { @@ -792,7 +792,7 @@ ruleTester.run('jsx-curly-spacing', rule, { }, { code: '
', output: '
', - options: [{attributes: {spaces: 'always'}}], + options: [{attributes: {when: 'always'}}], errors: [{ message: 'A space is required after \'{\'' }, {