Skip to content

Commit 181060f

Browse files
committed
Rename option to 'first', align with first prop
1 parent efbab1d commit 181060f

File tree

2 files changed

+41
-57
lines changed

2 files changed

+41
-57
lines changed

lib/rules/jsx-indent-props.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = {
4747

4848
schema: [{
4949
oneOf: [{
50-
enum: ['tab', 'aligned']
50+
enum: ['tab', 'first']
5151
}, {
5252
type: 'integer'
5353
}]
@@ -64,8 +64,8 @@ module.exports = {
6464
const sourceCode = context.getSourceCode();
6565

6666
if (context.options.length) {
67-
if (context.options[0] === 'aligned') {
68-
indentSize = 'aligned';
67+
if (context.options[0] === 'first') {
68+
indentSize = 'first';
6969
indentType = 'space';
7070
} else if (context.options[0] === 'tab') {
7171
indentSize = 1;
@@ -167,24 +167,9 @@ module.exports = {
167167
return;
168168
}
169169
let propIndent;
170-
if (indentSize === 'aligned') {
170+
if (indentSize === 'first') {
171171
const firstPropNode = node.attributes[0];
172-
// '<' and any space following it
173-
const beforeNameLength = node.name.range[0] - node.range[0];
174-
// the name itself
175-
const nameLength = node.name.range[1] - node.name.range[0];
176-
// any space between the name and the first attribute
177-
const afterNameLength = Math.max(1, firstPropNode.loc.start.column - node.name.loc.end.column);
178-
if (afterNameLength !== 1) {
179-
// this is not easily fixable, so we just report another error for it.
180-
// it should be unlikely enough to be triggered anyway
181-
context.report({
182-
node: node,
183-
message: 'Found too much whitespace between tag name and first attribute.'
184-
});
185-
}
186-
// use the indentation of the element relative to the beginning of the line
187-
propIndent = node.loc.start.column + beforeNameLength + nameLength + afterNameLength;
172+
propIndent = firstPropNode.loc.start.column;
188173
} else {
189174
const elementIndent = getNodeIndent(node);
190175
propIndent = elementIndent + indentSize;

tests/lib/rules/jsx-indent-props.js

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -63,39 +63,47 @@ ruleTester.run('jsx-indent-props', rule, {
6363
code: [
6464
'<App/>'
6565
].join('\n'),
66-
options: ['aligned']
66+
options: ['first']
6767
}, {
6868
code: [
6969
'<App aaa',
7070
' b',
7171
' cc',
7272
'/>'
7373
].join('\n'),
74-
options: ['aligned']
74+
options: ['first']
75+
}, {
76+
code: [
77+
'<App aaa',
78+
' b',
79+
' cc',
80+
'/>'
81+
].join('\n'),
82+
options: ['first']
7583
}, {
7684
code: [
7785
'const test = <App aaa',
7886
' b',
7987
' cc',
8088
' />'
8189
].join('\n'),
82-
options: ['aligned']
90+
options: ['first']
8391
}, {
8492
code: [
8593
'<App aaa x',
8694
' b y',
8795
' cc',
8896
'/>'
8997
].join('\n'),
90-
options: ['aligned']
98+
options: ['first']
9199
}, {
92100
code: [
93101
'const test = <App aaa x',
94102
' b y',
95103
' cc',
96104
' />'
97105
].join('\n'),
98-
options: ['aligned']
106+
options: ['first']
99107
}, {
100108
code: [
101109
'<App aaa',
@@ -105,7 +113,7 @@ ruleTester.run('jsx-indent-props', rule, {
105113
' d/>',
106114
'</App>'
107115
].join('\n'),
108-
options: ['aligned']
116+
options: ['first']
109117
}, {
110118
code: [
111119
'<Fragment>',
@@ -119,7 +127,15 @@ ruleTester.run('jsx-indent-props', rule, {
119127
' />',
120128
'</Fragment>'
121129
].join('\n'),
122-
options: ['aligned']
130+
options: ['first']
131+
}, {
132+
code: [
133+
'<App',
134+
' a',
135+
' b',
136+
'/>'
137+
].join('\n'),
138+
options: ['first']
123139
}],
124140

125141
invalid: [{
@@ -184,20 +200,7 @@ ruleTester.run('jsx-indent-props', rule, {
184200
' b',
185201
'/>'
186202
].join('\n'),
187-
options: ['aligned'],
188-
errors: [{message: 'Expected indentation of 5 space characters but found 2.'}]
189-
}, {
190-
code: [
191-
'<App a x',
192-
' b y',
193-
'/>'
194-
].join('\n'),
195-
output: [
196-
'<App a x',
197-
' b y',
198-
'/>'
199-
].join('\n'),
200-
options: ['aligned'],
203+
options: ['first'],
201204
errors: [{message: 'Expected indentation of 5 space characters but found 2.'}]
202205
}, {
203206
code: [
@@ -210,11 +213,8 @@ ruleTester.run('jsx-indent-props', rule, {
210213
' b',
211214
'/>'
212215
].join('\n'),
213-
options: ['aligned'],
214-
errors: [
215-
{message: 'Found too much whitespace between tag name and first attribute.'},
216-
{message: 'Expected indentation of 6 space characters but found 3.'}
217-
]
216+
options: ['first'],
217+
errors: [{message: 'Expected indentation of 6 space characters but found 3.'}]
218218
}, {
219219
code: [
220220
'<App',
@@ -228,28 +228,27 @@ ruleTester.run('jsx-indent-props', rule, {
228228
' b',
229229
'/>'
230230
].join('\n'),
231-
options: ['aligned'],
232-
errors: [
233-
{message: 'Found too much whitespace between tag name and first attribute.'},
234-
{message: 'Expected indentation of 6 space characters but found 3.'}
235-
]
231+
options: ['first'],
232+
errors: [{message: 'Expected indentation of 6 space characters but found 3.'}]
236233
}, {
237234
code: [
238235
'<App',
239236
' a',
240-
' b',
237+
' b',
238+
' c',
241239
'/>'
242240
].join('\n'),
243241
output: [
244242
'<App',
245-
' a',
246-
' b',
243+
' a',
244+
' b',
245+
' c',
247246
'/>'
248247
].join('\n'),
249-
options: ['aligned'],
248+
options: ['first'],
250249
errors: [
251-
{message: 'Expected indentation of 5 space characters but found 2.'},
252-
{message: 'Expected indentation of 5 space characters but found 2.'}
250+
{message: 'Expected indentation of 2 space characters but found 1.'},
251+
{message: 'Expected indentation of 2 space characters but found 3.'}
253252
]
254253
}]
255254
});

0 commit comments

Comments
 (0)