Skip to content

Commit 45019af

Browse files
committed
Rename jsx-fragments mode
1 parent 31da0ce commit 45019af

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

lib/rules/jsx-fragments.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ module.exports = {
2929
fixable: 'code',
3030

3131
schema: [{
32-
enum: ['always', 'never']
32+
enum: ['syntax', 'element']
3333
}]
3434
},
3535

3636
create: function(context) {
37-
const configuration = context.options[0] || 'always';
37+
const configuration = context.options[0] || 'syntax';
3838
const sourceCode = context.getSourceCode();
3939
const reactPragma = pragmaUtil.getFromContext(context);
4040
const fragmentPragma = pragmaUtil.getFragmentFromContext(context);
@@ -116,7 +116,7 @@ module.exports = {
116116
}
117117

118118
const jsxElements = [];
119-
const fragmentNames = [];
119+
const fragmentNames = [`${reactPragma}.${fragmentPragma}`];
120120

121121
// --------------------------------------------------------------------------
122122
// Public
@@ -132,7 +132,7 @@ module.exports = {
132132
return;
133133
}
134134

135-
if (configuration === 'never') {
135+
if (configuration === 'element') {
136136
context.report({
137137
node,
138138
message: `Prefer ${reactPragma}.${fragmentPragma} over fragment shorthand`,
@@ -154,19 +154,17 @@ module.exports = {
154154
},
155155

156156
'Program:exit'() {
157-
const possibleFragmentNames = fragmentNames.concat([`${reactPragma}.${fragmentPragma}`]);
158-
159157
jsxElements.forEach(node => {
160158
const openingEl = node.openingElement;
161159
const elName = elementType(openingEl);
162160

163-
if (possibleFragmentNames.indexOf(elName) !== -1 || refersToReactFragment(elName)) {
161+
if (fragmentNames.indexOf(elName) !== -1 || refersToReactFragment(elName)) {
164162
if (reportOnReactVersion(node)) {
165163
return;
166164
}
167165

168166
const attrs = openingEl.attributes;
169-
if (configuration === 'always' && !(attrs && attrs.length > 0)) {
167+
if (configuration === 'syntax' && !(attrs && attrs.length > 0)) {
170168
context.report({
171169
node,
172170
message: `Prefer fragment shorthand over ${reactPragma}.${fragmentPragma}`,

tests/lib/rules/jsx-fragments.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,39 +47,39 @@ ruleTester.run('jsx-fragments', rule, {
4747
settings
4848
}, {
4949
code: '<Act.Frag><Foo /></Act.Frag>',
50-
options: ['never'],
50+
options: ['element'],
5151
settings
5252
}, {
5353
code: `
5454
import Act, { Frag as F } from 'react';
5555
<F><Foo /></F>;
5656
`,
57-
options: ['never'],
57+
options: ['element'],
5858
settings
5959
}, {
6060
code: `
6161
const F = Act.Frag;
6262
<F><Foo /></F>;
6363
`,
64-
options: ['never'],
64+
options: ['element'],
6565
settings
6666
}, {
6767
code: `
6868
const { Frag } = Act;
6969
<Frag><Foo /></Frag>;
7070
`,
71-
options: ['never'],
71+
options: ['element'],
7272
settings
7373
}, {
7474
code: `
7575
const { Frag } = require('react');
7676
<Frag><Foo /></Frag>;
7777
`,
78-
options: ['never'],
78+
options: ['element'],
7979
settings
8080
}, {
8181
code: '<Act.Frag key="key"><Foo /></Act.Frag>',
82-
options: ['always'],
82+
options: ['syntax'],
8383
settings
8484
}],
8585

@@ -99,15 +99,15 @@ ruleTester.run('jsx-fragments', rule, {
9999
}, {
100100
code: '<><Foo /></>',
101101
parser: 'babel-eslint',
102-
options: ['never'],
102+
options: ['element'],
103103
settings,
104104
errors: [{
105105
message: 'Prefer Act.Frag over fragment shorthand'
106106
}],
107107
output: '<Act.Frag><Foo /></Act.Frag>'
108108
}, {
109109
code: '<Act.Frag><Foo /></Act.Frag>',
110-
options: ['always'],
110+
options: ['syntax'],
111111
settings,
112112
errors: [{
113113
message: 'Prefer fragment shorthand over Act.Frag'
@@ -118,7 +118,7 @@ ruleTester.run('jsx-fragments', rule, {
118118
import Act, { Frag as F } from 'react';
119119
<F><Foo /></F>;
120120
`,
121-
options: ['always'],
121+
options: ['syntax'],
122122
settings,
123123
errors: [{
124124
message: 'Prefer fragment shorthand over Act.Frag'
@@ -132,7 +132,7 @@ ruleTester.run('jsx-fragments', rule, {
132132
import Act, { Frag } from 'react';
133133
<Frag><Foo /></Frag>;
134134
`,
135-
options: ['always'],
135+
options: ['syntax'],
136136
settings,
137137
errors: [{
138138
message: 'Prefer fragment shorthand over Act.Frag'
@@ -146,7 +146,7 @@ ruleTester.run('jsx-fragments', rule, {
146146
const F = Act.Frag;
147147
<F><Foo /></F>;
148148
`,
149-
options: ['always'],
149+
options: ['syntax'],
150150
settings,
151151
errors: [{
152152
message: 'Prefer fragment shorthand over Act.Frag'
@@ -160,7 +160,7 @@ ruleTester.run('jsx-fragments', rule, {
160160
const { Frag } = Act;
161161
<Frag><Foo /></Frag>;
162162
`,
163-
options: ['always'],
163+
options: ['syntax'],
164164
settings,
165165
errors: [{
166166
message: 'Prefer fragment shorthand over Act.Frag'
@@ -174,7 +174,7 @@ ruleTester.run('jsx-fragments', rule, {
174174
const { Frag } = require('react');
175175
<Frag><Foo /></Frag>;
176176
`,
177-
options: ['always'],
177+
options: ['syntax'],
178178
settings,
179179
errors: [{
180180
message: 'Prefer fragment shorthand over Act.Frag'

0 commit comments

Comments
 (0)