diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index e219ef75b4fd..9bc60d2f0d81 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -6,9 +6,27 @@ labels: triage assignees: '' --- -**What were you trying to do?** + + +- [ ] I have tried restarting my IDE and the issue persists. +- [ ] I have updated to the latest version of the packages. +- [ ] I have [read the FAQ](https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md) and my problem is not listed. + +**Repro** + + + +```JSON { "rules": { "@typescript-eslint/": [""] @@ -16,13 +34,36 @@ assignees: '' } ``` -```ts -// Put your code here +```TS +// your repro code case ``` -**What did you expect to happen?** + + +**Expected Result** + + + +**Actual Result** + + + +**Additional Info** + + **Versions** diff --git a/CHANGELOG.md b/CHANGELOG.md index 84849c434bba..5cbbbd123a5f 100644 --- a/CHANGELOG.md +++ b/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. +## [3.10.1](https://github.com/typescript-eslint/typescript-eslint/compare/v3.10.0...v3.10.1) (2020-08-25) + + +### Bug Fixes + +* **eslint-plugin:** [no-unnecessary-condition] correct regression with unary negations ([#2422](https://github.com/typescript-eslint/typescript-eslint/issues/2422)) ([d1f0887](https://github.com/typescript-eslint/typescript-eslint/commit/d1f08879338c825a1a20406fe47c051a287d6519)), closes [#2421](https://github.com/typescript-eslint/typescript-eslint/issues/2421) + + + + + # [3.10.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.9.1...v3.10.0) (2020-08-24) diff --git a/lerna.json b/lerna.json index 87ca3691b8dd..4072d24da13a 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "3.10.0", + "version": "3.10.1", "npmClient": "yarn", "useWorkspaces": true, "stream": true diff --git a/packages/eslint-plugin-internal/CHANGELOG.md b/packages/eslint-plugin-internal/CHANGELOG.md index 8aeb586d04c3..e53d3d725107 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. +## [3.10.1](https://github.com/typescript-eslint/typescript-eslint/compare/v3.10.0...v3.10.1) (2020-08-25) + +**Note:** Version bump only for package @typescript-eslint/eslint-plugin-internal + + + + + # [3.10.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.9.1...v3.10.0) (2020-08-24) **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 104990aa4c8f..1adff2164ed8 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": "3.10.0", + "version": "3.10.1", "private": true, "main": "dist/index.js", "scripts": { @@ -13,7 +13,7 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/experimental-utils": "3.10.0", + "@typescript-eslint/experimental-utils": "3.10.1", "prettier": "*" } } diff --git a/packages/eslint-plugin-tslint/CHANGELOG.md b/packages/eslint-plugin-tslint/CHANGELOG.md index fc2a8c861e35..0d598dd62fc4 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. +## [3.10.1](https://github.com/typescript-eslint/typescript-eslint/compare/v3.10.0...v3.10.1) (2020-08-25) + +**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint + + + + + # [3.10.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.9.1...v3.10.0) (2020-08-24) **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 fdb07457acd4..f148419c3b06 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": "3.10.0", + "version": "3.10.1", "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": "3.10.0", + "@typescript-eslint/experimental-utils": "3.10.1", "lodash": "^4.17.15" }, "peerDependencies": { @@ -48,6 +48,6 @@ }, "devDependencies": { "@types/lodash": "^4.14.149", - "@typescript-eslint/parser": "3.10.0" + "@typescript-eslint/parser": "3.10.1" } } diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md index 10ee5ed01f5d..e5510d75c4e6 100644 --- a/packages/eslint-plugin/CHANGELOG.md +++ b/packages/eslint-plugin/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. +## [3.10.1](https://github.com/typescript-eslint/typescript-eslint/compare/v3.10.0...v3.10.1) (2020-08-25) + + +### Bug Fixes + +* **eslint-plugin:** [no-unnecessary-condition] correct regression with unary negations ([#2422](https://github.com/typescript-eslint/typescript-eslint/issues/2422)) ([d1f0887](https://github.com/typescript-eslint/typescript-eslint/commit/d1f08879338c825a1a20406fe47c051a287d6519)), closes [#2421](https://github.com/typescript-eslint/typescript-eslint/issues/2421) + + + + + # [3.10.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.9.1...v3.10.0) (2020-08-24) diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index b80ea9569366..079fefb26685 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin", - "version": "3.10.0", + "version": "3.10.1", "description": "TypeScript plugin for ESLint", "keywords": [ "eslint", @@ -42,7 +42,7 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/experimental-utils": "3.10.0", + "@typescript-eslint/experimental-utils": "3.10.1", "debug": "^4.1.1", "functional-red-black-tree": "^1.0.1", "regexpp": "^3.0.0", diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts index 29f9aa4442d2..2528b8709fcd 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts @@ -165,13 +165,16 @@ export default createRule({ * Checks if a conditional node is necessary: * if the type of the node is always true or always false, it's not necessary. */ - function checkNode(node: TSESTree.Expression): void { + function checkNode( + node: TSESTree.Expression, + isUnaryNotArgument = false, + ): void { // Check if the node is Unary Negation expression and handle it if ( node.type === AST_NODE_TYPES.UnaryExpression && node.operator === '!' ) { - return checkIfUnaryNegationExpressionIsNecessaryConditional(node); + return checkNode(node.argument, true); } // Since typescript array index signature types don't represent the @@ -208,41 +211,19 @@ export default createRule({ ) { return; } - const messageId = isTypeFlagSet(type, ts.TypeFlags.Never) - ? 'never' - : !isPossiblyTruthy(type) - ? 'alwaysFalsy' - : !isPossiblyFalsy(type) - ? 'alwaysTruthy' - : undefined; - - if (messageId) { - context.report({ node, messageId }); + let messageId: MessageId | null = null; + + if (isTypeFlagSet(type, ts.TypeFlags.Never)) { + messageId = 'never'; + } else if (!isPossiblyTruthy(type)) { + messageId = !isUnaryNotArgument ? 'alwaysFalsy' : 'alwaysTruthy'; + } else if (!isPossiblyFalsy(type)) { + messageId = !isUnaryNotArgument ? 'alwaysTruthy' : 'alwaysFalsy'; } - } - - /** - * If it is Unary Negation Expression, check the argument for alwaysTruthy / alwaysFalsy - */ - function checkIfUnaryNegationExpressionIsNecessaryConditional( - node: TSESTree.UnaryExpression, - ): void { - if (isArrayIndexExpression(node.argument)) { - return; - } - const type = getNodeType(node.argument); - const messageId = isTypeFlagSet(type, ts.TypeFlags.Never) - ? 'never' - : isPossiblyTruthy(type) - ? 'alwaysFalsy' - : isPossiblyFalsy(type) - ? 'alwaysTruthy' - : undefined; if (messageId) { context.report({ node, messageId }); } - return; } function checkNodeForNullish(node: TSESTree.Expression): void { @@ -257,13 +238,15 @@ export default createRule({ if (isTypeAnyType(type) || isTypeUnknownType(type)) { return; } - const messageId = isTypeFlagSet(type, ts.TypeFlags.Never) - ? 'never' - : !isPossiblyNullish(type) - ? 'neverNullish' - : isAlwaysNullish(type) - ? 'alwaysNullish' - : undefined; + + let messageId: MessageId | null = null; + if (isTypeFlagSet(type, ts.TypeFlags.Never)) { + messageId = 'never'; + } else if (!isPossiblyNullish(type)) { + messageId = 'neverNullish'; + } else if (isAlwaysNullish(type)) { + messageId = 'alwaysNullish'; + } if (messageId) { context.report({ node, messageId }); diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts index 3a9d0fb450bc..afb0b67a246e 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts @@ -472,37 +472,27 @@ function test(testVal?: boolean) { } } `, - ], - invalid: [ - // Ensure that it's checking in all the right places - { - code: ` -const a = null; -if (!a) { -} - `, - errors: [ruleError(3, 5, 'alwaysTruthy')], - }, - { - code: ` -const a = true; -if (!a) { + ` +declare const x: string[]; +if (!x[0]) { } - `, - errors: [ruleError(3, 5, 'alwaysFalsy')], - }, - { - code: ` -function sayHi(): void { - console.log('Hi!'); + `, + // https://github.com/typescript-eslint/typescript-eslint/issues/2421 + ` +const isEven = (val: number) => val % 2 === 0; +if (!isEven(1)) { } + `, + ` +declare const booleanTyped: boolean; +declare const unknownTyped: unknown; -let speech: never = sayHi(); -if (!speech) { +if (!(booleanTyped || unknownTyped)) { } - `, - errors: [ruleError(7, 5, 'never')], - }, + `, + ], + invalid: [ + // Ensure that it's checking in all the right places { code: ` const b1 = true; @@ -1442,5 +1432,34 @@ function test(testVal?: true) { }, ], }, + // https://github.com/typescript-eslint/typescript-eslint/issues/2255 + { + code: ` +const a = null; +if (!a) { +} + `, + errors: [ruleError(3, 6, 'alwaysTruthy')], + }, + { + code: ` +const a = true; +if (!a) { +} + `, + errors: [ruleError(3, 6, 'alwaysFalsy')], + }, + { + code: ` +function sayHi(): void { + console.log('Hi!'); +} + +let speech: never = sayHi(); +if (!speech) { +} + `, + errors: [ruleError(7, 6, 'never')], + }, ], }); diff --git a/packages/experimental-utils/CHANGELOG.md b/packages/experimental-utils/CHANGELOG.md index 266cf9ce4b61..12742d907a1f 100644 --- a/packages/experimental-utils/CHANGELOG.md +++ b/packages/experimental-utils/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. +## [3.10.1](https://github.com/typescript-eslint/typescript-eslint/compare/v3.10.0...v3.10.1) (2020-08-25) + +**Note:** Version bump only for package @typescript-eslint/experimental-utils + + + + + # [3.10.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.9.1...v3.10.0) (2020-08-24) **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 5e7aa294fa16..594e623554a4 100644 --- a/packages/experimental-utils/package.json +++ b/packages/experimental-utils/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/experimental-utils", - "version": "3.10.0", + "version": "3.10.1", "description": "(Experimental) Utilities for working with TypeScript + ESLint together", "keywords": [ "eslint", @@ -40,8 +40,8 @@ }, "dependencies": { "@types/json-schema": "^7.0.3", - "@typescript-eslint/types": "3.10.0", - "@typescript-eslint/typescript-estree": "3.10.0", + "@typescript-eslint/types": "3.10.1", + "@typescript-eslint/typescript-estree": "3.10.1", "eslint-scope": "^5.0.0", "eslint-utils": "^2.0.0" }, diff --git a/packages/parser/CHANGELOG.md b/packages/parser/CHANGELOG.md index bf9cb88fc0ee..702c9330709f 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. +## [3.10.1](https://github.com/typescript-eslint/typescript-eslint/compare/v3.10.0...v3.10.1) (2020-08-25) + +**Note:** Version bump only for package @typescript-eslint/parser + + + + + # [3.10.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.9.1...v3.10.0) (2020-08-24) **Note:** Version bump only for package @typescript-eslint/parser diff --git a/packages/parser/package.json b/packages/parser/package.json index b3b92a64d583..eedfb438f862 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/parser", - "version": "3.10.0", + "version": "3.10.1", "description": "An ESLint custom parser which leverages TypeScript ESTree", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -44,14 +44,14 @@ }, "dependencies": { "@types/eslint-visitor-keys": "^1.0.0", - "@typescript-eslint/experimental-utils": "3.10.0", - "@typescript-eslint/types": "3.10.0", - "@typescript-eslint/typescript-estree": "3.10.0", + "@typescript-eslint/experimental-utils": "3.10.1", + "@typescript-eslint/types": "3.10.1", + "@typescript-eslint/typescript-estree": "3.10.1", "eslint-visitor-keys": "^1.1.0" }, "devDependencies": { "@types/glob": "^7.1.1", - "@typescript-eslint/shared-fixtures": "3.10.0", + "@typescript-eslint/shared-fixtures": "3.10.1", "glob": "*" }, "peerDependenciesMeta": { diff --git a/packages/scope-manager/CHANGELOG.md b/packages/scope-manager/CHANGELOG.md index 54589536057b..9e1349625709 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. +## [3.10.1](https://github.com/typescript-eslint/typescript-eslint/compare/v3.10.0...v3.10.1) (2020-08-25) + +**Note:** Version bump only for package @typescript-eslint/scope-manager + + + + + # [3.10.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.9.1...v3.10.0) (2020-08-24) **Note:** Version bump only for package @typescript-eslint/scope-manager diff --git a/packages/scope-manager/package.json b/packages/scope-manager/package.json index f6b84d9cd229..58075cbd8606 100644 --- a/packages/scope-manager/package.json +++ b/packages/scope-manager/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/scope-manager", - "version": "3.10.0", + "version": "3.10.1", "description": "TypeScript scope analyser for ESLint", "keywords": [ "eslint", @@ -39,11 +39,11 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/types": "3.10.0", - "@typescript-eslint/visitor-keys": "3.10.0" + "@typescript-eslint/types": "3.10.1", + "@typescript-eslint/visitor-keys": "3.10.1" }, "devDependencies": { - "@typescript-eslint/typescript-estree": "3.10.0", + "@typescript-eslint/typescript-estree": "3.10.1", "glob": "*", "jest-specific-snapshot": "*", "make-dir": "*", diff --git a/packages/shared-fixtures/CHANGELOG.md b/packages/shared-fixtures/CHANGELOG.md index 4175ca136b55..484ccc7cfd64 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. +## [3.10.1](https://github.com/typescript-eslint/typescript-eslint/compare/v3.10.0...v3.10.1) (2020-08-25) + +**Note:** Version bump only for package @typescript-eslint/shared-fixtures + + + + + # [3.10.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.9.1...v3.10.0) (2020-08-24) **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 e774df2ced17..33a5eb919056 100644 --- a/packages/shared-fixtures/package.json +++ b/packages/shared-fixtures/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/shared-fixtures", - "version": "3.10.0", + "version": "3.10.1", "private": true, "scripts": { "build": "tsc -b tsconfig.build.json", diff --git a/packages/types/CHANGELOG.md b/packages/types/CHANGELOG.md index 04bba8223beb..c9d70cc2df88 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. +## [3.10.1](https://github.com/typescript-eslint/typescript-eslint/compare/v3.10.0...v3.10.1) (2020-08-25) + +**Note:** Version bump only for package @typescript-eslint/types + + + + + # [3.10.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.9.1...v3.10.0) (2020-08-24) **Note:** Version bump only for package @typescript-eslint/types diff --git a/packages/types/package.json b/packages/types/package.json index 874a2054a3cf..a2deae04ccbf 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/types", - "version": "3.10.0", + "version": "3.10.1", "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 dda22fd04cca..581055bf5ea3 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. +## [3.10.1](https://github.com/typescript-eslint/typescript-eslint/compare/v3.10.0...v3.10.1) (2020-08-25) + +**Note:** Version bump only for package @typescript-eslint/typescript-estree + + + + + # [3.10.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.9.1...v3.10.0) (2020-08-24) diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 9ccf017328fe..e193ba53954a 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/typescript-estree", - "version": "3.10.0", + "version": "3.10.1", "description": "A parser that converts TypeScript source code into an ESTree compatible form", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -40,8 +40,8 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/types": "3.10.0", - "@typescript-eslint/visitor-keys": "3.10.0", + "@typescript-eslint/types": "3.10.1", + "@typescript-eslint/visitor-keys": "3.10.1", "debug": "^4.1.1", "glob": "^7.1.6", "is-glob": "^4.0.1", @@ -59,7 +59,7 @@ "@types/lodash": "^4.14.149", "@types/semver": "^7.1.0", "@types/tmp": "^0.2.0", - "@typescript-eslint/shared-fixtures": "3.10.0", + "@typescript-eslint/shared-fixtures": "3.10.1", "glob": "*", "jest-specific-snapshot": "*", "make-dir": "*", diff --git a/packages/visitor-keys/CHANGELOG.md b/packages/visitor-keys/CHANGELOG.md index 134f54ea42f1..d350f62021a7 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. +## [3.10.1](https://github.com/typescript-eslint/typescript-eslint/compare/v3.10.0...v3.10.1) (2020-08-25) + +**Note:** Version bump only for package @typescript-eslint/visitor-keys + + + + + # [3.10.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.9.1...v3.10.0) (2020-08-24) **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 35213fd281e7..bb45e82f32fc 100644 --- a/packages/visitor-keys/package.json +++ b/packages/visitor-keys/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/visitor-keys", - "version": "3.10.0", + "version": "3.10.1", "description": "Visitor keys used to help traverse the TypeScript-ESTree AST", "keywords": [ "eslint", @@ -39,7 +39,7 @@ "eslint-visitor-keys": "^1.1.0" }, "devDependencies": { - "@typescript-eslint/types": "3.10.0" + "@typescript-eslint/types": "3.10.1" }, "funding": { "type": "opencollective",