Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Feature indent depth check #3395

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
428 changes: 426 additions & 2 deletions src/rules/indentRule.ts

Large diffs are not rendered by default.

295 changes: 295 additions & 0 deletions test/rules/indent/indent-depth-space-test-2/test.ts.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
foo(
`foo`, // this line is valid
// next line should have an error, currently it is ignored
`
bar
`,
// the two lines above are valid, because the indent is inside the template string
);

for(;;) {}

`foo ${
foo // in string template
}`
return (
foo
);
export interface TestResult {
directory: string;
results: {
[fileName: string]: TestOutput | SkippedTest;
};
}
if (foo) {
foo;
} else if (bar) {
bar; // elseif
}
import {
foo123,
bar,
} from "foobar";

// probably the same for 'export'
export {
foo456,
bar,
}; // export123
let someReallyLongVariableName =
anotherReallyLongVariableName;

return foo
&& bar
&& baz;

someArray.filter((element) =>
doStuff1(element));
// or
const someFn = (element) =>
doStuff(element);
function() {
return new Promise((resolve, reject) => {
doxxxy()
.then(abcd)
doxxx().then(resolve)
}) // abcdoxxx
}
if (
const axax = true
) { // close paren

}
function fff(
aaaxxx
) {

}
module TestModule {
foo( // xxx
'xxxp', /** xxx */
bar,
baz,
);
interface Foo {
a: number
b: string
}
var func = () => {
console.warn("hi");
};

class
TestClass {
private variable;

testFunction() {
this.variable = 3;
}
}

var obj = {
a: 1,
b: 2,
c: 3
};

// ignore leading tabs inside template strings
var s1 = `
multiline` + ` template
string`;
var s2 = `
multiline ${ "A" }
template ${ "B"
+ "C" }
string`;

export enum TestEnum {
VALUE1,
VALUE2
}

switch (integerValue) {
case 1:
console.warn("1");
break;
default:
console.warn("default");
break;
}

function loops() {
for (var i = 0; i < 1; ++i) {
console.warn(i);
}

while (i < 1) {
console.warn(i);
}

do {
console.warn(i);
} while (i < 1);

if (i < 1) {
console.warn(i);
} else {
console.warn(i + 1);
}
}
}

function abc() {
let a = 1
let b = 1
let c = 1
let d = 1
let e = 1
var a1 = 1,
a2 = 2,
a3 = 3
}

function fff(
aaayyy,
bbb,
ccc
) {
if (
aaaif
&& bbb &&
ccc
) {
var bbbbcontent
}
if (
const axa = true
) { // close paren

}
}

// invalid code
// we get a weird scenario here where our ~~ underlines don't quite line up with the line above
// this is because tabs are only one character and thus only one ~ goes beneath them.
module TestModule {
var testVariable = 123;
}

function() {
var test = 123;
}

class TestClass {
private variable;

testFunction() {
this.variable = 3;
}
}

var obj = {
a: 1,
b: 2,
c: 3
};

enum TestEnum {
VALUE1,
VALUE2
}

switch (integerValue) {
case 0:
console.warn("1");
break;
case 1:
console.warn("1");
break;
default:
console.warn("default");
break;
}

for (var i = 0; i < 1; ++i) {
console.warn("123");
}

while (i < 1) {
console.warn("123");
}

do {
console.warn("123");
} while (
i < 1);

if (i < 1) {
console.warn("123");
}

var arr = [
1,
2
];

var arr2 = [
{
a: 1,
b: 2
},
{
a: 3,
b: 4
}
];
// multiline condition, works well for `if`, but probably doesn't for `while`
while(foo() &&
barx() &&
baz()) {
doStuff;
}
// might not be worth fixing, because it can be reformatted to
while(
foo() &&
bar() &&
baz()
) {
doStuff;
}

// statement continuation on the next line
let foo = bar
? baz
: bas;
foo = "some"
+ "really"
+ "long"
+ "string";

// multiline property access
foo
.bar
.baz();
var a = 10
- 9
*8
/7
declare namespace Foo {
export interface InterFoo {
foo(s: string): boolean
}
const a = 1
export class Bar implements Barz {
fff(s: string): boolean {
return false
}
}
}
export interface StringValidator {
isAcceptable(s: string): boolean;
}
new Foo(
barnew,
baznew,
);
Loading