diff --git a/CHANGELOG.md b/CHANGELOG.md
index f0d9d32f580c..504afb47d025 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,23 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [4.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.2.0...v4.3.0) (2020-09-28)
+
+
+### Bug Fixes
+
+* **eslint-plugin:** added safe getTypeOfPropertyOfType wrapper ([#2567](https://github.com/typescript-eslint/typescript-eslint/issues/2567)) ([7cba2de](https://github.com/typescript-eslint/typescript-eslint/commit/7cba2de138542563d678fbfc738cd1b3ebf01e07))
+* **experimental-utils:** treat RuleTester arrays as readonly ([#2601](https://github.com/typescript-eslint/typescript-eslint/issues/2601)) ([8025777](https://github.com/typescript-eslint/typescript-eslint/commit/80257776b78bd2b2b4389d6bd530b009a75fb520))
+
+
+### Features
+
+* **eslint-plugin:** [no-invalid-void-type] add option to allow `this: void` ([#2481](https://github.com/typescript-eslint/typescript-eslint/issues/2481)) ([ddf5660](https://github.com/typescript-eslint/typescript-eslint/commit/ddf5660846784003cab4b10ae7a5e510b9dd562b))
+
+
+
+
+
# [4.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.1.1...v4.2.0) (2020-09-21)
diff --git a/lerna.json b/lerna.json
index 60d71ebb777a..cdce5135a1dd 100644
--- a/lerna.json
+++ b/lerna.json
@@ -1,5 +1,5 @@
{
- "version": "4.2.0",
+ "version": "4.3.0",
"npmClient": "yarn",
"useWorkspaces": true,
"stream": true
diff --git a/packages/eslint-plugin-internal/CHANGELOG.md b/packages/eslint-plugin-internal/CHANGELOG.md
index 601b9c9ddbf4..b547950da658 100644
--- a/packages/eslint-plugin-internal/CHANGELOG.md
+++ b/packages/eslint-plugin-internal/CHANGELOG.md
@@ -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.
+# [4.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.2.0...v4.3.0) (2020-09-28)
+
+**Note:** Version bump only for package @typescript-eslint/eslint-plugin-internal
+
+
+
+
+
# [4.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.1.1...v4.2.0) (2020-09-21)
**Note:** Version bump only for package @typescript-eslint/eslint-plugin-internal
diff --git a/packages/eslint-plugin-internal/package.json b/packages/eslint-plugin-internal/package.json
index 51b8a4b28d68..665d964e8e71 100644
--- a/packages/eslint-plugin-internal/package.json
+++ b/packages/eslint-plugin-internal/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin-internal",
- "version": "4.2.0",
+ "version": "4.3.0",
"private": true,
"main": "dist/index.js",
"scripts": {
@@ -14,7 +14,7 @@
},
"dependencies": {
"@types/prettier": "*",
- "@typescript-eslint/experimental-utils": "4.2.0",
+ "@typescript-eslint/experimental-utils": "4.3.0",
"prettier": "*"
}
}
diff --git a/packages/eslint-plugin-tslint/CHANGELOG.md b/packages/eslint-plugin-tslint/CHANGELOG.md
index 8683c9ff8fdf..bb34688171a6 100644
--- a/packages/eslint-plugin-tslint/CHANGELOG.md
+++ b/packages/eslint-plugin-tslint/CHANGELOG.md
@@ -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.
+# [4.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.2.0...v4.3.0) (2020-09-28)
+
+**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint
+
+
+
+
+
# [4.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.1.1...v4.2.0) (2020-09-21)
**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint
diff --git a/packages/eslint-plugin-tslint/package.json b/packages/eslint-plugin-tslint/package.json
index a84d1bdc8acc..9ea12ed75d99 100644
--- a/packages/eslint-plugin-tslint/package.json
+++ b/packages/eslint-plugin-tslint/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin-tslint",
- "version": "4.2.0",
+ "version": "4.3.0",
"main": "dist/index.js",
"typings": "src/index.ts",
"description": "TSLint wrapper plugin for ESLint",
@@ -38,7 +38,7 @@
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
- "@typescript-eslint/experimental-utils": "4.2.0",
+ "@typescript-eslint/experimental-utils": "4.3.0",
"lodash": "^4.17.15"
},
"peerDependencies": {
@@ -48,6 +48,6 @@
},
"devDependencies": {
"@types/lodash": "*",
- "@typescript-eslint/parser": "4.2.0"
+ "@typescript-eslint/parser": "4.3.0"
}
}
diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md
index 808a0022292b..eb0a0c0db51d 100644
--- a/packages/eslint-plugin/CHANGELOG.md
+++ b/packages/eslint-plugin/CHANGELOG.md
@@ -3,6 +3,23 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [4.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.2.0...v4.3.0) (2020-09-28)
+
+
+### Bug Fixes
+
+* **eslint-plugin:** added safe getTypeOfPropertyOfType wrapper ([#2567](https://github.com/typescript-eslint/typescript-eslint/issues/2567)) ([7cba2de](https://github.com/typescript-eslint/typescript-eslint/commit/7cba2de138542563d678fbfc738cd1b3ebf01e07))
+* **experimental-utils:** treat RuleTester arrays as readonly ([#2601](https://github.com/typescript-eslint/typescript-eslint/issues/2601)) ([8025777](https://github.com/typescript-eslint/typescript-eslint/commit/80257776b78bd2b2b4389d6bd530b009a75fb520))
+
+
+### Features
+
+* **eslint-plugin:** [no-invalid-void-type] add option to allow `this: void` ([#2481](https://github.com/typescript-eslint/typescript-eslint/issues/2481)) ([ddf5660](https://github.com/typescript-eslint/typescript-eslint/commit/ddf5660846784003cab4b10ae7a5e510b9dd562b))
+
+
+
+
+
# [4.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.1.1...v4.2.0) (2020-09-21)
diff --git a/packages/eslint-plugin/docs/rules/ban-types.md b/packages/eslint-plugin/docs/rules/ban-types.md
index 9f279ea7ba57..ab8320d10dc7 100644
--- a/packages/eslint-plugin/docs/rules/ban-types.md
+++ b/packages/eslint-plugin/docs/rules/ban-types.md
@@ -46,7 +46,7 @@ Example configuration:
{
"types": {
// add a custom message to help explain why not to use it
- "Foo": "Don't use Far because it is unsafe",
+ "Foo": "Don't use Foo because it is unsafe",
// add a custom message, AND tell the plugin how to fix it
"String": {
diff --git a/packages/eslint-plugin/docs/rules/consistent-type-definitions.md b/packages/eslint-plugin/docs/rules/consistent-type-definitions.md
index 1688552d8f0f..52afd3f9a81c 100644
--- a/packages/eslint-plugin/docs/rules/consistent-type-definitions.md
+++ b/packages/eslint-plugin/docs/rules/consistent-type-definitions.md
@@ -25,10 +25,10 @@ This rule accepts one string option:
For example:
-```CJSON
+```jsonc
{
- // Use type for object definitions
- "@typescript-eslint/consistent-type-definitions": ["error", "type"]
+ // Use type for object definitions
+ "@typescript-eslint/consistent-type-definitions": ["error", "type"]
}
```
diff --git a/packages/eslint-plugin/docs/rules/dot-notation.md b/packages/eslint-plugin/docs/rules/dot-notation.md
index f827b003e57b..bd1ea7487df6 100644
--- a/packages/eslint-plugin/docs/rules/dot-notation.md
+++ b/packages/eslint-plugin/docs/rules/dot-notation.md
@@ -7,7 +7,7 @@ It adds support for optionally ignoring computed `private` member access.
## How to use
-```cjson
+```jsonc
{
// note you must disable the base rule as it can report incorrect errors
"dot-notation": "off",
diff --git a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md
index 3cafe4224eb8..9e5b4c841bf2 100644
--- a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md
+++ b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md
@@ -69,6 +69,8 @@ type Options = {
allowTypedFunctionExpressions?: boolean;
// if true, functions immediately returning another function expression will not be checked
allowHigherOrderFunctions?: boolean;
+ // if true, arrow functions immediately returning a `as const` value will not be checked
+ allowDirectConstAssertionInArrowFunctions?: boolean;
// if true, concise arrow functions that start with the void keyword will not be checked
allowConciseArrowFunctionExpressionsStartingWithVoid?: boolean;
};
@@ -77,6 +79,7 @@ const defaults = {
allowExpressions: false,
allowTypedFunctionExpressions: true,
allowHigherOrderFunctions: true,
+ allowDirectConstAssertionInArrowFunctions: true,
allowConciseArrowFunctionExpressionsStartingWithVoid: true,
};
```
@@ -201,6 +204,22 @@ function fn() {
}
```
+### `allowDirectConstAssertionInArrowFunctions`
+
+Examples of **incorrect** code for this rule with `{ allowDirectConstAssertionInArrowFunctions: true }`:
+
+```ts
+const func = (value: number) => ({ type: 'X', value } as any);
+const func = (value: number) => ({ type: 'X', value } as Action);
+```
+
+Examples of **correct** code for this rule with `{ allowDirectConstAssertionInArrowFunctions: true }`:
+
+```ts
+const func = (value: number) => ({ foo: 'bar', value } as const);
+const func = () => x as const;
+```
+
### `allowConciseArrowFunctionExpressionsStartingWithVoid`
Examples of **incorrect** code for this rule with `{ allowConciseArrowFunctionExpressionsStartingWithVoid: true }`:
diff --git a/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md b/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md
index 9b148d95c85f..cfbb3154f902 100644
--- a/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md
+++ b/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md
@@ -258,6 +258,10 @@ class Animal {
class Animal {
constructor(public animalName: string) {}
}
+
+class Animal {
+ constructor(animalName: string) {}
+}
```
e.g. `[ { accessibility: 'off', overrides: { parameterProperties: 'no-public' } } ]`
diff --git a/packages/eslint-plugin/docs/rules/init-declarations.md b/packages/eslint-plugin/docs/rules/init-declarations.md
index 8888e2efef27..f83c5bd9c3f4 100644
--- a/packages/eslint-plugin/docs/rules/init-declarations.md
+++ b/packages/eslint-plugin/docs/rules/init-declarations.md
@@ -7,7 +7,7 @@ It adds support for TypeScript's `declare` variables.
## How to use
-```cjson
+```jsonc
{
// note you must disable the base rule as it can report incorrect errors
"init-declarations": "off",
diff --git a/packages/eslint-plugin/docs/rules/keyword-spacing.md b/packages/eslint-plugin/docs/rules/keyword-spacing.md
index ca2926d6c825..3178542d2d68 100644
--- a/packages/eslint-plugin/docs/rules/keyword-spacing.md
+++ b/packages/eslint-plugin/docs/rules/keyword-spacing.md
@@ -7,7 +7,7 @@ This version adds support for generic type parameters on function calls.
## How to use
-```cjson
+```jsonc
{
// note you must disable the base rule as it can report incorrect errors
"keyword-spacing": "off",
diff --git a/packages/eslint-plugin/docs/rules/lines-between-class-members.md b/packages/eslint-plugin/docs/rules/lines-between-class-members.md
index 06cdf55421ee..e2692bb18a0c 100644
--- a/packages/eslint-plugin/docs/rules/lines-between-class-members.md
+++ b/packages/eslint-plugin/docs/rules/lines-between-class-members.md
@@ -11,7 +11,7 @@ See the [ESLint documentation](https://eslint.org/docs/rules/lines-between-class
## Rule Changes
-```cjson
+```jsonc
{
// note you must disable the base rule as it can report incorrect errors
"lines-between-class-members": "off",
diff --git a/packages/eslint-plugin/docs/rules/no-empty-function.md b/packages/eslint-plugin/docs/rules/no-empty-function.md
index 071584e99069..356700d834ea 100644
--- a/packages/eslint-plugin/docs/rules/no-empty-function.md
+++ b/packages/eslint-plugin/docs/rules/no-empty-function.md
@@ -75,4 +75,16 @@ class Foo {
}
```
+## How to use
+
+```jsonc
+{
+ // note you must disable the base rule as it can report incorrect errors
+ "no-empty-function": "off",
+ "@typescript-eslint/no-empty-function": ["error"]
+}
+```
+
+---
+
Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/no-empty-function.md)
diff --git a/packages/eslint-plugin/docs/rules/no-implied-eval.md b/packages/eslint-plugin/docs/rules/no-implied-eval.md
index 3753adf26d7b..a03ce7279352 100644
--- a/packages/eslint-plugin/docs/rules/no-implied-eval.md
+++ b/packages/eslint-plugin/docs/rules/no-implied-eval.md
@@ -88,6 +88,16 @@ class Foo {
setTimeout(Foo.fn, 100);
```
+## How to use
+
+```jsonc
+{
+ // note you must disable the base rule as it can report incorrect errors
+ "no-implied-eval": "off",
+ "@typescript-eslint/no-implied-eval": ["error"]
+}
+```
+
## When Not To Use It
If you want to allow `new Function()` or `setTimeout()`, `setInterval()`, `setImmediate()` and `execScript()` with string arguments, then you can safely disable this rule.
diff --git a/packages/eslint-plugin/docs/rules/no-invalid-this.md b/packages/eslint-plugin/docs/rules/no-invalid-this.md
index ac9dc30122c4..728c42b7f2cf 100644
--- a/packages/eslint-plugin/docs/rules/no-invalid-this.md
+++ b/packages/eslint-plugin/docs/rules/no-invalid-this.md
@@ -7,7 +7,7 @@ It adds support for TypeScript's `this` parameters.
## How to use
-```cjson
+```jsonc
{
// note you must disable the base rule as it can report incorrect errors
"no-invalid-this": "off",
diff --git a/packages/eslint-plugin/docs/rules/no-invalid-void-type.md b/packages/eslint-plugin/docs/rules/no-invalid-void-type.md
index f1607478a0d8..567d9c0bb33e 100644
--- a/packages/eslint-plugin/docs/rules/no-invalid-void-type.md
+++ b/packages/eslint-plugin/docs/rules/no-invalid-void-type.md
@@ -54,10 +54,12 @@ type stillVoid = void | never;
```ts
interface Options {
allowInGenericTypeArguments?: boolean | string[];
+ allowAsThisParameter?: boolean;
}
const defaultOptions: Options = {
allowInGenericTypeArguments: true,
+ allowAsThisParameter: false,
};
```
@@ -97,6 +99,23 @@ type AllowedVoid = Ex.Mx.Tx;
type AllowedVoidUnion = void | Ex.Mx.Tx;
```
+#### `allowAsThisParameter`
+
+This option allows specifying a `this` parameter of a function to be `void` when set to `true`.
+This pattern can be useful to explicitly label function types that do not use a `this` argument. [See the TypeScript docs for more information](https://www.typescriptlang.org/docs/handbook/functions.html#this-parameters-in-callbacks).
+
+This option is `false` by default.
+
+The following patterns are considered warnings with `{ allowAsThisParameter: false }` but valid with `{ allowAsThisParameter: true }`:
+
+```ts
+function doThing(this: void) {}
+class Example {
+ static helper(this: void) {}
+ callback(this: void) {}
+}
+```
+
## When Not To Use It
If you don't care about if `void` is used with other types,
diff --git a/packages/eslint-plugin/docs/rules/no-loop-func.md b/packages/eslint-plugin/docs/rules/no-loop-func.md
index d48d38c20f6f..d4e66d6c7de7 100644
--- a/packages/eslint-plugin/docs/rules/no-loop-func.md
+++ b/packages/eslint-plugin/docs/rules/no-loop-func.md
@@ -7,7 +7,7 @@ It adds support for TypeScript types.
## How to use
-```cjson
+```jsonc
{
// note you must disable the base rule as it can report incorrect errors
"no-loop-func": "off",
diff --git a/packages/eslint-plugin/docs/rules/no-throw-literal.md b/packages/eslint-plugin/docs/rules/no-throw-literal.md
index 3b7ee9c2d977..0b89f10e9276 100644
--- a/packages/eslint-plugin/docs/rules/no-throw-literal.md
+++ b/packages/eslint-plugin/docs/rules/no-throw-literal.md
@@ -79,6 +79,16 @@ class CustomError extends Error {
throw new CustomError();
```
+## How to use
+
+```jsonc
+{
+ // note you must disable the base rule as it can report incorrect errors
+ "no-throw-literal": "off",
+ "@typescript-eslint/no-throw-literal": ["error"]
+}
+```
+
---
Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/no-throw-literal.md)
diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json
index 3522598037f5..e9e1d0cd38be 100644
--- a/packages/eslint-plugin/package.json
+++ b/packages/eslint-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin",
- "version": "4.2.0",
+ "version": "4.3.0",
"description": "TypeScript plugin for ESLint",
"keywords": [
"eslint",
@@ -42,8 +42,8 @@
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
- "@typescript-eslint/experimental-utils": "4.2.0",
- "@typescript-eslint/scope-manager": "4.2.0",
+ "@typescript-eslint/experimental-utils": "4.3.0",
+ "@typescript-eslint/scope-manager": "4.3.0",
"debug": "^4.1.1",
"functional-red-black-tree": "^1.0.1",
"regexpp": "^3.0.0",
diff --git a/packages/eslint-plugin/src/configs/README.md b/packages/eslint-plugin/src/configs/README.md
index 3f232c7d9df2..c3ee9dbddf86 100644
--- a/packages/eslint-plugin/src/configs/README.md
+++ b/packages/eslint-plugin/src/configs/README.md
@@ -8,7 +8,7 @@ The `eslint-recommended` ruleset is meant to be used after extending `eslint:rec
This config is automatically included if you use either the `recommended` or `recommended-requiring-type-checking` configs.
-```cjson
+```jsonc
{
"extends": [
"eslint:recommended",
@@ -40,7 +40,7 @@ We will not add new rules to the `recommended` set unless we release a major pac
If you disagree with a rule (or it disagrees with your codebase), consider using your local config to change the rule config so it works for your project.
-```cjson
+```jsonc
{
"extends": ["plugin:@typescript-eslint/recommended"],
"rules": {
diff --git a/packages/eslint-plugin/src/rules/no-invalid-void-type.ts b/packages/eslint-plugin/src/rules/no-invalid-void-type.ts
index b78107bac650..0dff489e585f 100644
--- a/packages/eslint-plugin/src/rules/no-invalid-void-type.ts
+++ b/packages/eslint-plugin/src/rules/no-invalid-void-type.ts
@@ -5,13 +5,16 @@ import {
import * as util from '../util';
interface Options {
- allowInGenericTypeArguments: boolean | string[];
+ allowInGenericTypeArguments?: boolean | string[];
+ allowAsThisParameter?: boolean;
}
type MessageIds =
| 'invalidVoidForGeneric'
| 'invalidVoidNotReturnOrGeneric'
- | 'invalidVoidNotReturn';
+ | 'invalidVoidNotReturn'
+ | 'invalidVoidNotReturnOrThisParam'
+ | 'invalidVoidNotReturnOrThisParamOrGeneric';
export default util.createRule<[Options], MessageIds>({
name: 'no-invalid-void-type',
@@ -29,6 +32,10 @@ export default util.createRule<[Options], MessageIds>({
invalidVoidNotReturnOrGeneric:
'void is only valid as a return type or generic type variable',
invalidVoidNotReturn: 'void is only valid as a return type',
+ invalidVoidNotReturnOrThisParam:
+ 'void is only valid as return type or type of `this` parameter',
+ invalidVoidNotReturnOrThisParamOrGeneric:
+ 'void is only valid as a return type or generic type variable or the type of a `this` parameter',
},
schema: [
{
@@ -44,13 +51,18 @@ export default util.createRule<[Options], MessageIds>({
},
],
},
+ allowAsThisParameter: {
+ type: 'boolean',
+ },
},
additionalProperties: false,
},
],
},
- defaultOptions: [{ allowInGenericTypeArguments: true }],
- create(context, [{ allowInGenericTypeArguments }]) {
+ defaultOptions: [
+ { allowInGenericTypeArguments: true, allowAsThisParameter: false },
+ ],
+ create(context, [{ allowInGenericTypeArguments, allowAsThisParameter }]) {
const validParents: AST_NODE_TYPES[] = [
AST_NODE_TYPES.TSTypeAnnotation, //
];
@@ -110,7 +122,9 @@ export default util.createRule<[Options], MessageIds>({
if (!allowInGenericTypeArguments) {
context.report({
- messageId: 'invalidVoidNotReturn',
+ messageId: allowAsThisParameter
+ ? 'invalidVoidNotReturnOrThisParam'
+ : 'invalidVoidNotReturn',
node,
});
}
@@ -159,6 +173,16 @@ export default util.createRule<[Options], MessageIds>({
return;
}
+ // this parameter is ok to be void.
+ if (
+ allowAsThisParameter &&
+ node.parent.type === AST_NODE_TYPES.TSTypeAnnotation &&
+ node.parent.parent.type === AST_NODE_TYPES.Identifier &&
+ node.parent.parent.name === 'this'
+ ) {
+ return;
+ }
+
// default cases
if (
validParents.includes(node.parent.type) &&
@@ -168,9 +192,14 @@ export default util.createRule<[Options], MessageIds>({
}
context.report({
- messageId: allowInGenericTypeArguments
- ? 'invalidVoidNotReturnOrGeneric'
- : 'invalidVoidNotReturn',
+ messageId:
+ allowInGenericTypeArguments && allowAsThisParameter
+ ? 'invalidVoidNotReturnOrThisParamOrGeneric'
+ : allowInGenericTypeArguments
+ ? 'invalidVoidNotReturnOrGeneric'
+ : allowAsThisParameter
+ ? 'invalidVoidNotReturnOrThisParam'
+ : 'invalidVoidNotReturn',
node,
});
},
diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts
index 134cefd76d1b..3e1ad26bcda2 100644
--- a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts
+++ b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts
@@ -24,6 +24,7 @@ import {
isTypeAnyType,
isTypeUnknownType,
getTypeName,
+ getTypeOfPropertyOfName,
} from '../util';
// Truthiness utilities
@@ -499,7 +500,8 @@ export default createRule({
);
}
if (propertyType.isNumberLiteral() || propertyType.isStringLiteral()) {
- const propType = checker.getTypeOfPropertyOfType(
+ const propType = getTypeOfPropertyOfName(
+ checker,
objType,
propertyType.value.toString(),
);
@@ -535,7 +537,11 @@ export default createRule({
const propertyType = getNodeType(node.property);
return isNullablePropertyType(type, propertyType);
}
- const propType = checker.getTypeOfPropertyOfType(type, property.name);
+ const propType = getTypeOfPropertyOfName(
+ checker,
+ type,
+ property.name,
+ );
return propType && isNullableType(propType, { allowUndefined: true });
});
return (
diff --git a/packages/eslint-plugin/src/util/index.ts b/packages/eslint-plugin/src/util/index.ts
index 82828f138932..672f50dc4fff 100644
--- a/packages/eslint-plugin/src/util/index.ts
+++ b/packages/eslint-plugin/src/util/index.ts
@@ -6,6 +6,7 @@ export * from './isTypeReadonly';
export * from './misc';
export * from './nullThrows';
export * from './objectIterators';
+export * from './propertyTypes';
export * from './types';
// this is done for convenience - saves migrating all of the old rules
diff --git a/packages/eslint-plugin/src/util/isTypeReadonly.ts b/packages/eslint-plugin/src/util/isTypeReadonly.ts
index da9529e63a9d..b10f00006ec5 100644
--- a/packages/eslint-plugin/src/util/isTypeReadonly.ts
+++ b/packages/eslint-plugin/src/util/isTypeReadonly.ts
@@ -6,7 +6,7 @@ import {
isPropertyReadonlyInType,
} from 'tsutils';
import * as ts from 'typescript';
-import { nullThrows, NullThrowsReasons } from '.';
+import { getTypeOfPropertyOfType, nullThrows, NullThrowsReasons } from '.';
const enum Readonlyness {
/** the type cannot be handled by the function */
@@ -101,7 +101,7 @@ function isTypeReadonlyObject(
// doing this deep, potentially expensive check.
for (const property of properties) {
const propertyType = nullThrows(
- checker.getTypeOfPropertyOfType(type, property.getName()),
+ getTypeOfPropertyOfType(checker, type, property),
NullThrowsReasons.MissingToken(`property "${property.name}"`, 'type'),
);
diff --git a/packages/eslint-plugin/src/util/propertyTypes.ts b/packages/eslint-plugin/src/util/propertyTypes.ts
new file mode 100644
index 000000000000..5e2f1054239d
--- /dev/null
+++ b/packages/eslint-plugin/src/util/propertyTypes.ts
@@ -0,0 +1,36 @@
+import * as ts from 'typescript';
+
+export function getTypeOfPropertyOfName(
+ checker: ts.TypeChecker,
+ type: ts.Type,
+ name: string,
+ escapedName?: ts.__String,
+): ts.Type | undefined {
+ // Most names are directly usable in the checker and aren't different from escaped names
+ if (!escapedName || !name.startsWith('__')) {
+ return checker.getTypeOfPropertyOfType(type, name);
+ }
+
+ // Symbolic names may differ in their escaped name compared to their human-readable name
+ // https://github.com/typescript-eslint/typescript-eslint/issues/2143
+ const escapedProperty = type
+ .getProperties()
+ .find(property => property.escapedName === escapedName);
+
+ return escapedProperty
+ ? checker.getDeclaredTypeOfSymbol(escapedProperty)
+ : undefined;
+}
+
+export function getTypeOfPropertyOfType(
+ checker: ts.TypeChecker,
+ type: ts.Type,
+ property: ts.Symbol,
+): ts.Type | undefined {
+ return getTypeOfPropertyOfName(
+ checker,
+ type,
+ property.getName(),
+ property.getEscapedName(),
+ );
+}
diff --git a/packages/eslint-plugin/tests/rules/indent/indent.test.ts b/packages/eslint-plugin/tests/rules/indent/indent.test.ts
index beb648d4f52e..8296bf19520c 100644
--- a/packages/eslint-plugin/tests/rules/indent/indent.test.ts
+++ b/packages/eslint-plugin/tests/rules/indent/indent.test.ts
@@ -621,6 +621,9 @@ type Foo = string | {
(acc, testCase) => {
const indent = ' ';
+ const validCases = [...acc.valid];
+ const invalidCases = [...acc.invalid];
+
const codeCases = testCase.code.map(code =>
[
'', // newline to make test error messages nicer
@@ -631,7 +634,7 @@ type Foo = string | {
codeCases.forEach(code => {
// valid test case is just the code
- acc.valid.push(code);
+ validCases.push(code);
const invalid = {
// test the fixer by removing all the spaces
@@ -663,11 +666,11 @@ type Foo = string | {
),
};
if (invalid.errors.length > 0) {
- acc.invalid.push(invalid);
+ invalidCases.push(invalid);
}
});
- return acc;
+ return { ...acc, valid: validCases, invalid: invalidCases };
},
{ valid: [], invalid: [] },
);
diff --git a/packages/eslint-plugin/tests/rules/no-invalid-void-type.test.ts b/packages/eslint-plugin/tests/rules/no-invalid-void-type.test.ts
index 31771c561c0e..56df4f47ab6f 100644
--- a/packages/eslint-plugin/tests/rules/no-invalid-void-type.test.ts
+++ b/packages/eslint-plugin/tests/rules/no-invalid-void-type.test.ts
@@ -538,3 +538,56 @@ async function foo(bar: () => void | Promise) {
},
],
});
+
+ruleTester.run('allowAsThisParameter: true', rule, {
+ valid: [
+ {
+ code: 'function f(this: void) {}',
+ options: [{ allowAsThisParameter: true }],
+ },
+ {
+ code: `
+class Test {
+ public static helper(this: void) {}
+ method(this: void) {}
+}
+ `,
+ options: [{ allowAsThisParameter: true }],
+ },
+ ],
+ invalid: [
+ {
+ code: 'type alias = void;',
+ options: [
+ { allowAsThisParameter: true, allowInGenericTypeArguments: true },
+ ],
+ errors: [
+ {
+ messageId: 'invalidVoidNotReturnOrThisParamOrGeneric',
+ },
+ ],
+ },
+ {
+ code: 'type alias = void;',
+ options: [
+ { allowAsThisParameter: true, allowInGenericTypeArguments: false },
+ ],
+ errors: [
+ {
+ messageId: 'invalidVoidNotReturnOrThisParam',
+ },
+ ],
+ },
+ {
+ code: 'type alias = Array;',
+ options: [
+ { allowAsThisParameter: true, allowInGenericTypeArguments: false },
+ ],
+ errors: [
+ {
+ messageId: 'invalidVoidNotReturnOrThisParam',
+ },
+ ],
+ },
+ ],
+});
diff --git a/packages/eslint-plugin/tests/rules/prefer-readonly-parameter-types.test.ts b/packages/eslint-plugin/tests/rules/prefer-readonly-parameter-types.test.ts
index 3ca6c0201fc1..d5408a5d859d 100644
--- a/packages/eslint-plugin/tests/rules/prefer-readonly-parameter-types.test.ts
+++ b/packages/eslint-plugin/tests/rules/prefer-readonly-parameter-types.test.ts
@@ -238,6 +238,15 @@ ruleTester.run('prefer-readonly-parameter-types', rule, {
}
function foo(arg: Readonly) {}
`,
+ `
+ const sym = Symbol('sym');
+
+ interface WithSymbol {
+ [sym]: number;
+ }
+
+ const willNotCrash = (foo: Readonly) => {};
+ `,
],
invalid: [
// arrays
@@ -643,5 +652,24 @@ ruleTester.run('prefer-readonly-parameter-types', rule, {
},
],
},
+ {
+ code: `
+ const sym = Symbol('sym');
+
+ interface WithSymbol {
+ [sym]: number;
+ }
+
+ const willNot = (foo: WithSymbol) => {};
+ `,
+ errors: [
+ {
+ messageId: 'shouldBeReadonly',
+ line: 8,
+ column: 26,
+ endColumn: 41,
+ },
+ ],
+ },
],
});
diff --git a/packages/experimental-utils/CHANGELOG.md b/packages/experimental-utils/CHANGELOG.md
index e4160881daa8..88a8ced7b0ce 100644
--- a/packages/experimental-utils/CHANGELOG.md
+++ b/packages/experimental-utils/CHANGELOG.md
@@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [4.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.2.0...v4.3.0) (2020-09-28)
+
+
+### Bug Fixes
+
+* **experimental-utils:** treat RuleTester arrays as readonly ([#2601](https://github.com/typescript-eslint/typescript-eslint/issues/2601)) ([8025777](https://github.com/typescript-eslint/typescript-eslint/commit/80257776b78bd2b2b4389d6bd530b009a75fb520))
+
+
+
+
+
# [4.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.1.1...v4.2.0) (2020-09-21)
**Note:** Version bump only for package @typescript-eslint/experimental-utils
diff --git a/packages/experimental-utils/package.json b/packages/experimental-utils/package.json
index f3fe1e5d9303..4ac8648c8aa8 100644
--- a/packages/experimental-utils/package.json
+++ b/packages/experimental-utils/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/experimental-utils",
- "version": "4.2.0",
+ "version": "4.3.0",
"description": "(Experimental) Utilities for working with TypeScript + ESLint together",
"keywords": [
"eslint",
@@ -40,9 +40,9 @@
},
"dependencies": {
"@types/json-schema": "^7.0.3",
- "@typescript-eslint/scope-manager": "4.2.0",
- "@typescript-eslint/types": "4.2.0",
- "@typescript-eslint/typescript-estree": "4.2.0",
+ "@typescript-eslint/scope-manager": "4.3.0",
+ "@typescript-eslint/types": "4.3.0",
+ "@typescript-eslint/typescript-estree": "4.3.0",
"eslint-scope": "^5.0.0",
"eslint-utils": "^2.0.0"
},
diff --git a/packages/experimental-utils/src/ts-eslint/RuleTester.ts b/packages/experimental-utils/src/ts-eslint/RuleTester.ts
index b54c1190ad83..a1fa2104a91e 100644
--- a/packages/experimental-utils/src/ts-eslint/RuleTester.ts
+++ b/packages/experimental-utils/src/ts-eslint/RuleTester.ts
@@ -64,7 +64,7 @@ interface InvalidTestCase<
/**
* Expected errors.
*/
- readonly errors: TestCaseError[];
+ readonly errors: readonly TestCaseError[];
/**
* The expected code after autofixes are applied. If set to `null`, the test runner will assert that no autofix is suggested.
*/
@@ -114,8 +114,8 @@ interface RunTests<
TOptions extends Readonly
> {
// RuleTester.run also accepts strings for valid cases
- readonly valid: (ValidTestCase | string)[];
- readonly invalid: InvalidTestCase[];
+ readonly valid: readonly (ValidTestCase | string)[];
+ readonly invalid: readonly InvalidTestCase[];
}
interface RuleTesterConfig {
// should be require.resolve(parserPackageName)
diff --git a/packages/parser/CHANGELOG.md b/packages/parser/CHANGELOG.md
index e6587af9a5f4..4b413595271f 100644
--- a/packages/parser/CHANGELOG.md
+++ b/packages/parser/CHANGELOG.md
@@ -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.
+# [4.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.2.0...v4.3.0) (2020-09-28)
+
+**Note:** Version bump only for package @typescript-eslint/parser
+
+
+
+
+
# [4.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.1.1...v4.2.0) (2020-09-21)
**Note:** Version bump only for package @typescript-eslint/parser
diff --git a/packages/parser/package.json b/packages/parser/package.json
index 96580b94b982..683cdd04db55 100644
--- a/packages/parser/package.json
+++ b/packages/parser/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/parser",
- "version": "4.2.0",
+ "version": "4.3.0",
"description": "An ESLint custom parser which leverages TypeScript ESTree",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -44,15 +44,15 @@
"eslint": "^5.0.0 || ^6.0.0 || ^7.0.0"
},
"dependencies": {
- "@typescript-eslint/scope-manager": "4.2.0",
- "@typescript-eslint/types": "4.2.0",
- "@typescript-eslint/typescript-estree": "4.2.0",
+ "@typescript-eslint/scope-manager": "4.3.0",
+ "@typescript-eslint/types": "4.3.0",
+ "@typescript-eslint/typescript-estree": "4.3.0",
"debug": "^4.1.1"
},
"devDependencies": {
"@types/glob": "*",
- "@typescript-eslint/experimental-utils": "4.2.0",
- "@typescript-eslint/shared-fixtures": "4.2.0",
+ "@typescript-eslint/experimental-utils": "4.3.0",
+ "@typescript-eslint/shared-fixtures": "4.3.0",
"glob": "*",
"typescript": "*"
},
diff --git a/packages/scope-manager/CHANGELOG.md b/packages/scope-manager/CHANGELOG.md
index b69bb9b861b3..d68103fe5761 100644
--- a/packages/scope-manager/CHANGELOG.md
+++ b/packages/scope-manager/CHANGELOG.md
@@ -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.
+# [4.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.2.0...v4.3.0) (2020-09-28)
+
+**Note:** Version bump only for package @typescript-eslint/scope-manager
+
+
+
+
+
# [4.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.1.1...v4.2.0) (2020-09-21)
diff --git a/packages/scope-manager/package.json b/packages/scope-manager/package.json
index 58845e57d674..84cb81967c91 100644
--- a/packages/scope-manager/package.json
+++ b/packages/scope-manager/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/scope-manager",
- "version": "4.2.0",
+ "version": "4.3.0",
"description": "TypeScript scope analyser for ESLint",
"keywords": [
"eslint",
@@ -39,12 +39,12 @@
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
- "@typescript-eslint/types": "4.2.0",
- "@typescript-eslint/visitor-keys": "4.2.0"
+ "@typescript-eslint/types": "4.3.0",
+ "@typescript-eslint/visitor-keys": "4.3.0"
},
"devDependencies": {
"@types/glob": "*",
- "@typescript-eslint/typescript-estree": "4.2.0",
+ "@typescript-eslint/typescript-estree": "4.3.0",
"glob": "*",
"jest-specific-snapshot": "*",
"make-dir": "*",
diff --git a/packages/shared-fixtures/CHANGELOG.md b/packages/shared-fixtures/CHANGELOG.md
index c57a16297049..c11ce5fdef69 100644
--- a/packages/shared-fixtures/CHANGELOG.md
+++ b/packages/shared-fixtures/CHANGELOG.md
@@ -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.
+# [4.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.2.0...v4.3.0) (2020-09-28)
+
+**Note:** Version bump only for package @typescript-eslint/shared-fixtures
+
+
+
+
+
# [4.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.1.1...v4.2.0) (2020-09-21)
**Note:** Version bump only for package @typescript-eslint/shared-fixtures
diff --git a/packages/shared-fixtures/package.json b/packages/shared-fixtures/package.json
index e56173fca727..de66b604889b 100644
--- a/packages/shared-fixtures/package.json
+++ b/packages/shared-fixtures/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/shared-fixtures",
- "version": "4.2.0",
+ "version": "4.3.0",
"private": true,
"scripts": {
"build": "tsc -b tsconfig.build.json",
diff --git a/packages/types/CHANGELOG.md b/packages/types/CHANGELOG.md
index 0581c895a635..a9206bf533de 100644
--- a/packages/types/CHANGELOG.md
+++ b/packages/types/CHANGELOG.md
@@ -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.
+# [4.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.2.0...v4.3.0) (2020-09-28)
+
+**Note:** Version bump only for package @typescript-eslint/types
+
+
+
+
+
# [4.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.1.1...v4.2.0) (2020-09-21)
**Note:** Version bump only for package @typescript-eslint/types
diff --git a/packages/types/package.json b/packages/types/package.json
index 2d52d18b7fb9..7aaca2739b79 100644
--- a/packages/types/package.json
+++ b/packages/types/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/types",
- "version": "4.2.0",
+ "version": "4.3.0",
"description": "Types for the TypeScript-ESTree AST spec",
"keywords": [
"eslint",
diff --git a/packages/typescript-estree/CHANGELOG.md b/packages/typescript-estree/CHANGELOG.md
index bb7225c97238..0a5a33b1c563 100644
--- a/packages/typescript-estree/CHANGELOG.md
+++ b/packages/typescript-estree/CHANGELOG.md
@@ -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.
+# [4.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.2.0...v4.3.0) (2020-09-28)
+
+**Note:** Version bump only for package @typescript-eslint/typescript-estree
+
+
+
+
+
# [4.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.1.1...v4.2.0) (2020-09-21)
**Note:** Version bump only for package @typescript-eslint/typescript-estree
diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json
index 98cffe748bc1..69f10c2f5e9c 100644
--- a/packages/typescript-estree/package.json
+++ b/packages/typescript-estree/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/typescript-estree",
- "version": "4.2.0",
+ "version": "4.3.0",
"description": "A parser that converts TypeScript source code into an ESTree compatible form",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -41,8 +41,8 @@
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
- "@typescript-eslint/types": "4.2.0",
- "@typescript-eslint/visitor-keys": "4.2.0",
+ "@typescript-eslint/types": "4.3.0",
+ "@typescript-eslint/visitor-keys": "4.3.0",
"debug": "^4.1.1",
"globby": "^11.0.1",
"is-glob": "^4.0.1",
@@ -61,7 +61,7 @@
"@types/lodash": "*",
"@types/semver": "^7.1.0",
"@types/tmp": "^0.2.0",
- "@typescript-eslint/shared-fixtures": "4.2.0",
+ "@typescript-eslint/shared-fixtures": "4.3.0",
"glob": "*",
"jest-specific-snapshot": "*",
"make-dir": "*",
diff --git a/packages/visitor-keys/CHANGELOG.md b/packages/visitor-keys/CHANGELOG.md
index 30f1b67de929..4ef4cf67f1be 100644
--- a/packages/visitor-keys/CHANGELOG.md
+++ b/packages/visitor-keys/CHANGELOG.md
@@ -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.
+# [4.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.2.0...v4.3.0) (2020-09-28)
+
+**Note:** Version bump only for package @typescript-eslint/visitor-keys
+
+
+
+
+
# [4.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.1.1...v4.2.0) (2020-09-21)
**Note:** Version bump only for package @typescript-eslint/visitor-keys
diff --git a/packages/visitor-keys/package.json b/packages/visitor-keys/package.json
index 9dc95229ff5c..792e9cc10fef 100644
--- a/packages/visitor-keys/package.json
+++ b/packages/visitor-keys/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/visitor-keys",
- "version": "4.2.0",
+ "version": "4.3.0",
"description": "Visitor keys used to help traverse the TypeScript-ESTree AST",
"keywords": [
"eslint",
@@ -38,7 +38,7 @@
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
- "@typescript-eslint/types": "4.2.0",
+ "@typescript-eslint/types": "4.3.0",
"eslint-visitor-keys": "^2.0.0"
},
"devDependencies": {