Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'typescript-eslint-use-default-type-parameter' of https:…
…//github.com/JoshuaKGoldberg/typescript-eslint into typescript-eslint-use-default-type-parameter
- Loading branch information
Showing
55 changed files
with
12,636 additions
and
6,846 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
open_collective: typescript-eslint |
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": "1.10.2", | ||
"version": "1.11.0", | ||
"npmClient": "yarn", | ||
"useWorkspaces": true, | ||
"stream": true | ||
|
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
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
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
74 changes: 74 additions & 0 deletions
74
packages/eslint-plugin/docs/rules/consistent-type-definitions.md
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,74 @@ | ||
# Consistent with type definition either `interface` or `type` (consistent-type-definitions) | ||
|
||
There are two ways to define a type. | ||
|
||
```ts | ||
// type alias | ||
type T1 = { | ||
a: string; | ||
b: number; | ||
}; | ||
|
||
// interface keyword | ||
interface T2 { | ||
a: string; | ||
b: number; | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
This rule accepts one string option: | ||
|
||
- `"interface"`: enforce using `interface`s for object type definitions. | ||
- `"type"`: enforce using `type`s for object type definitions. | ||
|
||
For example: | ||
|
||
```CJSON | ||
{ | ||
// Use type for object definitions | ||
"@typescript-eslint/consistent-type-definitions": ["error", "type"] | ||
} | ||
``` | ||
|
||
## Rule Details | ||
|
||
Examples of **incorrect** code with `interface` option. | ||
|
||
```ts | ||
type T = { x: number }; | ||
``` | ||
|
||
Examples of **correct** code with `interface` option. | ||
|
||
```ts | ||
type T = string; | ||
type Foo = string | {}; | ||
|
||
interface T { | ||
x: number; | ||
} | ||
``` | ||
|
||
Examples of **incorrect** code with `type` option. | ||
|
||
```ts | ||
interface T { | ||
x: number; | ||
} | ||
``` | ||
|
||
Examples of **correct** code with `type` option. | ||
|
||
```ts | ||
type T = { x: number }; | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
If you specifically want to use an interface or type literal for stylistic reasons, you can disable this rule. | ||
|
||
## Compatibility | ||
|
||
- TSLint: [interface-over-type-literal](https://palantir.github.io/tslint/rules/interface-over-type-literal/) |
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,47 @@ | ||
# Disallow Empty Functions (@typescript-eslint/no-empty-function) | ||
|
||
Empty functions can reduce readability because readers need to guess whether it’s intentional or not. So writing a clear comment for empty functions is a good practice. | ||
|
||
## Rule Details | ||
|
||
The `@typescript-eslint/no-empty-function` rule extends the `no-empty-function` rule from ESLint core, and adds support for handling Typescript specific code that would otherwise trigger the rule. | ||
|
||
One example of valid Typescript specific code that would otherwise trigger the `no-empty-function` rule is the use of [parameter properties](https://www.typescriptlang.org/docs/handbook/classes.html#parameter-properties) in constructor functions: | ||
|
||
```typescript | ||
class Person { | ||
constructor(private firstName: string, private surname: string) {} | ||
} | ||
``` | ||
|
||
The above code is functionally equivalent to: | ||
|
||
```typescript | ||
class Person { | ||
private firstName: string; | ||
private surname: string; | ||
|
||
constructor(firstName: string, surname: string) { | ||
this.firstName = firstName; | ||
this.surname = surname; | ||
} | ||
} | ||
``` | ||
|
||
Parameter properties enable both the _declaration_ and _initialization_ of member properties in a single location, avoiding the boilerplate & duplication that is common when initializing member properties from parameter values in a constructor function. | ||
|
||
In these cases, although the constructor has an empty function body, it is technically valid and should not trigger an error. | ||
|
||
See the [ESLint documentation](https://eslint.org/docs/rules/no-empty-function) for more details on the `no-empty-function` rule. | ||
|
||
## Rule Changes | ||
|
||
```cjson | ||
{ | ||
// note you must disable the base rule as it can report incorrect errors | ||
"no-empty-function": "off", | ||
"@typescript-eslint/no-empty-function": "error" | ||
} | ||
``` | ||
|
||
<sup>Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/no-empty-function.md)</sup> |
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
Oops, something went wrong.