From 4670aabef31d9017ad302f206b9c2f18d53c8ee4 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Mon, 3 Feb 2020 12:07:30 -0800 Subject: [PATCH 1/5] fix(eslint-plugin): [unbound-method] blacklist a few unbound natives (#1562) --- .../eslint-plugin/src/rules/unbound-method.ts | 74 +++++++++++++++---- .../tests/rules/unbound-method.test.ts | 10 +++ 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/packages/eslint-plugin/src/rules/unbound-method.ts b/packages/eslint-plugin/src/rules/unbound-method.ts index bdd740fb4d4c..1e9cb9131ada 100644 --- a/packages/eslint-plugin/src/rules/unbound-method.ts +++ b/packages/eslint-plugin/src/rules/unbound-method.ts @@ -18,8 +18,53 @@ export type Options = [Config]; export type MessageIds = 'unbound'; -const nativelyBoundMembers = ([ - 'Promise', +/** + * The following is a list of exceptions to the rule + * Generated via the following script. + * This is statically defined to save making purposely invalid calls every lint run + * ``` +SUPPORTED_GLOBALS.flatMap(namespace => { + const object = window[namespace]; + return Object.getOwnPropertyNames(object) + .filter( + name => + !name.startsWith('_') && + typeof object[name] === 'function', + ) + .map(name => { + try { + const x = object[name]; + x(); + } catch (e) { + if (e.message.includes("called on non-object")) { + return `${namespace}.${name}`; + } + } + }); +}).filter(Boolean); + * ``` + */ +const nativelyNotBoundMembers = new Set([ + 'Promise.all', + 'Promise.race', + 'Promise.resolve', + 'Promise.reject', + 'Promise.allSettled', + 'Object.defineProperties', + 'Object.defineProperty', + 'Reflect.defineProperty', + 'Reflect.deleteProperty', + 'Reflect.get', + 'Reflect.getOwnPropertyDescriptor', + 'Reflect.getPrototypeOf', + 'Reflect.has', + 'Reflect.isExtensible', + 'Reflect.ownKeys', + 'Reflect.preventExtensions', + 'Reflect.set', + 'Reflect.setPrototypeOf', +]); +const SUPPORTED_GLOBALS = [ 'Number', 'Object', 'String', // eslint-disable-line @typescript-eslint/internal/prefer-ast-types-enum @@ -35,18 +80,19 @@ const nativelyBoundMembers = ([ 'Math', 'JSON', 'Intl', -] as const) - .map(namespace => { - const object = global[namespace]; - return Object.getOwnPropertyNames(object) - .filter( - name => - !name.startsWith('_') && - typeof (object as Record)[name] === 'function', - ) - .map(name => `${namespace}.${name}`); - }) - .reduce((arr, names) => arr.concat(names), []); +] as const; +const nativelyBoundMembers = SUPPORTED_GLOBALS.map(namespace => { + const object = global[namespace]; + return Object.getOwnPropertyNames(object) + .filter( + name => + !name.startsWith('_') && + typeof (object as Record)[name] === 'function', + ) + .map(name => `${namespace}.${name}`); +}) + .reduce((arr, names) => arr.concat(names), []) + .filter(name => !nativelyNotBoundMembers.has(name)); const isMemberNotImported = ( symbol: ts.Symbol, diff --git a/packages/eslint-plugin/tests/rules/unbound-method.test.ts b/packages/eslint-plugin/tests/rules/unbound-method.test.ts index 2bf38e1c83e2..619b681c4ea5 100644 --- a/packages/eslint-plugin/tests/rules/unbound-method.test.ts +++ b/packages/eslint-plugin/tests/rules/unbound-method.test.ts @@ -324,5 +324,15 @@ const x = CommunicationError.prototype.foo; }, ], }, + { + // Promise.all is not auto-bound to Promise + code: 'const x = Promise.all', + errors: [ + { + line: 1, + messageId: 'unbound', + }, + ], + }, ], }); From 10d86b1f648896c418041e5eaee5198d274e7d27 Mon Sep 17 00:00:00 2001 From: Jens Duttke Date: Tue, 4 Feb 2020 17:48:03 +0100 Subject: [PATCH 2/5] docs(eslint-plugin): [no-dupe-class-members] fix typo (#1566) --- .../eslint-plugin/docs/rules/no-dupe-class-members.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/no-dupe-class-members.md b/packages/eslint-plugin/docs/rules/no-dupe-class-members.md index b096ea0c808f..d0b3b57d988a 100644 --- a/packages/eslint-plugin/docs/rules/no-dupe-class-members.md +++ b/packages/eslint-plugin/docs/rules/no-dupe-class-members.md @@ -2,7 +2,7 @@ ## Rule Details -This rule extends the base [`eslint/no-no-dupe-class-members`](https://eslint.org/docs/rules/no-no-dupe-class-members) rule. +This rule extends the base [`eslint/no-dupe-class-members`](https://eslint.org/docs/rules/no-dupe-class-members) rule. It adds support for TypeScript's method overload definitions. ## How to use @@ -10,9 +10,9 @@ It adds support for TypeScript's method overload definitions. ```cjson { // note you must disable the base rule as it can report incorrect errors - "no-no-dupe-class-members": "off", - "@typescript-eslint/no-no-dupe-class-members": ["error"] + "no-dupe-class-members": "off", + "@typescript-eslint/no-dupe-class-members": ["error"] } ``` -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/no-no-dupe-class-members.md) +Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/no-dupe-class-members.md) From e9cf734ed5f689ab65ed2719e557649e7c5e5727 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Thu, 6 Feb 2020 10:35:29 -0800 Subject: [PATCH 3/5] docs(eslint-plugin): fix typo in readme --- packages/eslint-plugin/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index 48bc4300eec9..0f55ace3d5de 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -10,8 +10,8 @@ ## Getting Started -**[You can find our Getting Started docs here](../../docs/getting-started/linting/README.md)** -**[You can find our FAQ / Troubleshooting docs here](../../docs/getting-started/linting/FAQ.md)** +- **[You can find our Getting Started docs here](../../docs/getting-started/linting/README.md)** +- **[You can find our FAQ / Troubleshooting docs here](../../docs/getting-started/linting/FAQ.md)** These docs walk you through setting up ESLint, this plugin, and our parser. If you know what you're doing and just want to quick start, read on... From 4c12dac075f774801a145cd29c4c7eff64f98fdc Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Thu, 6 Feb 2020 17:23:35 -0800 Subject: [PATCH 4/5] fix(typescript-estree): ts returning wrong file with project references (#1575) --- .../src/create-program/createProjectProgram.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/typescript-estree/src/create-program/createProjectProgram.ts b/packages/typescript-estree/src/create-program/createProjectProgram.ts index b81409e647e6..c7949b02811a 100644 --- a/packages/typescript-estree/src/create-program/createProjectProgram.ts +++ b/packages/typescript-estree/src/create-program/createProjectProgram.ts @@ -9,6 +9,13 @@ const log = debug('typescript-eslint:typescript-estree:createProjectProgram'); const DEFAULT_EXTRA_FILE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx']; +function getExtension(fileName: string | undefined): string | null { + if (!fileName) { + return null; + } + return fileName.endsWith('.d.ts') ? '.d.ts' : path.extname(fileName); +} + /** * @param code The code of the file being linted * @param createDefaultProgram True if the default program should be created @@ -26,6 +33,14 @@ function createProjectProgram( getProgramsForProjects(code, extra.filePath, extra), currentProgram => { const ast = currentProgram.getSourceFile(extra.filePath); + + // working around https://github.com/typescript-eslint/typescript-eslint/issues/1573 + const expectedExt = getExtension(extra.filePath); + const returnedExt = getExtension(ast?.fileName); + if (expectedExt !== returnedExt) { + return; + } + return ast && { ast, program: currentProgram }; }, ); From 1c8f0df133a861a722d5893ee6a6bca3b7c05436 Mon Sep 17 00:00:00 2001 From: James Henry Date: Mon, 10 Feb 2020 18:02:09 +0000 Subject: [PATCH 5/5] chore: publish v2.19.1 --- CHANGELOG.md | 12 ++++++++++++ lerna.json | 2 +- packages/eslint-plugin-internal/CHANGELOG.md | 8 ++++++++ packages/eslint-plugin-internal/package.json | 4 ++-- packages/eslint-plugin-tslint/CHANGELOG.md | 8 ++++++++ packages/eslint-plugin-tslint/package.json | 6 +++--- packages/eslint-plugin/CHANGELOG.md | 11 +++++++++++ packages/eslint-plugin/package.json | 4 ++-- packages/experimental-utils/CHANGELOG.md | 8 ++++++++ packages/experimental-utils/package.json | 4 ++-- packages/parser/CHANGELOG.md | 8 ++++++++ packages/parser/package.json | 8 ++++---- packages/shared-fixtures/CHANGELOG.md | 8 ++++++++ packages/shared-fixtures/package.json | 2 +- packages/typescript-estree/CHANGELOG.md | 11 +++++++++++ packages/typescript-estree/package.json | 4 ++-- 16 files changed, 91 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfd47e568396..f73c65c222ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.19.1](https://github.com/typescript-eslint/typescript-eslint/compare/v2.19.0...v2.19.1) (2020-02-10) + + +### Bug Fixes + +* **eslint-plugin:** [unbound-method] blacklist a few unbound natives ([#1562](https://github.com/typescript-eslint/typescript-eslint/issues/1562)) ([4670aab](https://github.com/typescript-eslint/typescript-eslint/commit/4670aabef31d9017ad302f206b9c2f18d53c8ee4)) +* **typescript-estree:** ts returning wrong file with project references ([#1575](https://github.com/typescript-eslint/typescript-eslint/issues/1575)) ([4c12dac](https://github.com/typescript-eslint/typescript-eslint/commit/4c12dac075f774801a145cd29c4c7eff64f98fdc)) + + + + + # [2.19.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.18.0...v2.19.0) (2020-02-03) diff --git a/lerna.json b/lerna.json index cf17872b696c..bc5c630f9644 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "2.19.0", + "version": "2.19.1", "npmClient": "yarn", "useWorkspaces": true, "stream": true diff --git a/packages/eslint-plugin-internal/CHANGELOG.md b/packages/eslint-plugin-internal/CHANGELOG.md index 26da15e2085f..497e81cc0869 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. +## [2.19.1](https://github.com/typescript-eslint/typescript-eslint/compare/v2.19.0...v2.19.1) (2020-02-10) + +**Note:** Version bump only for package @typescript-eslint/eslint-plugin-internal + + + + + # [2.19.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.18.0...v2.19.0) (2020-02-03) **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 616cb9a3927c..55fbec3eb054 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": "2.19.0", + "version": "2.19.1", "private": true, "main": "dist/index.js", "scripts": { @@ -12,6 +12,6 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/experimental-utils": "2.19.0" + "@typescript-eslint/experimental-utils": "2.19.1" } } diff --git a/packages/eslint-plugin-tslint/CHANGELOG.md b/packages/eslint-plugin-tslint/CHANGELOG.md index e8b1cd7495da..5b6403d89496 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. +## [2.19.1](https://github.com/typescript-eslint/typescript-eslint/compare/v2.19.0...v2.19.1) (2020-02-10) + +**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint + + + + + # [2.19.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.18.0...v2.19.0) (2020-02-03) **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 72574ce9c385..5f1727d807a2 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": "2.19.0", + "version": "2.19.1", "main": "dist/index.js", "typings": "src/index.ts", "description": "TSLint wrapper plugin for ESLint", @@ -31,7 +31,7 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/experimental-utils": "2.19.0", + "@typescript-eslint/experimental-utils": "2.19.1", "lodash": "^4.17.15" }, "peerDependencies": { @@ -41,6 +41,6 @@ }, "devDependencies": { "@types/lodash": "^4.14.149", - "@typescript-eslint/parser": "2.19.0" + "@typescript-eslint/parser": "2.19.1" } } diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md index fe3e3db0a7e1..59fd1f7dd45d 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. +## [2.19.1](https://github.com/typescript-eslint/typescript-eslint/compare/v2.19.0...v2.19.1) (2020-02-10) + + +### Bug Fixes + +* **eslint-plugin:** [unbound-method] blacklist a few unbound natives ([#1562](https://github.com/typescript-eslint/typescript-eslint/issues/1562)) ([4670aab](https://github.com/typescript-eslint/typescript-eslint/commit/4670aabef31d9017ad302f206b9c2f18d53c8ee4)) + + + + + # [2.19.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.18.0...v2.19.0) (2020-02-03) diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 6079ed6566a5..c5ea76cfa78b 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin", - "version": "2.19.0", + "version": "2.19.1", "description": "TypeScript plugin for ESLint", "keywords": [ "eslint", @@ -41,7 +41,7 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/experimental-utils": "2.19.0", + "@typescript-eslint/experimental-utils": "2.19.1", "eslint-utils": "^1.4.3", "functional-red-black-tree": "^1.0.1", "regexpp": "^3.0.0", diff --git a/packages/experimental-utils/CHANGELOG.md b/packages/experimental-utils/CHANGELOG.md index 4ed61479dc28..cddf7a341b1a 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. +## [2.19.1](https://github.com/typescript-eslint/typescript-eslint/compare/v2.19.0...v2.19.1) (2020-02-10) + +**Note:** Version bump only for package @typescript-eslint/experimental-utils + + + + + # [2.19.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.18.0...v2.19.0) (2020-02-03) **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 4b9992f2f219..64f07598e840 100644 --- a/packages/experimental-utils/package.json +++ b/packages/experimental-utils/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/experimental-utils", - "version": "2.19.0", + "version": "2.19.1", "description": "(Experimental) Utilities for working with TypeScript + ESLint together", "keywords": [ "eslint", @@ -37,7 +37,7 @@ }, "dependencies": { "@types/json-schema": "^7.0.3", - "@typescript-eslint/typescript-estree": "2.19.0", + "@typescript-eslint/typescript-estree": "2.19.1", "eslint-scope": "^5.0.0" }, "peerDependencies": { diff --git a/packages/parser/CHANGELOG.md b/packages/parser/CHANGELOG.md index 3cc542e1629d..0126631fabd8 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. +## [2.19.1](https://github.com/typescript-eslint/typescript-eslint/compare/v2.19.0...v2.19.1) (2020-02-10) + +**Note:** Version bump only for package @typescript-eslint/parser + + + + + # [2.19.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.18.0...v2.19.0) (2020-02-03) **Note:** Version bump only for package @typescript-eslint/parser diff --git a/packages/parser/package.json b/packages/parser/package.json index 5eca53f1093d..d99e6755f8ea 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/parser", - "version": "2.19.0", + "version": "2.19.1", "description": "An ESLint custom parser which leverages TypeScript ESTree", "main": "dist/parser.js", "types": "dist/parser.d.ts", @@ -43,13 +43,13 @@ }, "dependencies": { "@types/eslint-visitor-keys": "^1.0.0", - "@typescript-eslint/experimental-utils": "2.19.0", - "@typescript-eslint/typescript-estree": "2.19.0", + "@typescript-eslint/experimental-utils": "2.19.1", + "@typescript-eslint/typescript-estree": "2.19.1", "eslint-visitor-keys": "^1.1.0" }, "devDependencies": { "@types/glob": "^7.1.1", - "@typescript-eslint/shared-fixtures": "2.19.0", + "@typescript-eslint/shared-fixtures": "2.19.1", "glob": "*" }, "peerDependenciesMeta": { diff --git a/packages/shared-fixtures/CHANGELOG.md b/packages/shared-fixtures/CHANGELOG.md index b0edc9eb067f..97b31d5165d1 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. +## [2.19.1](https://github.com/typescript-eslint/typescript-eslint/compare/v2.19.0...v2.19.1) (2020-02-10) + +**Note:** Version bump only for package @typescript-eslint/shared-fixtures + + + + + # [2.19.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.18.0...v2.19.0) (2020-02-03) **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 c7d2753bcf9d..541023057542 100644 --- a/packages/shared-fixtures/package.json +++ b/packages/shared-fixtures/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/shared-fixtures", - "version": "2.19.0", + "version": "2.19.1", "private": true, "scripts": { "build": "tsc -b tsconfig.build.json", diff --git a/packages/typescript-estree/CHANGELOG.md b/packages/typescript-estree/CHANGELOG.md index 04358210a15f..be10d8762d06 100644 --- a/packages/typescript-estree/CHANGELOG.md +++ b/packages/typescript-estree/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. +## [2.19.1](https://github.com/typescript-eslint/typescript-eslint/compare/v2.19.0...v2.19.1) (2020-02-10) + + +### Bug Fixes + +* **typescript-estree:** ts returning wrong file with project references ([#1575](https://github.com/typescript-eslint/typescript-eslint/issues/1575)) ([4c12dac](https://github.com/typescript-eslint/typescript-eslint/commit/4c12dac075f774801a145cd29c4c7eff64f98fdc)) + + + + + # [2.19.0](https://github.com/typescript-eslint/typescript-eslint/compare/v2.18.0...v2.19.0) (2020-02-03) diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index c8cf6de72f80..7a8ea91391e2 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/typescript-estree", - "version": "2.19.0", + "version": "2.19.1", "description": "A parser that converts TypeScript source code into an ESTree compatible form", "main": "dist/parser.js", "types": "dist/parser.d.ts", @@ -58,7 +58,7 @@ "@types/lodash": "^4.14.149", "@types/semver": "^6.2.0", "@types/tmp": "^0.1.0", - "@typescript-eslint/shared-fixtures": "2.19.0", + "@typescript-eslint/shared-fixtures": "2.19.1", "tmp": "^0.1.0", "typescript": "*" },