Skip to content

Commit b0b4218

Browse files
authored
fix(indent): correctly ignore JSXText and TS nodes (#785)
* refactor: refactor array-like node handling to use a shared function * refactor: move `JSXText` to `baseOffsetListeners` * refactor: extract operator token handling into a separate function * refactor: extract conditional nodes handling into a separate function * refactor: extract object-like nodes handling into a separate function * test: add cases * refactor: move `TSImportEqualsDeclaration` to `baseOffsetListeners` * refactor: extract member expressions handling into a separate function * chore: rename function * refactor: separate `TSTypeParameterDeclaration` and `TSTypeParameterInstantiation` * refactor: extract block-like nodes handling into a separate function * refactor: extract heritage checking logic into a separate function * refactor: remove unused `convertTSPropertySignatureToProperty` function * test: add some cases * test: add more `ClassExpression` cases * fix: add missing conditional node check related: 34e4057
1 parent 07b2ee9 commit b0b4218

3 files changed

Lines changed: 522 additions & 618 deletions

File tree

packages/eslint-plugin/rules/indent/indent._js_.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,35 @@ run<RuleOptions, MessageIds>({
16541654
`,
16551655
options: [2],
16561656
},
1657+
{
1658+
code: $`
1659+
var Foo = class
1660+
extends Bar {
1661+
baz() {}
1662+
}
1663+
`,
1664+
options: [2],
1665+
},
1666+
{
1667+
code: $`
1668+
var Foo = class extends
1669+
Bar {
1670+
baz() {}
1671+
}
1672+
`,
1673+
options: [2],
1674+
},
1675+
{
1676+
code: $`
1677+
var Foo = class extends
1678+
(
1679+
Bar
1680+
) {
1681+
baz() {}
1682+
}
1683+
`,
1684+
options: [2],
1685+
},
16571686
{
16581687
code: $`
16591688
fs.readdirSync(path.join(__dirname, '../rules')).forEach(name => {
@@ -8087,6 +8116,34 @@ run<RuleOptions, MessageIds>({
80878116
options: [4, { VariableDeclarator: 1, SwitchCase: 1 }],
80888117
errors: expectedErrors([[2, 4, 2, 'Identifier'], [4, 4, 2, 'Identifier']]),
80898118
},
8119+
{
8120+
code: $`
8121+
class A
8122+
extends B {
8123+
}
8124+
`,
8125+
output: $`
8126+
class A
8127+
extends B {
8128+
}
8129+
`,
8130+
options: [4],
8131+
errors: expectedErrors([[2, 4, 0, 'Keyword']]),
8132+
},
8133+
{
8134+
code: $`
8135+
var A = class
8136+
extends B {
8137+
};
8138+
`,
8139+
output: $`
8140+
var A = class
8141+
extends B {
8142+
};
8143+
`,
8144+
options: [4],
8145+
errors: expectedErrors([[2, 4, 0, 'Keyword']]),
8146+
},
80908147
{
80918148
code: $`
80928149
var a = 1,

packages/eslint-plugin/rules/indent/indent._ts_.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ import foo = require(
362362
{
363363
node: AST_NODE_TYPES.TSMappedType,
364364
code: [
365+
$`
366+
type Partial<T> = {
367+
[P in keyof T];
368+
}
369+
`,
365370
`
366371
type Partial<T> = {
367372
[P in keyof T]: T[P];
@@ -1391,6 +1396,36 @@ import Dialogs = require("widgets/Dialogs");
13911396
},
13921397
{
13931398
code: `
1399+
import Dialogs =
1400+
require("widgets/Dialogs");
1401+
`,
1402+
output: `
1403+
import Dialogs =
1404+
require("widgets/Dialogs");
1405+
`,
1406+
errors: [
1407+
{
1408+
messageId: 'wrongIndentation',
1409+
data: {
1410+
expected: '0 spaces',
1411+
actual: 4,
1412+
},
1413+
line: 2,
1414+
column: 1,
1415+
},
1416+
{
1417+
messageId: 'wrongIndentation',
1418+
data: {
1419+
expected: '4 spaces',
1420+
actual: 6,
1421+
},
1422+
line: 3,
1423+
column: 1,
1424+
},
1425+
],
1426+
},
1427+
{
1428+
code: `
13941429
class Foo {
13951430
public bar : string;
13961431
private bar : string;

0 commit comments

Comments
 (0)