Skip to content

Commit

Permalink
Merge branch 'master'
Browse files Browse the repository at this point in the history
Conflicts:
	yarn.lock
  • Loading branch information
armano2 committed Mar 15, 2021
2 parents f941696 + 55e1fba commit 110b416
Show file tree
Hide file tree
Showing 44 changed files with 1,569 additions and 196 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,22 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [4.17.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.16.1...v4.17.0) (2021-03-08)


### Bug Fixes

* **eslint-plugin:** [no-unnecessary-type-assertion] handle assignment ([#3133](https://github.com/typescript-eslint/typescript-eslint/issues/3133)) ([cb22561](https://github.com/typescript-eslint/typescript-eslint/commit/cb2256168c67e0383083673a5afe77076de49da5))


### Features

* **eslint-plugin:** [strict-bool-expr] add fixes and suggestions ([#2847](https://github.com/typescript-eslint/typescript-eslint/issues/2847)) ([3f9e9a1](https://github.com/typescript-eslint/typescript-eslint/commit/3f9e9a1e9fc3e507bd01d1913ef642cd129de402))





## [4.16.1](https://github.com/typescript-eslint/typescript-eslint/compare/v4.16.0...v4.16.1) (2021-03-01)


Expand Down
2 changes: 1 addition & 1 deletion lerna.json
@@ -1,5 +1,5 @@
{
"version": "4.16.1",
"version": "4.17.0",
"npmClient": "yarn",
"useWorkspaces": true,
"stream": true
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -58,7 +58,7 @@
"@types/jest": "^26.0.20",
"@types/jest-specific-snapshot": "^0.5.5",
"@types/lodash": "^4.14.149",
"@types/marked": "^1.1.0",
"@types/marked": "^2.0.0",
"@types/node": "^14.14.27",
"@types/prettier": "^2.2.1",
"@types/rimraf": "^3.0.0",
Expand All @@ -81,7 +81,7 @@
"lerna": "^4.0.0",
"lint-staged": "^10.2.13",
"make-dir": "^3.1.0",
"markdownlint-cli": "^0.26.0",
"markdownlint-cli": "^0.27.1",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"ts-jest": "^26.5.1",
Expand Down
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.

# [4.17.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.16.1...v4.17.0) (2021-03-08)

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





## [4.16.1](https://github.com/typescript-eslint/typescript-eslint/compare/v4.16.0...v4.16.1) (2021-03-01)

**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": "4.16.1",
"version": "4.17.0",
"private": true,
"main": "dist/index.js",
"scripts": {
Expand All @@ -14,7 +14,7 @@
},
"dependencies": {
"@types/prettier": "*",
"@typescript-eslint/experimental-utils": "4.16.1",
"@typescript-eslint/experimental-utils": "4.17.0",
"prettier": "*"
}
}
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.

# [4.17.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.16.1...v4.17.0) (2021-03-08)

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





## [4.16.1](https://github.com/typescript-eslint/typescript-eslint/compare/v4.16.0...v4.16.1) (2021-03-01)

**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": "4.16.1",
"version": "4.17.0",
"main": "dist/index.js",
"typings": "src/index.ts",
"description": "TSLint wrapper plugin for ESLint",
Expand Down Expand Up @@ -38,7 +38,7 @@
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@typescript-eslint/experimental-utils": "4.16.1",
"@typescript-eslint/experimental-utils": "4.17.0",
"lodash": "^4.17.15"
},
"peerDependencies": {
Expand All @@ -48,6 +48,6 @@
},
"devDependencies": {
"@types/lodash": "*",
"@typescript-eslint/parser": "4.16.1"
"@typescript-eslint/parser": "4.17.0"
}
}
16 changes: 16 additions & 0 deletions packages/eslint-plugin/CHANGELOG.md
Expand Up @@ -3,6 +3,22 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [4.17.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.16.1...v4.17.0) (2021-03-08)


### Bug Fixes

* **eslint-plugin:** [no-unnecessary-type-assertion] handle assignment ([#3133](https://github.com/typescript-eslint/typescript-eslint/issues/3133)) ([cb22561](https://github.com/typescript-eslint/typescript-eslint/commit/cb2256168c67e0383083673a5afe77076de49da5))


### Features

* **eslint-plugin:** [strict-bool-expr] add fixes and suggestions ([#2847](https://github.com/typescript-eslint/typescript-eslint/issues/2847)) ([3f9e9a1](https://github.com/typescript-eslint/typescript-eslint/commit/3f9e9a1e9fc3e507bd01d1913ef642cd129de402))





## [4.16.1](https://github.com/typescript-eslint/typescript-eslint/compare/v4.16.0...v4.16.1) (2021-03-01)

**Note:** Version bump only for package @typescript-eslint/eslint-plugin
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/README.md
Expand Up @@ -169,7 +169,7 @@ Pro Tip: For larger codebases you may want to consider splitting our linting int
| [`@typescript-eslint/restrict-plus-operands`](./docs/rules/restrict-plus-operands.md) | When adding two variables, operands must both be of type number or of type string | :heavy_check_mark: | | :thought_balloon: |
| [`@typescript-eslint/restrict-template-expressions`](./docs/rules/restrict-template-expressions.md) | Enforce template literal expressions to be of string type | :heavy_check_mark: | | :thought_balloon: |
| [`@typescript-eslint/sort-type-union-intersection-members`](./docs/rules/sort-type-union-intersection-members.md) | Enforces that members of a type union/intersection are sorted alphabetically | | :wrench: | |
| [`@typescript-eslint/strict-boolean-expressions`](./docs/rules/strict-boolean-expressions.md) | Restricts the types allowed in boolean expressions | | | :thought_balloon: |
| [`@typescript-eslint/strict-boolean-expressions`](./docs/rules/strict-boolean-expressions.md) | Restricts the types allowed in boolean expressions | | :wrench: | :thought_balloon: |
| [`@typescript-eslint/switch-exhaustiveness-check`](./docs/rules/switch-exhaustiveness-check.md) | Exhaustiveness checking in switch with union type | | | :thought_balloon: |
| [`@typescript-eslint/triple-slash-reference`](./docs/rules/triple-slash-reference.md) | Sets preference level for triple slash directives versus ES6-style import declarations | :heavy_check_mark: | | |
| [`@typescript-eslint/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) | Require consistent spacing around type annotations | | :wrench: | |
Expand Down
Expand Up @@ -61,6 +61,6 @@ const x: import('Bar') = 1;
## When Not To Use It

- If you are not using TypeScript 3.8 (or greater), then you will not be able to use this rule, as type-only imports are not allowed.
- Certain libraries use the non-inlined imports to infer information about the variables. For example, for dependency injection.
- Certain libraries use the non-inlined imports to infer information about the variables. For example, for dependency injection.<br/>
type-only imports cannot be used with these libraries. See [#2559](https://github.com/typescript-eslint/typescript-eslint/issues/2559#issuecomment-692780580)
- If you specifically want to use both import kinds for stylistic reasons, you can disable this rule.
2 changes: 1 addition & 1 deletion packages/eslint-plugin/docs/rules/no-floating-promises.md
Expand Up @@ -77,7 +77,7 @@ void returnsPromise();
void Promise.reject('value');
```

With this option set to `true`, and if you are using `no-void`, you should turn on the [`allowAsAStatement`](https://eslint.org/docs/rules/no-void#allowasstatement) option.
With this option set to `true`, and if you are using `no-void`, you should turn on the [`allowAsStatement`](https://eslint.org/docs/rules/no-void#allowasstatement) option.

### `ignoreIIFE`

Expand Down
8 changes: 4 additions & 4 deletions packages/eslint-plugin/docs/rules/no-magic-numbers.md
Expand Up @@ -53,8 +53,8 @@ Examples of **incorrect** code for the `{ "ignoreEnums": false }` option:
```ts
/*eslint @typescript-eslint/no-magic-numbers: ["error", { "ignoreEnums": false }]*/

enum foo = {
SECOND = 1000,
enum foo {
SECOND = 1000,
}
```

Expand All @@ -63,8 +63,8 @@ Examples of **correct** code for the `{ "ignoreEnums": true }` option:
```ts
/*eslint @typescript-eslint/no-magic-numbers: ["error", { "ignoreEnums": true }]*/

enum foo = {
SECOND = 1000,
enum foo {
SECOND = 1000,
}
```

Expand Down
32 changes: 32 additions & 0 deletions packages/eslint-plugin/docs/rules/strict-boolean-expressions.md
Expand Up @@ -155,6 +155,38 @@ You should be using `strictNullChecks` to ensure complete type-safety in your co

If for some reason you cannot turn on `strictNullChecks`, but still want to use this rule - you can use this option to allow it - but know that the behavior of this rule is _undefined_ with the compiler option turned off. We will not accept bug reports if you are using this option.

## Fixes and suggestions

This rule provides following fixes and suggestions for particular types in boolean context:

- `boolean` - Always allowed - no fix needed.
- `string` - (when `allowString` is `false`) - Provides following suggestions:
- Change condition to check string's length (`str``str.length > 0`)
- Change condition to check for empty string (`str``str !== ""`)
- Explicitly cast value to a boolean (`str``Boolean(str)`)
- `number` - (when `allowNumber` is `false`):
- For `array.length` - Provides **autofix**:
- Change condition to check for 0 (`array.length``array.length > 0`)
- For other number values - Provides following suggestions:
- Change condition to check for 0 (`num``num !== 0`)
- Change condition to check for NaN (`num``!Number.isNaN(num)`)
- Explicitly cast value to a boolean (`num``Boolean(num)`)
- `object | null | undefined` - (when `allowNullableObject` is `false`) - Provides **autofix**:
- Change condition to check for null/undefined (`maybeObj``maybeObj != null`)
- `boolean | null | undefined` - Provides following suggestions:
- Explicitly treat nullish value the same as false (`maybeBool``maybeBool ?? false`)
- Change condition to check for true/false (`maybeBool``maybeBool === true`)
- `string | null | undefined` - Provides following suggestions:
- Change condition to check for null/undefined (`maybeStr``maybeStr != null`)
- Explicitly treat nullish value the same as an empty string (`maybeStr``maybeStr ?? ""`)
- Explicitly cast value to a boolean (`maybeStr``Boolean(maybeStr)`)
- `number | null | undefined` - Provides following suggestions:
- Change condition to check for null/undefined (`maybeNum``maybeNum != null`)
- Explicitly treat nullish value the same as 0 (`maybeNum``maybeNum ?? 0`)
- Explicitly cast value to a boolean (`maybeNum``Boolean(maybeNum)`)
- `any` and `unknown` - Provides following suggestions:
- Explicitly cast value to a boolean (`value``Boolean(value)`)

## Related To

- TSLint: [strict-boolean-expressions](https://palantir.github.io/tslint/rules/strict-boolean-expressions)
Expand Down
2 changes: 0 additions & 2 deletions packages/eslint-plugin/docs/rules/triple-slash-reference.md
Expand Up @@ -2,8 +2,6 @@

Use of triple-slash reference type directives is discouraged in favor of the newer `import` style. This rule allows you to ban use of `/// <reference path="" />`, `/// <reference types="" />`, or `/// <reference lib="" />` directives.

Consider using this rule in place of [`no-triple-slash-reference`](./no-triple-slash-reference.md) which has been deprecated.

## Rule Details

With `{ "path": "never", "types": "never", "lib": "never" }` options set, the following will all be **incorrect** usage:
Expand Down
4 changes: 4 additions & 0 deletions packages/eslint-plugin/index.d.ts
@@ -0,0 +1,4 @@
import { TSESLint } from '@typescript-eslint/experimental-utils';

export const rules: Record<string, TSESLint.RuleModule<string, unknown[]>>;
export const configs: Record<string, TSESLint.Linter.Config>;
8 changes: 5 additions & 3 deletions packages/eslint-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin",
"version": "4.16.1",
"version": "4.17.0",
"description": "TypeScript plugin for ESLint",
"keywords": [
"eslint",
Expand All @@ -14,6 +14,7 @@
"files": [
"dist",
"docs",
"index.d.ts",
"package.json",
"README.md",
"LICENSE"
Expand All @@ -28,6 +29,7 @@
},
"license": "MIT",
"main": "dist/index.js",
"types": "index.d.ts",
"scripts": {
"build": "tsc -b tsconfig.build.json",
"check:docs": "jest tests/docs.test.ts --runTestsByPath --silent --runInBand",
Expand All @@ -42,8 +44,8 @@
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@typescript-eslint/experimental-utils": "4.16.1",
"@typescript-eslint/scope-manager": "4.16.1",
"@typescript-eslint/experimental-utils": "4.17.0",
"@typescript-eslint/scope-manager": "4.17.0",
"debug": "^4.1.1",
"functional-red-black-tree": "^1.0.1",
"lodash": "^4.17.15",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/no-extraneous-class.ts
Expand Up @@ -79,13 +79,13 @@ export default util.createRule<Options, MessageIds>({
| TSESTree.ClassExpression
| undefined;

if (!parent || parent.superClass) {
if (!parent || parent.superClass || isAllowWithDecorator(parent)) {
return;
}

const reportNode = 'id' in parent && parent.id ? parent.id : parent;
if (node.body.length === 0) {
if (allowEmpty || isAllowWithDecorator(parent)) {
if (allowEmpty) {
return;
}

Expand Down
19 changes: 19 additions & 0 deletions packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts
Expand Up @@ -135,7 +135,26 @@ export default util.createRule<Options, MessageIds>({

return {
TSNonNullExpression(node): void {
if (
node.parent?.type === AST_NODE_TYPES.AssignmentExpression &&
node.parent?.operator === '=' &&
node.parent.left === node
) {
context.report({
node,
messageId: 'contextuallyUnnecessary',
fix(fixer) {
return fixer.removeRange([
node.expression.range[1],
node.range[1],
]);
},
});
return;
}

const originalNode = parserServices.esTreeNodeToTSNodeMap.get(node);

const type = util.getConstrainedTypeAtLocation(
checker,
originalNode.expression,
Expand Down

0 comments on commit 110b416

Please sign in to comment.