From fc0bf724c6bb7b37296927c8ec6b33470a03e9f5 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Wed, 27 May 2020 10:28:42 -0700 Subject: [PATCH 1/4] docs: add FAQ for restricted syntax --- docs/getting-started/linting/FAQ.md | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/docs/getting-started/linting/FAQ.md b/docs/getting-started/linting/FAQ.md index 799b7b626bad..2a72964e0dc8 100644 --- a/docs/getting-started/linting/FAQ.md +++ b/docs/getting-started/linting/FAQ.md @@ -8,6 +8,7 @@ - [I am using a rule from ESLint core, and it doesn't work correctly with TypeScript code](#i-am-using-a-rule-from-eslint-core-and-it-doesnt-work-correctly-with-typescript-code) - [One of my lint rules isn't working correctly on a pure JavaScript file](#one-of-my-lint-rules-isnt-working-correctly-on-a-pure-javascript-file) - [TypeScript should be installed locally](#typescript-should-be-installed-locally) +- [How can I ban ``?](#how-can-i-ban-specific-language-feature) --- @@ -169,3 +170,48 @@ If you have some pure JavaScript code that you do not want to apply certain lint Make sure that you have installed TypeScript locally i.e. by using `npm install typescript`, not `npm install -g typescript`, or by using `yarn add typescript`, not `yarn global add typescript`. See https://github.com/typescript-eslint/typescript-eslint/issues/2041 for more information. + +
+
+
+ +--- + +
+
+
+ +## How can I ban ``? + +ESLint core contains the rule [`no-restricted-syntax`](https://eslint.org/docs/rules/no-restricted-syntax). This generic rule allows you to specify a [selector](https://eslint.org/docs/developer-guide/selectors) for the code you want to ban, along with a custom error message. + +You can use a tool like [AST Explorer](https://astexplorer.net/) to help in figuring out the structure of the AST that you want to ban. + +For example, you can ban enums (or some variation of) using one of the following configs: + +```jsonc +{ + "rules": { + "no-restricted-syntax": [ + "error", + // ban all enums + { + "selector": "TSEnumDeclaration", + "message": "My reason for not using any enums at all" + }, + + // ban just const enums + { + "selector": "TSEnumDeclaration[const=true]", + "message": "My reason for not using const enums" + }, + + // ban just non-const enums + { + "selector": "TSEnumDeclaration:not([const=true])", + "message": "My reason for not using non-const enums" + } + ] + } +} +``` From efb29be95f735c4cd58c0cb5193926690abe4783 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Wed, 27 May 2020 10:39:37 -0700 Subject: [PATCH 2/4] docs: update FAQ for typed linting --- docs/getting-started/linting/FAQ.md | 9 +-------- docs/getting-started/linting/TYPED_LINTING.md | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/getting-started/linting/FAQ.md b/docs/getting-started/linting/FAQ.md index 2a72964e0dc8..3fab7b587c9b 100644 --- a/docs/getting-started/linting/FAQ.md +++ b/docs/getting-started/linting/FAQ.md @@ -82,14 +82,7 @@ This error means that the file that's being linted is not included in any of the There are a couple of solutions to this, depending on what you want to achieve. -- If you **do not** want to lint the file: - - Use [one of the options ESLint offers](https://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories) to ignore files, like a `.eslintignore` file, or `ignorePatterns` config. -- If you **do** want to lint the file: - - If you **do not** want to lint the file with [type-aware linting](./TYPED_LINTING.md): - - Use [ESLint's `overrides` configuration](https://eslint.org/docs/user-guide/configuring#configuration-based-on-glob-patterns) to configure the file to not be parsed with type information. - - If you **do** want to lint the file with [type-aware linting](./TYPED_LINTING.md): - - Check the `include` option of each of the tsconfigs that you provide to `parserOptions.project` - you must ensure that all files match an `include` glob, or else our tooling will not be able to find it. - - If your file shouldn't be a part of one of your existing tsconfigs (for example, it is a script/tool local to the repo), then consider creating a new tsconfig (we advise calling it `tsconfig.eslint.json`) in your project root which lists this file in its `include`. +See our docs on [type aware linting](./TYPED_LINTING.md##i-get-errors-telling-me-the-file-must-be-included-in-at-least-one-of-the-projects-provided) for solutions to this.

diff --git a/docs/getting-started/linting/TYPED_LINTING.md b/docs/getting-started/linting/TYPED_LINTING.md index 188a7e71ed1d..3b10d793db10 100644 --- a/docs/getting-started/linting/TYPED_LINTING.md +++ b/docs/getting-started/linting/TYPED_LINTING.md @@ -43,6 +43,23 @@ Additionally, most users primarily consume lint errors via IDE plugins which, th We strongly recommend you do use it, but the above information is included so that you can make your own, informed decision. +## I get errors telling me "The file must be included in at least one of the projects provided" + +This error means that the file that's being linted is not included in any of the tsconfig files you provided us. A lot of the time this happens when users have test files or similar that are not included in their normal tsconfigs. + +There are a couple of solutions to this, depending on what you want to achieve. + +- If you **do not** want to lint the file: + - Use [one of the options ESLint offers](https://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories) to ignore files, like a `.eslintignore` file, or `ignorePatterns` config. +- If you **do** want to lint the file: + - If you **do not** want to lint the file with [type-aware linting](./TYPED_LINTING.md): + - Use [ESLint's `overrides` configuration](https://eslint.org/docs/user-guide/configuring#configuration-based-on-glob-patterns) to configure the file to not be parsed with type information. + - If you **do** want to lint the file with [type-aware linting](./TYPED_LINTING.md): + - Check the `include` option of each of the tsconfigs that you provide to `parserOptions.project` - you must ensure that all files match an `include` glob, or else our tooling will not be able to find it. + - If your file shouldn't be a part of one of your existing tsconfigs (for example, it is a script/tool local to the repo), then consider creating a new tsconfig (we advise calling it `tsconfig.eslint.json`) in your project root which lists this file in its `include`. For an example of this, you can check out the configuration we use in this repo: + - [`tsconfig.eslint.json`](../../../tsconfig.eslint.json) + - [`.eslintrc.js`](../../../.eslintrc.js) + ## FAQ If you're having problems getting this working, please have a look at our [Troubleshooting FAQ](./FAQ.md). From 8df509f1954fc347688ada4a78c479116fc3d7b3 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Wed, 27 May 2020 10:43:19 -0700 Subject: [PATCH 3/4] chore: add config.yml linking to FAQ --- .github/ISSUE_TEMPLATE/config.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/config.yml diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 000000000000..ed86108f5ebe --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,10 @@ +blank_issues_enabled: false +contact_links: + - + name: FAQ + about: Please check out our FAQ before filing new issues + url: https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md + - + name: Getting Started Guide + about: If you're looking for help setting up check out our getting started guide + url: https://github.com/typescript-eslint/typescript-eslint/tree/master/docs/getting-started From dbb70ee41600760b64521bcc63528aa5c30fca85 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Wed, 27 May 2020 10:45:07 -0700 Subject: [PATCH 4/4] docs: fix link --- docs/getting-started/linting/FAQ.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started/linting/FAQ.md b/docs/getting-started/linting/FAQ.md index 3fab7b587c9b..aa55b60b7513 100644 --- a/docs/getting-started/linting/FAQ.md +++ b/docs/getting-started/linting/FAQ.md @@ -82,7 +82,7 @@ This error means that the file that's being linted is not included in any of the There are a couple of solutions to this, depending on what you want to achieve. -See our docs on [type aware linting](./TYPED_LINTING.md##i-get-errors-telling-me-the-file-must-be-included-in-at-least-one-of-the-projects-provided) for solutions to this. +See our docs on [type aware linting](./TYPED_LINTING.md#i-get-errors-telling-me-the-file-must-be-included-in-at-least-one-of-the-projects-provided) for solutions to this.