Skip to content

Commit

Permalink
Merge branch 'typescript-eslint-use-default-type-parameter' of https:…
Browse files Browse the repository at this point in the history
…//github.com/JoshuaKGoldberg/typescript-eslint into typescript-eslint-use-default-type-parameter
  • Loading branch information
Josh Goldberg committed Jul 10, 2019
2 parents 5cc3715 + cb5a6e8 commit 0c381fb
Show file tree
Hide file tree
Showing 55 changed files with 12,636 additions and 6,846 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
@@ -0,0 +1 @@
open_collective: typescript-eslint
3 changes: 3 additions & 0 deletions .prettierignore
Expand Up @@ -8,3 +8,6 @@
packages/eslint-plugin-tslint/tests/test-tslint-rules-directory/alwaysFailRule.js
.github
packages/eslint-plugin/src/configs/*.json

# Ignore CHANGELOG.md files to avoid issues with automated release job
CHANGELOG.md
23 changes: 23 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,29 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [1.11.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.10.2...v1.11.0) (2019-06-23)


### Bug Fixes

* **eslint-plugin:** [no-magic-numbers] add support for enums ([#543](https://github.com/typescript-eslint/typescript-eslint/issues/543)) ([5c40d01](https://github.com/typescript-eslint/typescript-eslint/commit/5c40d01))
* **eslint-plugin:** [promise-function-async] allow any as return value ([#553](https://github.com/typescript-eslint/typescript-eslint/issues/553)) ([9a387b0](https://github.com/typescript-eslint/typescript-eslint/commit/9a387b0))
* **eslint-plugin:** Remove duplicated code ([#611](https://github.com/typescript-eslint/typescript-eslint/issues/611)) ([c4df4ff](https://github.com/typescript-eslint/typescript-eslint/commit/c4df4ff))
* **parser:** add simpleTraverse, replaces private ESLint util ([#628](https://github.com/typescript-eslint/typescript-eslint/issues/628)) ([aa206c4](https://github.com/typescript-eslint/typescript-eslint/commit/aa206c4))
* **typescript-estree:** fix more cases with double slash in JSX text ([#607](https://github.com/typescript-eslint/typescript-eslint/issues/607)) ([34cfa53](https://github.com/typescript-eslint/typescript-eslint/commit/34cfa53))


### Features

* **eslint-plugin:** [no-explicit-any] ignoreRestArgs ([#548](https://github.com/typescript-eslint/typescript-eslint/issues/548)) ([753ad75](https://github.com/typescript-eslint/typescript-eslint/commit/753ad75))
* **eslint-plugin:** add `consistent-type-definitions` rule ([#463](https://github.com/typescript-eslint/typescript-eslint/issues/463)) ([ec87d06](https://github.com/typescript-eslint/typescript-eslint/commit/ec87d06))
* **eslint-plugin:** add new rule no-empty-function ([#626](https://github.com/typescript-eslint/typescript-eslint/issues/626)) ([747bfcb](https://github.com/typescript-eslint/typescript-eslint/commit/747bfcb))
* **eslint-plugin:** add new rule no-floating-promises ([#495](https://github.com/typescript-eslint/typescript-eslint/issues/495)) ([61e6385](https://github.com/typescript-eslint/typescript-eslint/commit/61e6385))





## [1.10.2](https://github.com/typescript-eslint/typescript-eslint/compare/v1.10.1...v1.10.2) (2019-06-10)

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -76,7 +76,7 @@ For example:
var x: number = 1;
```

This is not valid JavaScript code, because it contains a so called type-annotation. When the TypeScript Compiler parses this code to produce a TypeScript AST, that `: number` syntax will be represented in the tree, and this is simply not something that ESLint can understand without additional help.
This is not valid JavaScript code, because it contains a so-called type annotation. When the TypeScript Compiler parses this code to produce a TypeScript AST, that `: number` syntax will be represented in the tree, and this is simply not something that ESLint can understand without additional help.

However, we can leverage the fact that ESLint has been designed with these use-cases in mind!

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
@@ -1,5 +1,5 @@
{
"version": "1.10.2",
"version": "1.11.0",
"npmClient": "yarn",
"useWorkspaces": true,
"stream": true
Expand Down
8 changes: 8 additions & 0 deletions packages/eslint-plugin-tslint/CHANGELOG.md
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [1.11.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.10.2...v1.11.0) (2019-06-23)

**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint





## [1.10.2](https://github.com/typescript-eslint/typescript-eslint/compare/v1.10.1...v1.10.2) (2019-06-10)

**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin-tslint/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin-tslint",
"version": "1.10.2",
"version": "1.11.0",
"main": "dist/index.js",
"typings": "src/index.ts",
"description": "TSLint wrapper plugin for ESLint",
Expand Down Expand Up @@ -31,7 +31,7 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@typescript-eslint/experimental-utils": "1.10.2",
"@typescript-eslint/experimental-utils": "1.11.0",
"lodash.memoize": "^4.1.2"
},
"peerDependencies": {
Expand All @@ -41,6 +41,6 @@
"devDependencies": {
"@types/json-schema": "^7.0.3",
"@types/lodash.memoize": "^4.1.4",
"@typescript-eslint/parser": "1.10.2"
"@typescript-eslint/parser": "1.11.0"
}
}
20 changes: 20 additions & 0 deletions packages/eslint-plugin/CHANGELOG.md
Expand Up @@ -3,6 +3,26 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [1.11.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.10.2...v1.11.0) (2019-06-23)


### Bug Fixes

* **eslint-plugin:** [no-magic-numbers] add support for enums ([#543](https://github.com/typescript-eslint/typescript-eslint/issues/543)) ([5c40d01](https://github.com/typescript-eslint/typescript-eslint/commit/5c40d01))
* **eslint-plugin:** [promise-function-async] allow any as return value ([#553](https://github.com/typescript-eslint/typescript-eslint/issues/553)) ([9a387b0](https://github.com/typescript-eslint/typescript-eslint/commit/9a387b0))


### Features

* **eslint-plugin:** [no-explicit-any] ignoreRestArgs ([#548](https://github.com/typescript-eslint/typescript-eslint/issues/548)) ([753ad75](https://github.com/typescript-eslint/typescript-eslint/commit/753ad75))
* **eslint-plugin:** add `consistent-type-definitions` rule ([#463](https://github.com/typescript-eslint/typescript-eslint/issues/463)) ([ec87d06](https://github.com/typescript-eslint/typescript-eslint/commit/ec87d06))
* **eslint-plugin:** add new rule no-empty-function ([#626](https://github.com/typescript-eslint/typescript-eslint/issues/626)) ([747bfcb](https://github.com/typescript-eslint/typescript-eslint/commit/747bfcb))
* **eslint-plugin:** add new rule no-floating-promises ([#495](https://github.com/typescript-eslint/typescript-eslint/issues/495)) ([61e6385](https://github.com/typescript-eslint/typescript-eslint/commit/61e6385))





## [1.10.2](https://github.com/typescript-eslint/typescript-eslint/compare/v1.10.1...v1.10.2) (2019-06-10)

### Bug Fixes
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin/README.md
Expand Up @@ -131,6 +131,7 @@ Then you should add `airbnb` (or `airbnb-base`) to your `extends` section of `.e
| [`@typescript-eslint/ban-types`](./docs/rules/ban-types.md) | Enforces that types will not to be used | :heavy_check_mark: | :wrench: | |
| [`@typescript-eslint/camelcase`](./docs/rules/camelcase.md) | Enforce camelCase naming convention | :heavy_check_mark: | | |
| [`@typescript-eslint/class-name-casing`](./docs/rules/class-name-casing.md) | Require PascalCased class and interface names | :heavy_check_mark: | | |
| [`@typescript-eslint/consistent-type-definitions`](./docs/rules/consistent-type-definitions.md) | Consistent with type definition either `interface` or `type` | :heavy_check_mark: | :wrench: | |
| [`@typescript-eslint/explicit-function-return-type`](./docs/rules/explicit-function-return-type.md) | Require explicit return types on functions and class methods | :heavy_check_mark: | | |
| [`@typescript-eslint/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) | Require explicit accessibility modifiers on class properties and methods | :heavy_check_mark: | | |
| [`@typescript-eslint/func-call-spacing`](./docs/rules/func-call-spacing.md) | Require or disallow spacing between function identifiers and their invocations | | :wrench: | |
Expand All @@ -142,6 +143,7 @@ Then you should add `airbnb` (or `airbnb-base`) to your `extends` section of `.e
| [`@typescript-eslint/member-ordering`](./docs/rules/member-ordering.md) | Require a consistent member declaration order | | | |
| [`@typescript-eslint/no-angle-bracket-type-assertion`](./docs/rules/no-angle-bracket-type-assertion.md) | Enforces the use of `as Type` assertions instead of `<Type>` assertions | :heavy_check_mark: | | |
| [`@typescript-eslint/no-array-constructor`](./docs/rules/no-array-constructor.md) | Disallow generic `Array` constructors | :heavy_check_mark: | :wrench: | |
| [`@typescript-eslint/no-empty-function`](./docs/rules/no-empty-function.md) | Disallow empty functions | | | |
| [`@typescript-eslint/no-empty-interface`](./docs/rules/no-empty-interface.md) | Disallow the declaration of empty interfaces | :heavy_check_mark: | | |
| [`@typescript-eslint/no-explicit-any`](./docs/rules/no-explicit-any.md) | Disallow usage of the `any` type | :heavy_check_mark: | | |
| [`@typescript-eslint/no-extra-parens`](./docs/rules/no-extra-parens.md) | Disallow unnecessary parentheses | | :wrench: | |
Expand All @@ -168,7 +170,6 @@ Then you should add `airbnb` (or `airbnb-base`) to your `extends` section of `.e
| [`@typescript-eslint/prefer-for-of`](./docs/rules/prefer-for-of.md) | Prefer a ‘for-of’ loop over a standard ‘for’ loop if the index is only used to access the array being iterated | | | |
| [`@typescript-eslint/prefer-function-type`](./docs/rules/prefer-function-type.md) | Use function types instead of interfaces with call signatures | | :wrench: | |
| [`@typescript-eslint/prefer-includes`](./docs/rules/prefer-includes.md) | Enforce `includes` method over `indexOf` method | | :wrench: | :thought_balloon: |
| [`@typescript-eslint/prefer-interface`](./docs/rules/prefer-interface.md) | Prefer an interface declaration over a type literal (type T = { ... }) | :heavy_check_mark: | :wrench: | |
| [`@typescript-eslint/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) | Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules | :heavy_check_mark: | :wrench: | |
| [`@typescript-eslint/prefer-regexp-exec`](./docs/rules/prefer-regexp-exec.md) | Prefer RegExp#exec() over String#match() if no global flag is provided | | | :thought_balloon: |
| [`@typescript-eslint/prefer-string-starts-ends-with`](./docs/rules/prefer-string-starts-ends-with.md) | Enforce the use of `String#startsWith` and `String#endsWith` instead of other equivalent methods of checking substrings | | :wrench: | :thought_balloon: |
Expand Down
4 changes: 3 additions & 1 deletion packages/eslint-plugin/ROADMAP.md
Expand Up @@ -14,7 +14,7 @@
| --------------------------------- | :-: | ---------------------------------------------------- |
| [`adjacent-overload-signatures`] || [`@typescript-eslint/adjacent-overload-signatures`] |
| [`ban-ts-ignore`] || [`@typescript-eslint/ban-ts-ignore`] |
| [`ban-types`] | | [`@typescript-eslint/ban-types`] |
| [`ban-types`] | 🌓 | [`@typescript-eslint/ban-types`]<sup>[1]</sup> |
| [`member-access`] || [`@typescript-eslint/explicit-member-accessibility`] |
| [`member-ordering`] || [`@typescript-eslint/member-ordering`] |
| [`no-any`] || [`@typescript-eslint/no-explicit-any`] |
Expand All @@ -36,6 +36,8 @@
| [`typedef-whitespace`] || [`@typescript-eslint/type-annotation-spacing`] |
| [`unified-signatures`] || [`@typescript-eslint/unified-signatures`] |

<sup>[1]</sup> The ESLint rule only supports exact string matching, rather than regular expressions<br>

### Functionality

| TSLint rule | | ESLint rule |
Expand Down
74 changes: 74 additions & 0 deletions packages/eslint-plugin/docs/rules/consistent-type-definitions.md
@@ -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/)
47 changes: 47 additions & 0 deletions packages/eslint-plugin/docs/rules/no-empty-function.md
@@ -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>
48 changes: 47 additions & 1 deletion packages/eslint-plugin/docs/rules/no-explicit-any.md
Expand Up @@ -5,7 +5,7 @@ When `any` is used, all compiler type checks around that value are ignored.

## Rule Details

This rule goes doesn't allow `any` types to be defined.
This rule doesn't allow `any` types to be defined.
It aims to keep TypeScript maximally useful.
TypeScript has a compiler flag for `--noImplicitAny` that will prevent
an `any` type from being implied by the compiler, but doesn't prevent
Expand Down Expand Up @@ -87,6 +87,52 @@ function greet(param: Array<string>): string {}
function greet(param: Array<string>): Array<string> {}
```

### ignoreRestArgs

A boolean to specify if arrays from the rest operator are considered okay. `false` by default.

Examples of **incorrect** code for the `{ "ignoreRestArgs": false }` option:

```ts
/*eslint @typescript-eslint/no-explicit-any: ["error", { "ignoreRestArgs": false }]*/

