Skip to content

Commit

Permalink
refactor code, add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjuan committed Dec 31, 2019
1 parent 9ba2fc1 commit c780efb
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 11 deletions.
7 changes: 2 additions & 5 deletions lib/rules/indent.js
Expand Up @@ -923,11 +923,8 @@ module.exports = {
parameterParens.add(openingParen);
parameterParens.add(closingParen);

let offsetToken = sourceCode.getTokenBefore(openingParen);

if (node.callee.type === "TaggedTemplateExpression") {
offsetToken = sourceCode.getTokenBefore(node.callee.quasi);
}
const offsetAfterToken = node.callee.type === "TaggedTemplateExpression" ? node.callee.quasi : openingParen;
const offsetToken = sourceCode.getTokenBefore(offsetAfterToken);

offsets.setDesiredOffset(openingParen, offsetToken, 0);

Expand Down
136 changes: 130 additions & 6 deletions tests/lib/rules/indent.js
Expand Up @@ -5498,13 +5498,82 @@ ruleTester.run("indent", rule, {
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo.bar\` template literal \`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo.bar.baz\` template literal \`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo
.test\`
.bar\` template
literal \`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo
.bar
.baz\` template
literal \`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo.bar\`
\${a} \${b}
\`(() => {
bar();
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo.bar1.bar2\`
\${a} \${b}
\`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo
.bar1
.bar2\`
\${a} \${b}
\`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo
.bar\`
\${a} \${b}
\`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
Expand All @@ -5515,21 +5584,23 @@ ruleTester.run("indent", rule, {
.test\`
\${a} \${b}
\`(() => {
bar();
baz();
})
`,
options: [4, { MemberExpression: 0 }]
options: [4, { MemberExpression: 0 }],
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo
.test\`
\${a} \${b}
\`(() => {
bar();
baz();
})
`,
options: [4, { MemberExpression: 2 }]
options: [4, { MemberExpression: 2 }],
parserOptions: { ecmaVersion: 2015 }
}
],

Expand Down Expand Up @@ -10927,6 +10998,59 @@ ruleTester.run("indent", rule, {
[9, 8, 0, "Identifier"]
])
},
{
code: unIndent`
foo.bar\` template literal \`(() => {
baz();
})
`,
output: unIndent`
foo.bar\` template literal \`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 },
errors: expectedErrors([
[2, 4, 8, "Identifier"]
])
},
{
code: unIndent`
foo.bar.baz\` template literal \`(() => {
baz();
})
`,
output: unIndent`
foo.bar.baz\` template literal \`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 },
errors: expectedErrors([
[2, 4, 0, "Identifier"],
[3, 0, 4, "Punctuator"]
])
},
{
code: unIndent`
foo
.bar\` template
literal \`(() => {
baz();
})
`,
output: unIndent`
foo
.bar\` template
literal \`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 },
errors: expectedErrors([
[5, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
foo
Expand Down

0 comments on commit c780efb

Please sign in to comment.