From 52944bd7a1b8b1beb0cd2658c78ce53832766a38 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Sat, 27 Apr 2019 11:47:29 -0700 Subject: [PATCH 1/4] chore: Update plugin issue template (#472) * chore: Update plugin issue template Updated some of the information to attempt to get people to submit more info with bugs * format * format --- .../eslint-plugin-typescript.md | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/eslint-plugin-typescript.md b/.github/ISSUE_TEMPLATE/eslint-plugin-typescript.md index ddae219da63..8e382d30f23 100644 --- a/.github/ISSUE_TEMPLATE/eslint-plugin-typescript.md +++ b/.github/ISSUE_TEMPLATE/eslint-plugin-typescript.md @@ -1,7 +1,7 @@ --- name: '@typescript-eslint/eslint-plugin' about: Report an issue with the '@typescript-eslint/eslint-plugin' package -title: '' +title: '[rulename] ' labels: 'package: eslint-plugin, triage' assignees: '' --- @@ -9,19 +9,24 @@ assignees: '' **Repro** ```JSON { "rules": { - "typescript/": "" + "typescript/": [""] } } ``` @@ -36,6 +41,13 @@ Please try to avoid code that isn't directly related to the bug, as it makes it **Additional Info** + + **Versions** | package | version | From e99ca8155c9f889f2579e2651a1268ee9da6a7b0 Mon Sep 17 00:00:00 2001 From: Ricky Lippmann <3674067+ldrick@users.noreply.github.com> Date: Tue, 30 Apr 2019 01:30:38 +0200 Subject: [PATCH 2/4] fix(eslint-plugin): support switch statement [unbound-method] (#485) --- packages/eslint-plugin/src/rules/unbound-method.ts | 1 + .../tests/rules/unbound-method.test.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/eslint-plugin/src/rules/unbound-method.ts b/packages/eslint-plugin/src/rules/unbound-method.ts index 621e95ec7c5..a8a0f41b90d 100644 --- a/packages/eslint-plugin/src/rules/unbound-method.ts +++ b/packages/eslint-plugin/src/rules/unbound-method.ts @@ -97,6 +97,7 @@ function isSafeUse(node: TSESTree.Node): boolean { case AST_NODE_TYPES.IfStatement: case AST_NODE_TYPES.ForStatement: case AST_NODE_TYPES.MemberExpression: + case AST_NODE_TYPES.SwitchStatement: case AST_NODE_TYPES.UpdateExpression: case AST_NODE_TYPES.WhileStatement: return true; diff --git a/packages/eslint-plugin/tests/rules/unbound-method.test.ts b/packages/eslint-plugin/tests/rules/unbound-method.test.ts index 8b4ed003fd4..e2757630acb 100644 --- a/packages/eslint-plugin/tests/rules/unbound-method.test.ts +++ b/packages/eslint-plugin/tests/rules/unbound-method.test.ts @@ -98,6 +98,20 @@ instane.boundStatic && 0; ContainsMethods.boundStatic ? 1 : 0; ContainsMethods.unboundStatic ? 1 : 0; `, + `interface RecordA { + readonly type: "A" + readonly a: {} +} +interface RecordB { + readonly type: "B" + readonly b: {} +} +type AnyRecord = RecordA | RecordB + +function test(obj: AnyRecord) { + switch (obj.type) { + } +}`, ], invalid: [ { From a205db81f581027ed7f7f10be59449e264553848 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Mon, 29 Apr 2019 22:42:39 -0400 Subject: [PATCH 3/4] docs(eslint-plugin): add recommended config readme (#457) * docs(eslint-plugin): add recommended config readme * Typescript -> TypeScript --- packages/eslint-plugin/src/configs/README.md | 42 ++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 packages/eslint-plugin/src/configs/README.md diff --git a/packages/eslint-plugin/src/configs/README.md b/packages/eslint-plugin/src/configs/README.md new file mode 100644 index 00000000000..c9e8d9769f9 --- /dev/null +++ b/packages/eslint-plugin/src/configs/README.md @@ -0,0 +1,42 @@ +# Premade configs + +These configs exist for your convenience. They contain configuration intended to save you time and effort when configuring your project by disabling rules known to conflict with this repository, or cause issues in typesript codebases. + +## All + +TODO when all config is added. + +## Recommended + +The recommended set is an **_opinionated_** set of rules that we think you should use because: + +1. They help you adhere to TypeScript best practices. +2. They help catch probable issue vectors in your code. + +That being said, it is not the only way to use `@typescript-eslint/eslint-plugin`, nor is it the way that will necesasrily work 100% for your project/company. It has been built based off of two main things: + +1. TypeScript best practices collected and collated from places like: + - [TypeScript repo](https://github.com/Microsoft/TypeScript). + - [TypeScript documentation](https://www.typescriptlang.org/docs/home.html). + - The style used by many OSS TypeScript projects. +2. The combined state of community contributed rulesets at the time of creation. + +We will not add new rules to the recommended set unless we release a major package version (i.e. it is seen as a breaking change). + +### Altering the recommended set to suit your project + +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 +{ + "extends": ["plugin:@typescript-eslint/recommended"], + "rules": { + // our project thinks using IPrefixedInterfaces is a good practice + "@typescript-eslint/interface-name-prefix": ["error", "always"] + } +} +``` + +### Suggesting changes to the recommended set + +If you feel _very_, **very**, **_very_** strongly that a specific rule should (or should not) be in the recommended ruleset, please feel free to file an issue along with a **detailed** argument explaning your reasoning. We expect to see you citing concrete evidence supporting why (or why not) a rule is considered best practice. **Please note that if your reasoning is along the lines of "it's what my project/company does", or "I don't like the rule", then we will likely close the request without discussion.** From 6fd3e10904bc40de1fe9207a855c9f8525bf420f Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Mon, 29 Apr 2019 22:47:36 -0400 Subject: [PATCH 4/4] docs(eslint-plugin): Correct await-thenable recommended (#479) --- packages/eslint-plugin/README.md | 2 +- packages/eslint-plugin/src/rules/await-thenable.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index 16908c6c9a9..044ff064372 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -112,7 +112,7 @@ Then you should add `airbnb` (or `airbnb-base`) to your `extends` section of `.e | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | -------- | ----------------- | | [`@typescript-eslint/adjacent-overload-signatures`](./docs/rules/adjacent-overload-signatures.md) | Require that member overloads be consecutive (`adjacent-overload-signatures` from TSLint) | :heavy_check_mark: | | | | [`@typescript-eslint/array-type`](./docs/rules/array-type.md) | Requires using either `T[]` or `Array` for arrays (`array-type` from TSLint) | :heavy_check_mark: | :wrench: | | -| [`@typescript-eslint/await-thenable`](./docs/rules/await-thenable.md) | Disallow awaiting a value that is not a Promise (`await-promise` from TSLint) | :heavy_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/await-thenable`](./docs/rules/await-thenable.md) | Disallow awaiting a value that is not a Promise (`await-promise` from TSLint) | | | :thought_balloon: | | [`@typescript-eslint/ban-ts-ignore`](./docs/rules/ban-ts-ignore.md) | Bans “// @ts-ignore” comments from being used (`ban-ts-ignore` from TSLint) | | | | | [`@typescript-eslint/ban-types`](./docs/rules/ban-types.md) | Enforces that types will not to be used (`ban-types` from TSLint) | :heavy_check_mark: | :wrench: | | | [`@typescript-eslint/camelcase`](./docs/rules/camelcase.md) | Enforce camelCase naming convention | :heavy_check_mark: | | | diff --git a/packages/eslint-plugin/src/rules/await-thenable.ts b/packages/eslint-plugin/src/rules/await-thenable.ts index a52469ef6e3..3bee5b029f7 100644 --- a/packages/eslint-plugin/src/rules/await-thenable.ts +++ b/packages/eslint-plugin/src/rules/await-thenable.ts @@ -9,7 +9,7 @@ export default util.createRule({ docs: { description: 'Disallows awaiting a value that is not a Thenable', category: 'Best Practices', - recommended: 'error', + recommended: false, tslintName: 'await-thenable', }, messages: {