function foo1(...args: any[]): void {}
function foo2(...args: readonly any[]): void {}
function foo3(...args: Array<any>): void {}
function foo4(...args: ReadonlyArray<any>): void {}

const bar1 = (...args: any[]): void {}
const bar2 = (...args: readonly any[]): void {}
const bar3 = (...args: Array<any>): void {}
const bar4 = (...args: ReadonlyArray<any>): void {}

const baz1 = function (...args: any[]) {}
const baz2 = function (...args: readonly any[]) {}
const baz3 = function (...args: Array<any>) {}
const baz4 = function (...args: ReadonlyArray<any>) {}
```

Examples of **correct** code for the `{ "ignoreRestArgs": true }` option:

```ts
/*eslint @typescript-eslint/no-explicit-any: ["error", { "ignoreRestArgs": true }]*/

function foo1(...args: any[]): void {}
function foo2(...args: readonly any[]): void {}
function foo3(...args: Array<any>): void {}
function foo4(...args: ReadonlyArray<any>): void {}

const bar1 = (...args: any[]): void {}
const bar2 = (...args: readonly any[]): void {}
const bar3 = (...args: Array<any>): void {}
const bar4 = (...args: ReadonlyArray<any>): void {}

const baz1 = function (...args: any[]) {}
const baz2 = function (...args: readonly any[]) {}
const baz3 = function (...args: Array<any>) {}
const baz4 = function (...args: ReadonlyArray<any>) {}
```

## When Not To Use It

If an unknown type or a library without typings is used
Expand Down

0 comments on commit 0c381fb

Please sign in to comment.