Skip to content

Commit

Permalink
Merge branch 'master' into noTimeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat committed Mar 9, 2020
2 parents 0351eea + b5b3be0 commit 054204a
Show file tree
Hide file tree
Showing 58 changed files with 5,527 additions and 1,253 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,30 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [2.23.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.22.0...v2.23.0) (2020-03-09)


### Bug Fixes

* **eslint-plugin:** [prefer-readonly-parameter-types] handle recursive types ([#1672](https://github.com/typescript-eslint/typescript-eslint/issues/1672)) ([e5db36f](https://github.com/typescript-eslint/typescript-eslint/commit/e5db36f140b6463965858ad4ed77f71a9a00c5a7)), closes [#1665](https://github.com/typescript-eslint/typescript-eslint/issues/1665)
* **eslint-plugin:** [type-annotation-spacing] handle constructor types ([#1664](https://github.com/typescript-eslint/typescript-eslint/issues/1664)) ([fbf1640](https://github.com/typescript-eslint/typescript-eslint/commit/fbf1640c5ab67770a1ace5a9bad2bddfa35bd88d)), closes [#1663](https://github.com/typescript-eslint/typescript-eslint/issues/1663)
* **eslint-plugin:** fix autofixer for computed properties ([#1662](https://github.com/typescript-eslint/typescript-eslint/issues/1662)) ([ba22ea7](https://github.com/typescript-eslint/typescript-eslint/commit/ba22ea7f604b236828ce4dcff75831ec1da01ec1))
* **eslint-plugin:** fix placeholder in `ban-ts-comment` ([#1703](https://github.com/typescript-eslint/typescript-eslint/issues/1703)) ([144345c](https://github.com/typescript-eslint/typescript-eslint/commit/144345c4774c0664752116ef2cf28f46cf52052f))


### Features

* **eslint-plugin:** [no-unsafe-call] support tagged templates ([#1680](https://github.com/typescript-eslint/typescript-eslint/issues/1680)) ([55a58ff](https://github.com/typescript-eslint/typescript-eslint/commit/55a58ff0ae0434970537657ec2cb0bc7ab64c13d))
* **eslint-plugin:** [no-unsafe-member-access] report any typed… ([#1683](https://github.com/typescript-eslint/typescript-eslint/issues/1683)) ([1543117](https://github.com/typescript-eslint/typescript-eslint/commit/1543117874047726a6bc1b71bd2f68779f266591))
* **eslint-plugin:** add rule no-unsafe-call ([#1647](https://github.com/typescript-eslint/typescript-eslint/issues/1647)) ([91423e4](https://github.com/typescript-eslint/typescript-eslint/commit/91423e49d19163fae7b03cbc79bb3cd3db8c2c6d))
* **eslint-plugin:** add rule no-unsafe-member-access ([#1643](https://github.com/typescript-eslint/typescript-eslint/issues/1643)) ([608a750](https://github.com/typescript-eslint/typescript-eslint/commit/608a750d53c39e892fdb982aeea9e4f9c5e2382d))
* **eslint-plugin:** add rule no-unsafe-return ([#1644](https://github.com/typescript-eslint/typescript-eslint/issues/1644)) ([cfc3ef1](https://github.com/typescript-eslint/typescript-eslint/commit/cfc3ef10941f46cdbc084e99e1d48d6d3a928903))
* **typescript-estree:** support 3.8 import/export type ([#1697](https://github.com/typescript-eslint/typescript-eslint/issues/1697)) ([625d603](https://github.com/typescript-eslint/typescript-eslint/commit/625d603f94bf0521f834313bf31c734ce4948b7a))





# [2.22.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.21.0...v2.22.0) (2020-03-02)


Expand Down
2 changes: 1 addition & 1 deletion lerna.json
@@ -1,5 +1,5 @@
{
"version": "2.22.0",
"version": "2.23.0",
"npmClient": "yarn",
"useWorkspaces": true,
"stream": true
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -74,9 +74,9 @@
"ts-jest": "^25.0.0",
"ts-node": "^8.5.0",
"tslint": "^5.20.1",
"typescript": ">=3.2.1 <3.8.0"
"typescript": ">=3.2.1 <3.9.0"
},
"resolutions": {
"typescript": "^3.7.2"
"typescript": "^3.8.3"
}
}
8 changes: 8 additions & 0 deletions packages/eslint-plugin-internal/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.

# [2.23.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.22.0...v2.23.0) (2020-03-09)

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





# [2.22.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.21.0...v2.22.0) (2020-03-02)

**Note:** Version bump only for package @typescript-eslint/eslint-plugin-internal
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin-internal/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin-internal",
"version": "2.22.0",
"version": "2.23.0",
"private": true,
"main": "dist/index.js",
"scripts": {
Expand All @@ -12,6 +12,6 @@
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@typescript-eslint/experimental-utils": "2.22.0"
"@typescript-eslint/experimental-utils": "2.23.0"
}
}
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.

# [2.23.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.22.0...v2.23.0) (2020-03-09)

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





# [2.22.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.21.0...v2.22.0) (2020-03-02)

**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": "2.22.0",
"version": "2.23.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 -p tsconfig.json --noEmit"
},
"dependencies": {
"@typescript-eslint/experimental-utils": "2.22.0",
"@typescript-eslint/experimental-utils": "2.23.0",
"lodash": "^4.17.15"
},
"peerDependencies": {
Expand All @@ -41,6 +41,6 @@
},
"devDependencies": {
"@types/lodash": "^4.14.149",
"@typescript-eslint/parser": "2.22.0"
"@typescript-eslint/parser": "2.23.0"
}
}
23 changes: 23 additions & 0 deletions packages/eslint-plugin/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.

# [2.23.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.22.0...v2.23.0) (2020-03-09)


### Bug Fixes

* **eslint-plugin:** [prefer-readonly-parameter-types] handle recursive types ([#1672](https://github.com/typescript-eslint/typescript-eslint/issues/1672)) ([e5db36f](https://github.com/typescript-eslint/typescript-eslint/commit/e5db36f140b6463965858ad4ed77f71a9a00c5a7)), closes [#1665](https://github.com/typescript-eslint/typescript-eslint/issues/1665)
* **eslint-plugin:** [type-annotation-spacing] handle constructor types ([#1664](https://github.com/typescript-eslint/typescript-eslint/issues/1664)) ([fbf1640](https://github.com/typescript-eslint/typescript-eslint/commit/fbf1640c5ab67770a1ace5a9bad2bddfa35bd88d)), closes [#1663](https://github.com/typescript-eslint/typescript-eslint/issues/1663)
* **eslint-plugin:** fix autofixer for computed properties ([#1662](https://github.com/typescript-eslint/typescript-eslint/issues/1662)) ([ba22ea7](https://github.com/typescript-eslint/typescript-eslint/commit/ba22ea7f604b236828ce4dcff75831ec1da01ec1))
* **eslint-plugin:** fix placeholder in `ban-ts-comment` ([#1703](https://github.com/typescript-eslint/typescript-eslint/issues/1703)) ([144345c](https://github.com/typescript-eslint/typescript-eslint/commit/144345c4774c0664752116ef2cf28f46cf52052f))


### Features

* **eslint-plugin:** [no-unsafe-call] support tagged templates ([#1680](https://github.com/typescript-eslint/typescript-eslint/issues/1680)) ([55a58ff](https://github.com/typescript-eslint/typescript-eslint/commit/55a58ff0ae0434970537657ec2cb0bc7ab64c13d))
* **eslint-plugin:** [no-unsafe-member-access] report any typed… ([#1683](https://github.com/typescript-eslint/typescript-eslint/issues/1683)) ([1543117](https://github.com/typescript-eslint/typescript-eslint/commit/1543117874047726a6bc1b71bd2f68779f266591))
* **eslint-plugin:** add rule no-unsafe-call ([#1647](https://github.com/typescript-eslint/typescript-eslint/issues/1647)) ([91423e4](https://github.com/typescript-eslint/typescript-eslint/commit/91423e49d19163fae7b03cbc79bb3cd3db8c2c6d))
* **eslint-plugin:** add rule no-unsafe-member-access ([#1643](https://github.com/typescript-eslint/typescript-eslint/issues/1643)) ([608a750](https://github.com/typescript-eslint/typescript-eslint/commit/608a750d53c39e892fdb982aeea9e4f9c5e2382d))
* **eslint-plugin:** add rule no-unsafe-return ([#1644](https://github.com/typescript-eslint/typescript-eslint/issues/1644)) ([cfc3ef1](https://github.com/typescript-eslint/typescript-eslint/commit/cfc3ef10941f46cdbc084e99e1d48d6d3a928903))





# [2.22.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.21.0...v2.22.0) (2020-03-02)


Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/docs/rules/no-namespace.md
Expand Up @@ -16,7 +16,7 @@ or more of the following you may pass an object with the options set as follows:

- `allowDeclarations` set to `true` will allow you to `declare` custom TypeScript modules and namespaces (Default: `false`).
- `allowDefinitionFiles` set to `true` will allow you to `declare` and use custom TypeScript modules and namespaces
inside definition files (Default: `false`).
inside definition files (Default: `true`).

Examples of **incorrect** code for the default `{ "allowDeclarations": false, "allowDefinitionFiles": false }` options:

Expand Down
5 changes: 5 additions & 0 deletions packages/eslint-plugin/docs/rules/no-unsafe-call.md
Expand Up @@ -21,6 +21,9 @@ nestedAny.prop['a']();

new anyVar();
new nestedAny.prop();

anyVar`foo`;
nestedAny.prop`foo`;
```

Examples of **correct** code for this rule:
Expand All @@ -33,6 +36,8 @@ nestedAny.prop.a();
(() => {})();

new Map();

String.raw`foo`;
```

## Related to
Expand Down
11 changes: 11 additions & 0 deletions packages/eslint-plugin/docs/rules/no-unsafe-member-access.md
Expand Up @@ -23,6 +23,11 @@ nestedAny.prop['a'];

const key = 'a';
nestedAny.prop[key];

// usng an any to access a member is unsafe
const arr = [1, 2, 3];
arr[anyVar];
nestedAny[anyVar];
```

Examples of **correct** code for this rule:
Expand All @@ -35,6 +40,12 @@ nestedAny.prop['a'];

const key = 'a';
nestedAny.prop[key];

const arr = [1, 2, 3];
arr[1];
const idx = 1;
arr[idx];
arr[idx++];
```

## Related to
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin",
"version": "2.22.0",
"version": "2.23.0",
"description": "TypeScript plugin for ESLint",
"keywords": [
"eslint",
Expand Down Expand Up @@ -41,7 +41,7 @@
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@typescript-eslint/experimental-utils": "2.22.0",
"@typescript-eslint/experimental-utils": "2.23.0",
"eslint-utils": "^1.4.3",
"functional-red-black-tree": "^1.0.1",
"regexpp": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/ban-ts-comment.ts
Expand Up @@ -28,7 +28,7 @@ export default util.createRule<[Options], MessageIds>({
},
messages: {
tsDirectiveComment:
'Do not use "// @ts-{directive}" because it alters compilation errors.',
'Do not use "// @ts-{{directive}}" because it alters compilation errors.',
},
schema: [
{
Expand Down
25 changes: 15 additions & 10 deletions packages/eslint-plugin/src/rules/no-unsafe-call.ts
@@ -1,7 +1,7 @@
import { TSESTree } from '@typescript-eslint/experimental-utils';
import * as util from '../util';

type MessageIds = 'unsafeCall' | 'unsafeNew';
type MessageIds = 'unsafeCall' | 'unsafeNew' | 'unsafeTemplateTag';

export default util.createRule<[], MessageIds>({
name: 'no-unsafe-call',
Expand All @@ -16,6 +16,7 @@ export default util.createRule<[], MessageIds>({
messages: {
unsafeCall: 'Unsafe call of an any typed value',
unsafeNew: 'Unsafe construction of an any type value',
unsafeTemplateTag: 'Unsafe any typed template tag',
},
schema: [],
},
Expand All @@ -25,14 +26,11 @@ export default util.createRule<[], MessageIds>({
const checker = program.getTypeChecker();

function checkCall(
node:
| TSESTree.CallExpression
| TSESTree.OptionalCallExpression
| TSESTree.NewExpression,
reportingNode: TSESTree.Expression = node.callee,
messageId: MessageIds = 'unsafeCall',
node: TSESTree.Node,
reportingNode: TSESTree.Node,
messageId: MessageIds,
): void {
const tsNode = esTreeNodeToTSNodeMap.get(node.callee);
const tsNode = esTreeNodeToTSNodeMap.get(node);
const type = checker.getTypeAtLocation(tsNode);
if (util.isTypeAnyType(type)) {
context.report({
Expand All @@ -43,9 +41,16 @@ export default util.createRule<[], MessageIds>({
}

return {
'CallExpression, OptionalCallExpression': checkCall,
'CallExpression, OptionalCallExpression'(
node: TSESTree.CallExpression | TSESTree.OptionalCallExpression,
): void {
checkCall(node.callee, node.callee, 'unsafeCall');
},
NewExpression(node): void {
checkCall(node, node, 'unsafeNew');
checkCall(node.callee, node, 'unsafeNew');
},
'TaggedTemplateExpression > *.tag'(node: TSESTree.Node): void {
checkCall(node, node, 'unsafeTemplateTag');
},
};
},
Expand Down
36 changes: 35 additions & 1 deletion packages/eslint-plugin/src/rules/no-unsafe-member-access.ts
@@ -1,4 +1,7 @@
import { TSESTree } from '@typescript-eslint/experimental-utils';
import {
TSESTree,
AST_NODE_TYPES,
} from '@typescript-eslint/experimental-utils';
import * as util from '../util';

const enum State {
Expand All @@ -19,6 +22,8 @@ export default util.createRule({
messages: {
unsafeMemberExpression:
'Unsafe member access {{property}} on an any value',
unsafeComputedMemberAccess:
'Computed name {{property}} resolves to an any value',
},
schema: [],
},
Expand Down Expand Up @@ -69,6 +74,35 @@ export default util.createRule({

return {
'MemberExpression, OptionalMemberExpression': checkMemberExpression,
':matches(MemberExpression, OptionalMemberExpression)[computed = true] > *.property'(
node: TSESTree.Expression,
): void {
if (
// x[1]
node.type === AST_NODE_TYPES.Literal ||
// x[1++] x[++x] etc
// FUN FACT - **all** update expressions return type number, regardless of the argument's type,
// because JS engines return NaN if there the argument is not a number.
node.type === AST_NODE_TYPES.UpdateExpression
) {
// perf optimizations - literals can obviously never be `any`
return;
}

const tsNode = esTreeNodeToTSNodeMap.get(node);
const type = checker.getTypeAtLocation(tsNode);

if (util.isTypeAnyType(type)) {
const propertyName = sourceCode.getText(node);
context.report({
node,
messageId: 'unsafeComputedMemberAccess',
data: {
property: `[${propertyName}]`,
},
});
}
},
};
},
});
8 changes: 4 additions & 4 deletions packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts
Expand Up @@ -113,7 +113,7 @@ ruleTester.run('ts-nocheck', rule, {
code: '// @ts-nocheck',
errors: [
{
data: { directive: 'check' },
data: { directive: 'nocheck' },
messageId: 'tsDirectiveComment',
line: 1,
column: 1,
Expand All @@ -124,7 +124,7 @@ ruleTester.run('ts-nocheck', rule, {
code: '// @ts-nocheck: Suppress next line',
errors: [
{
data: { directive: 'check' },
data: { directive: 'nocheck' },
messageId: 'tsDirectiveComment',
line: 1,
column: 1,
Expand All @@ -135,7 +135,7 @@ ruleTester.run('ts-nocheck', rule, {
code: '/////@ts-nocheck: Suppress next line',
errors: [
{
data: { directive: 'check' },
data: { directive: 'nocheck' },
messageId: 'tsDirectiveComment',
line: 1,
column: 1,
Expand All @@ -151,7 +151,7 @@ if (false) {
`,
errors: [
{
data: { directive: 'check' },
data: { directive: 'nocheck' },
messageId: 'tsDirectiveComment',
line: 3,
column: 3,
Expand Down

0 comments on commit 054204a

Please sign in to comment.