-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support adding ability to enfore curly brace presence
- Loading branch information
1 parent
5605a36
commit d5e5a2e
Showing
6 changed files
with
166 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* @fileoverview Enfore curly brace presence or disallow unnecessary curly brace in JSX | ||
* @author Jacky Ho | ||
*/ | ||
'use strict'; | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Requirements | ||
// ------------------------------------------------------------------------------ | ||
|
||
const rule = require('../../../lib/rules/jsx-curly-brace-presence'); | ||
const RuleTester = require('eslint').RuleTester; | ||
const parserOptions = { | ||
ecmaVersion: 8, | ||
sourceType: 'module', | ||
ecmaFeatures: { | ||
experimentalObjectRestSpread: true, | ||
jsx: true | ||
} | ||
}; | ||
|
||
const missingCurlyMessage = 'Need to wrap this literal in a JSX expression.'; | ||
const unnecessaryCurlyMessage = 'Curly braces are unnecessary here.'; | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Tests | ||
// ------------------------------------------------------------------------------ | ||
|
||
const ruleTester = new RuleTester({parserOptions}); | ||
ruleTester.run('jsx-curly-spacing', rule, { | ||
valid: [ | ||
{ | ||
code: "<App>{<myApp></myApp>}</App>" | ||
}, | ||
{ | ||
code: "<App>{[]}</App>" | ||
}, | ||
{ | ||
code: "<App>foo</App>" | ||
}, | ||
{ | ||
code: "<App prop='bar'>foo</App>" | ||
}, | ||
{ | ||
code: "<App prop='bar'>{'foo \\n bar'}</App>" | ||
}, | ||
{ | ||
code: "<App prop={'foo \\u00b7 bar'}>foo</App>" | ||
}, | ||
{ | ||
code: "<MyComponent prop={'bar'}>foo</MyComponent>", | ||
options: [{ props: 'always' }], | ||
}, | ||
{ | ||
code: "<MyComponent>{'foo'}</MyComponent>", | ||
options: [{ children: 'always' }], | ||
}, | ||
{ | ||
code: "<MyComponent>{'foo'}</MyComponent>", | ||
options: [{ children: 'ignore' }], | ||
}, | ||
{ | ||
code: "<MyComponent prop={'bar'}>foo</MyComponent>", | ||
options: [{ props: 'ignore' }], | ||
}, | ||
{ | ||
code: "<MyComponent prop='bar'>foo</MyComponent>", | ||
options: [{ props: 'ignore' }], | ||
}, | ||
{ | ||
code: "<MyComponent>foo</MyComponent>", | ||
options: [{ children: 'ignore' }], | ||
}, | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: "<MyComponent>{'foo'}</MyComponent>", | ||
output: "<MyComponent>foo</MyComponent>", | ||
errors: [{ message: unnecessaryCurlyMessage }] | ||
}, | ||
{ | ||
code: "<MyComponent prop={'bar'}>foo</MyComponent>", | ||
output: '<MyComponent prop="bar">foo</MyComponent>', | ||
errors: [{ message: unnecessaryCurlyMessage }] | ||
}, | ||
{ | ||
code: "<MyComponent>{'foo'}</MyComponent>", | ||
output: "<MyComponent>foo</MyComponent>", | ||
options: [{ children: 'never' }], | ||
errors: [{ message: unnecessaryCurlyMessage }] | ||
}, | ||
{ | ||
code: "<MyComponent prop={'bar'}>foo</MyComponent>", | ||
output: '<MyComponent prop="bar">foo</MyComponent>', | ||
options: [{ props: 'never' }], | ||
errors: [{ message: unnecessaryCurlyMessage }] | ||
}, | ||
{ | ||
code: "<MyComponent prop='bar'>foo</MyComponent>", | ||
options: [{ props: 'always' }], | ||
errors: [{ message: missingCurlyMessage }] | ||
}, | ||
{ | ||
code: "<MyComponent>foo</MyComponent>", | ||
options: [{ children: 'always' }], | ||
errors: [{ message: missingCurlyMessage }] | ||
}, | ||
] | ||
}) |
This file was deleted.
Oops, something went wrong.