Skip to content

Commit

Permalink
Merge branch 'master' into method-signature-style
Browse files Browse the repository at this point in the history
  • Loading branch information
phaux committed Apr 3, 2020
2 parents b9f505d + ead0171 commit 932ae62
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/eslint-plugin-tslint.md
Expand Up @@ -15,7 +15,7 @@ The more relevant information you can include, the faster we can find the issue

<!--
Make sure you read through our FAQ before posting.
https://github.com/typescript-eslint/typescript-eslint/blob/issue-template-update/docs/getting-started/linting/FAQ.md
https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md
-->

**Repro**
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/eslint-plugin-typescript.md
Expand Up @@ -28,7 +28,7 @@ Are you opening an issue because the rule you're trying to use is not found?

<!--
Make sure you read through our FAQ before posting.
https://github.com/typescript-eslint/typescript-eslint/blob/issue-template-update/docs/getting-started/linting/FAQ.md
https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md
-->

**Repro**
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/typescript-eslint-parser.md
Expand Up @@ -15,7 +15,7 @@ The more relevant information you can include, the faster we can find the issue

<!--
Make sure you read through our FAQ before posting.
https://github.com/typescript-eslint/typescript-eslint/blob/issue-template-update/docs/getting-started/linting/FAQ.md
https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md
-->

**Repro**
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/typescript-eslint-utils.md
Expand Up @@ -15,7 +15,7 @@ The more relevant information you can include, the faster we can find the issue

<!--
Make sure you read through our FAQ before posting.
https://github.com/typescript-eslint/typescript-eslint/blob/issue-template-update/docs/getting-started/linting/FAQ.md
https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md
-->

**Repro**
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/typescript-estree.md
Expand Up @@ -15,7 +15,7 @@ The more relevant information you can include, the faster we can find the issue

<!--
Make sure you read through our FAQ before posting.
https://github.com/typescript-eslint/typescript-eslint/blob/issue-template-update/docs/getting-started/linting/FAQ.md
https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md
-->

**Repro**
Expand Down
76 changes: 31 additions & 45 deletions packages/eslint-plugin/docs/rules/no-explicit-any.md
Expand Up @@ -119,30 +119,23 @@ 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 {}
declare function bar(...args: 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>) {}
const baz = (...args: any[]) => {};
const qux = function(...args: any[]) {};

interface Qux1 { (...args: any[]): void; }
interface Qux2 { (...args: readonly any[]): void; }
interface Qux3 { (...args: Array<any>): void; }
interface Qux4 { (...args: ReadonlyArray<any>): void; }
type Quux = (...args: any[]) => void;
type Quuz = new (...args: any[]) => void;

function quux1(fn: (...args: any[]) => void): void {}
function quux2(fn: (...args: readonly any[]) => void): void {}
function quux3(fn: (...args: Array<any>) => void): void {}
function quux4(fn: (...args: ReadonlyArray<any>) => void): void {}

function quuz1(): ((...args: any[]) => void) {}
function quuz2(): ((...args: readonly any[]) => void) {}
function quuz3(): ((...args: Array<any>) => void) {}
function quuz4(): ((...args: ReadonlyArray<any>) => void) {}
interface Grault {
(...args: any[]): void;
}
interface Corge {
new (...args: any[]): void;
}
interface Garply {
f(...args: any[]): void;
}
```

Examples of **correct** code for the `{ "ignoreRestArgs": true }` option:
Expand All @@ -155,30 +148,23 @@ 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>) {}

interface Qux1 { (...args: any[]): void; }
interface Qux2 { (...args: readonly any[]): void; }
interface Qux3 { (...args: Array<any>): void; }
interface Qux4 { (...args: ReadonlyArray<any>): void; }

function quux1(fn: (...args: any[]) => void): void {}
function quux2(fn: (...args: readonly any[]) => void): void {}
function quux3(fn: (...args: Array<any>) => void): void {}
function quux4(fn: (...args: ReadonlyArray<any>) => void): void {}

function quuz1(): ((...args: any[]) => void) {}
function quuz2(): ((...args: readonly any[]) => void) {}
function quuz3(): ((...args: Array<any>) => void) {}
function quuz4(): ((...args: ReadonlyArray<any>) => void) {}
declare function bar(...args: any[]): void;

const baz = (...args: any[]) => {};
const qux = function(...args: any[]) {};

type Quux = (...args: any[]) => void;
type Quuz = new (...args: any[]) => void;

interface Grault {
(...args: any[]): void;
}
interface Corge {
new (...args: any[]): void;
}
interface Garply {
f(...args: any[]): void;
}
```

## When Not To Use It
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/docs/rules/no-type-alias.md
Expand Up @@ -69,7 +69,7 @@ On the other hand, using a type alias as an interface can limit your ability to:
- Debug your code: interfaces create a new name, so is easy to identify the base type of an object
while debugging the application.

Finally, mapping types is an advance technique, leaving it open can quickly become a pain point
Finally, mapping types is an advanced technique and leaving it open can quickly become a pain point
in your application.

## Rule Details
Expand Down
19 changes: 12 additions & 7 deletions packages/eslint-plugin/src/rules/no-explicit-any.ts
Expand Up @@ -53,18 +53,23 @@ export default util.createRule<Options, MessageIds>({
],
create(context, [{ ignoreRestArgs, fixToUnknown }]) {
/**
* Checks if the node is an arrow function, function declaration or function expression
* Checks if the node is an arrow function, function/constructor declaration or function expression
* @param node the node to be validated.
* @returns true if the node is an arrow function, function declaration, function expression, function type, or call signature
* @returns true if the node is any kind of function declaration or expression
* @private
*/
function isNodeValidFunction(node: TSESTree.Node): boolean {
return [
AST_NODE_TYPES.ArrowFunctionExpression,
AST_NODE_TYPES.FunctionDeclaration,
AST_NODE_TYPES.FunctionExpression,
AST_NODE_TYPES.TSFunctionType,
AST_NODE_TYPES.TSCallSignatureDeclaration,
AST_NODE_TYPES.ArrowFunctionExpression, // const x = (...args: any[]) => {};
AST_NODE_TYPES.FunctionDeclaration, // function f(...args: any[]) {}
AST_NODE_TYPES.FunctionExpression, // const x = function(...args: any[]) {};
AST_NODE_TYPES.TSEmptyBodyFunctionExpression, // declare class A { f(...args: any[]): unknown; }
AST_NODE_TYPES.TSFunctionType, // type T = (...args: any[]) => unknown;
AST_NODE_TYPES.TSConstructorType, // type T = new (...args: any[]) => unknown
AST_NODE_TYPES.TSCallSignatureDeclaration, // type T = {(...args: any[]): unknown};
AST_NODE_TYPES.TSConstructSignatureDeclaration, // type T = {new (...args: any[]): unknown};
AST_NODE_TYPES.TSMethodSignature, // type T = {f(...args: any[]): unknown};
AST_NODE_TYPES.TSDeclareFunction, // declare function _8(...args: any[]): unknown;
].includes(node.type);
}

Expand Down

0 comments on commit 932ae62

Please sign in to comment.