diff --git a/lib/rules/jsx-indent-props.js b/lib/rules/jsx-indent-props.js
index 1942b53605..7a07cca283 100644
--- a/lib/rules/jsx-indent-props.js
+++ b/lib/rules/jsx-indent-props.js
@@ -56,18 +56,17 @@ module.exports = {
},
create(context) {
- debugger;
const MESSAGE = 'Expected indentation of {{needed}} {{type}} {{characters}} but found {{gotten}}.';
const extraColumnStart = 0;
let indentType = 'space';
/** @type {number|'first'} */
let indentSize = 4;
- // beforeLine을 추가해줬다!
- const beforeLine = {
- isOperator : false,
- indent : 0,
+ const line = {
+ isUsingOperator: false,
+ currentOperator: false
};
+
if (context.options.length) {
if (context.options[0] === 'first') {
indentSize = 'first';
@@ -88,7 +87,6 @@ module.exports = {
* @param {Number} gotten Indentation character count in the actual node/code
*/
function report(node, needed, gotten) {
- debugger;
const msgContext = {
needed,
type: indentType,
@@ -96,7 +94,7 @@ module.exports = {
gotten
};
- context.report({ // 린트 에러를 호출하는 함수가 실행되지 않음
+ context.report({
node,
message: MESSAGE,
data: msgContext,
@@ -118,25 +116,21 @@ module.exports = {
src = lines[0];
let regExp;
- let useOperator;
- let operatorIndent;
if (indentType === 'space') {
regExp = /^[ ]+/;
} else {
regExp = /^[\t]+/;
}
+
const indent = regExp.exec(src);
- useOperator = /^[:](?![:])/.test(src) || /^[?](?![?])/.test(src); // 연산자가 사용됐는지 확인해준다
-
- if(useOperator) { // 만약 연산자가 사용됐다면 저장 해준다
- beforeLine.isOperator = true;
- beforeLine.indent = indent[0].length;
- } else if(!useOperator && beforeLine.isOperator) { // 현재 줄에서는 연산자가 사용되지 않고, 이 전 줄에 연산자가 사용됐다면 인덴트를 추가로 해주자
- beforeLine.isOperator = false;
- operatorIndent = indentSize !== 'first' ? indentSize : 0;
+ const useOperator = /^([ ]|[\t])*[:]/.test(src) || /^([ ]|[\t])*[?]/.test(src);
+ line.currentOperator = false;
+ if (useOperator) {
+ line.isUsingOperator = true;
+ line.currentOperator = true;
}
- debugger;
- return indent ? indent[0].length + operatorIndent : 0;
+
+ return indent ? indent[0].length : 0;
}
/**
@@ -144,10 +138,13 @@ module.exports = {
* @param {ASTNode[]} nodes list of node objects
* @param {Number} indent needed indent
*/
- function checkNodesIndent(nodes, indent) { // 여기가 요주의 함수이다 여기서 조건문으로 report로 넘어가는데 여
+ function checkNodesIndent(nodes, indent) {
nodes.forEach((node) => {
const nodeIndent = getNodeIndent(node);
- debugger;
+ if (line.isUsingOperator && !line.currentOperator && indentSize !== 'first') {
+ indent += indentSize;
+ line.isUsingOperator = false;
+ }
if (
node.type !== 'ArrayExpression' && node.type !== 'ObjectExpression'
&& nodeIndent !== indent && astUtil.isNodeFirstInLine(context, node)
@@ -159,7 +156,6 @@ module.exports = {
return {
JSXOpeningElement(node) {
- debugger;
if (!node.attributes.length) {
return;
}
@@ -167,11 +163,9 @@ module.exports = {
if (indentSize === 'first') {
const firstPropNode = node.attributes[0];
propIndent = firstPropNode.loc.start.column;
- debugger;
} else {
const elementIndent = getNodeIndent(node);
propIndent = elementIndent + indentSize;
- debugger;
}
checkNodesIndent(node.attributes, propIndent);
}
diff --git a/tests/lib/rules/jsx-indent-props.js b/tests/lib/rules/jsx-indent-props.js
index 1a84436f4b..0cd1de59ba 100644
--- a/tests/lib/rules/jsx-indent-props.js
+++ b/tests/lib/rules/jsx-indent-props.js
@@ -26,256 +26,294 @@ const parserOptions = {
const ruleTester = new RuleTester({parserOptions});
ruleTester.run('jsx-indent-props', rule, {
- valid: [
- // {
- // code: [
- // ''
- // ].join('\n')
- // }, {
- // code: [
- // ''
- // ].join('\n'),
- // options: [2]
- // }, {
- // code: [
- // ''
- // ].join('\n'),
- // options: [0]
- // }, {
- // code: [
- // ' '
- // ].join('\n'),
- // options: [-2]
- // }, {
- // code: [
- // ''
- // ].join('\n'),
- // options: ['tab']
- // }, {
- // code: [
- // ''
- // ].join('\n'),
- // options: ['first']
- // }, {
- // code: [
- // ''
- // ].join('\n'),
- // options: ['first']
- // }, {
- // code: [
- // ''
- // ].join('\n'),
- // options: ['first']
- // }, {
- // code: [
- // 'const test = '
- // ].join('\n'),
- // options: ['first']
- // }, {
- // code: [
- // ''
- // ].join('\n'),
- // options: ['first']
- // }, {
- // code: [
- // 'const test = '
- // ].join('\n'),
- // options: ['first']
- // }, {
- // code: [
- // '',
- // ' ',
- // ''
- // ].join('\n'),
- // options: ['first']
- // }, {
- // code: [
- // '',
- // ' ',
- // ' ',
- // ''
- // ].join('\n'),
- // options: ['first']
- // }, {
- // code: [
- // ''
- // ].join('\n'),
- // options: ['first']
- // }
- ],
+ valid: [{
+ code: [
+ ''
+ ].join('\n')
+ }, {
+ code: [
+ ''
+ ].join('\n'),
+ options: [2]
+ }, {
+ code: [
+ ''
+ ].join('\n'),
+ options: [0]
+ }, {
+ code: [
+ ' '
+ ].join('\n'),
+ options: [-2]
+ }, {
+ code: [
+ ''
+ ].join('\n'),
+ options: ['tab']
+ }, {
+ code: [
+ ''
+ ].join('\n'),
+ options: ['first']
+ }, {
+ code: [
+ ''
+ ].join('\n'),
+ options: ['first']
+ }, {
+ code: [
+ ''
+ ].join('\n'),
+ options: ['first']
+ }, {
+ code: [
+ 'const test = '
+ ].join('\n'),
+ options: ['first']
+ }, {
+ code: [
+ ''
+ ].join('\n'),
+ options: ['first']
+ }, {
+ code: [
+ 'const test = '
+ ].join('\n'),
+ options: ['first']
+ }, {
+ code: [
+ '',
+ ' ',
+ ''
+ ].join('\n'),
+ options: ['first']
+ }, {
+ code: [
+ '',
+ ' ',
+ ' ',
+ ''
+ ].join('\n'),
+ options: ['first']
+ }, {
+ code: [
+ ''
+ ].join('\n'),
+ options: ['first']
+ }],
- invalid: [
- // {
- // code: [
- // ''
- // ].join('\n'),
- // output: [
- // ''
- // ].join('\n'),
- // errors: [{message: 'Expected indentation of 4 space characters but found 2.'}]
- // }, {
- // code: [
- // ''
- // ].join('\n'),
- // output: [
- // ''
- // ].join('\n'),
- // options: [2],
- // errors: [{message: 'Expected indentation of 2 space characters but found 4.'}]
- // }, {
- // code: [
- // ''
- // ].join('\n'),
- // output: [
- // ''
- // ].join('\n'),
- // options: ['tab'],
- // errors: [{message: 'Expected indentation of 1 tab character but found 0.'}]
- // }, {
- // code: [
- // ''
- // ].join('\n'),
- // output: [
- // ''
- // ].join('\n'),
- // options: ['tab'],
- // errors: [{message: 'Expected indentation of 1 tab character but found 3.'}]
- // }, {
- // code: [
- // ''
- // ].join('\n'),
- // output: [
- // ''
- // ].join('\n'),
- // options: ['first'],
- // errors: [{message: 'Expected indentation of 5 space characters but found 2.'}]
- // }, {
- // code: [
- // ''
- // ].join('\n'),
- // output: [
- // ''
- // ].join('\n'),
- // options: ['first'],
- // errors: [{message: 'Expected indentation of 6 space characters but found 3.'}]
- // }, {
- // code: [
- // ''
- // ].join('\n'),
- // output: [
- // ''
- // ].join('\n'),
- // options: ['first'],
- // errors: [{message: 'Expected indentation of 6 space characters but found 3.'}]
- // }, {
- // code: [
- // ''
- // ].join('\n'),
- // output: [
- // ''
- // ].join('\n'),
- // options: ['first'],
- // errors: [
- // {message: 'Expected indentation of 2 space characters but found 1.'},
- // {message: 'Expected indentation of 2 space characters but found 3.'}
- // ]
- // },
- {
- code: [
- 'const test = true',
- ' ? ',
- ' : '
- ].join('\n'),
- output: [
- 'const test = true',
- ' ? ',
- ' : '
- ].join('\n'),
- options: [2],
- errors: [
- {message: 'Expected indentation of 6 space characters but found 4.'}
- ]
- }]
+ invalid: [{
+ code: [
+ ''
+ ].join('\n'),
+ output: [
+ ''
+ ].join('\n'),
+ errors: [{message: 'Expected indentation of 4 space characters but found 2.'}]
+ }, {
+ code: [
+ ''
+ ].join('\n'),
+ output: [
+ ''
+ ].join('\n'),
+ options: [2],
+ errors: [{message: 'Expected indentation of 2 space characters but found 4.'}]
+ }, {
+ code: [
+ 'const test = true',
+ ' ? ',
+ ' : '
+ ].join('\n'),
+ output: [
+ 'const test = true',
+ ' ? ',
+ ' : '
+ ].join('\n'),
+ options: [2],
+ errors: [
+ {message: 'Expected indentation of 6 space characters but found 4.'},
+ {message: 'Expected indentation of 6 space characters but found 4.'}
+ ]
+ }, {
+ code: [
+ '{test.isLoading',
+ ' ? ',
+ ' : ',
+ '}'
+ ].join('\n'),
+ output: [
+ '{test.isLoading',
+ ' ? ',
+ ' : ',
+ '}'
+ ].join('\n'),
+ options: [2],
+ errors: [
+ {message: 'Expected indentation of 6 space characters but found 4.'}
+ ]
+ }, {
+ code: [
+ '{test.isLoading',
+ ' ? ',
+ ' : ',
+ '}'
+ ].join('\n'),
+ output: [
+ '{test.isLoading',
+ ' ? ',
+ ' : ',
+ '}'
+ ].join('\n'),
+ options: [2],
+ errors: [
+ {message: 'Expected indentation of 6 space characters but found 4.'},
+ {message: 'Expected indentation of 6 space characters but found 4.'}
+ ]
+ }, {
+ code: [
+ ''
+ ].join('\n'),
+ output: [
+ ''
+ ].join('\n'),
+ options: ['tab'],
+ errors: [{message: 'Expected indentation of 1 tab character but found 0.'}]
+ }, {
+ code: [
+ ''
+ ].join('\n'),
+ output: [
+ ''
+ ].join('\n'),
+ options: ['tab'],
+ errors: [{message: 'Expected indentation of 1 tab character but found 3.'}]
+ }, {
+ code: [
+ ''
+ ].join('\n'),
+ output: [
+ ''
+ ].join('\n'),
+ options: ['first'],
+ errors: [{message: 'Expected indentation of 5 space characters but found 2.'}]
+ }, {
+ code: [
+ ''
+ ].join('\n'),
+ output: [
+ ''
+ ].join('\n'),
+ options: ['first'],
+ errors: [{message: 'Expected indentation of 6 space characters but found 3.'}]
+ }, {
+ code: [
+ ''
+ ].join('\n'),
+ output: [
+ ''
+ ].join('\n'),
+ options: ['first'],
+ errors: [{message: 'Expected indentation of 6 space characters but found 3.'}]
+ }, {
+ code: [
+ ''
+ ].join('\n'),
+ output: [
+ ''
+ ].join('\n'),
+ options: ['first'],
+ errors: [
+ {message: 'Expected indentation of 2 space characters but found 1.'},
+ {message: 'Expected indentation of 2 space characters but found 3.'}
+ ]
+ }]
});