forked from palantir/tslint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ignore-properties to no-inferrable-types (palantir#2178)
- Loading branch information
Showing
8 changed files
with
204 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// errors, inferrable type is declared | ||
let x = 7; | ||
let y = false; | ||
let z = "foo"; | ||
class C { | ||
x = 1; | ||
} | ||
|
||
// errors, types are inferrable | ||
function foo (a = 5, b = true, c = "bah") { } | ||
|
||
class Foo { | ||
bar = 0; | ||
baz = true, | ||
bas = "moar"; | ||
} | ||
|
||
// not errors, inferrable type is not declared | ||
let _x = 7; | ||
let _y = false; | ||
let _z = "foo"; | ||
|
||
// not error, type is not inferrable | ||
let weird: any = 123; | ||
|
||
// not errors, inferrable type is not declared | ||
function bar(a = 5, b = true, c = "bah") { } | ||
|
||
// not errors, types are not inferrable | ||
function baz(a: any = 5, b: any = true, c: any = "bah") { } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// errors, inferrable type is declared | ||
let x = 7; | ||
let y = false; | ||
let z = "foo"; | ||
|
||
// not errors, we are skipping params | ||
function foo (a: number = 5, b: boolean = true, c: string = "bah") { } | ||
|
||
class TestClass { | ||
doSomething(a: number = 5, b: boolean = true, c: string = "bah") {} | ||
} | ||
|
||
class Foo { | ||
bar = 0; | ||
baz = true, | ||
bas = "moar"; | ||
} | ||
|
||
// not errors, inferrable type is not declared | ||
let _x = 7; | ||
let _y = false; | ||
let _z = "foo"; | ||
|
||
// not error, type is not inferrable | ||
let weird: any = 123; | ||
|
||
// not errors, inferrable type is not declared | ||
function bar(a = 5, b = true, c = "bah") { } | ||
|
||
// not errors, types are not inferrable | ||
function baz(a: any = 5, b: any = true, c: any = "bah") { } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
test/rules/no-inferrable-types/ignore-properties/test.ts.fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// errors, inferrable type is declared | ||
let x = 7; | ||
let y = false; | ||
let z = "foo"; | ||
class C { | ||
x: number = 1; | ||
} | ||
|
||
// errors, types are inferrable | ||
function foo (a = 5, b = true, c = "bah") { } | ||
|
||
class Foo { | ||
bar: number = 0; | ||
baz: boolean = true, | ||
bas: string = "moar"; | ||
} | ||
|
||
// not errors, inferrable type is not declared | ||
let _x = 7; | ||
let _y = false; | ||
let _z = "foo"; | ||
|
||
// not error, type is not inferrable | ||
let weird: any = 123; | ||
|
||
// not errors, inferrable type is not declared | ||
function bar(a = 5, b = true, c = "bah") { } | ||
|
||
// not errors, types are not inferrable | ||
function baz(a: any = 5, b: any = true, c: any = "bah") { } | ||
|
40 changes: 40 additions & 0 deletions
40
test/rules/no-inferrable-types/ignore-properties/test.ts.lint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// errors, inferrable type is declared | ||
let x: number = 7; | ||
~~~~~~ [number] | ||
let y: boolean = false; | ||
~~~~~~~ [boolean] | ||
let z: string = "foo"; | ||
~~~~~~ [string] | ||
class C { | ||
x: number = 1; | ||
} | ||
|
||
// errors, types are inferrable | ||
function foo (a: number = 5, b: boolean = true, c: string = "bah") { } | ||
~~~~~~ [number] | ||
~~~~~~~ [boolean] | ||
~~~~~~ [string] | ||
|
||
class Foo { | ||
bar: number = 0; | ||
baz: boolean = true, | ||
bas: string = "moar"; | ||
} | ||
|
||
// not errors, inferrable type is not declared | ||
let _x = 7; | ||
let _y = false; | ||
let _z = "foo"; | ||
|
||
// not error, type is not inferrable | ||
let weird: any = 123; | ||
|
||
// not errors, inferrable type is not declared | ||
function bar(a = 5, b = true, c = "bah") { } | ||
|
||
// not errors, types are not inferrable | ||
function baz(a: any = 5, b: any = true, c: any = "bah") { } | ||
|
||
[number]: Type number trivially inferred from a number literal, remove type annotation | ||
[boolean]: Type boolean trivially inferred from a boolean literal, remove type annotation | ||
[string]: Type string trivially inferred from a string literal, remove type annotation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"no-inferrable-types": [true, "ignore-properties"] | ||
} | ||
} |