From 736a074b80eafd88376a90e6595a42217d939890 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Tue, 3 Sep 2019 08:25:40 -0700 Subject: [PATCH] =?UTF-8?q?docs(eslint-plugin):=20explicitly=20document=20?= =?UTF-8?q?mixed=20codebase=20usage=20fo=E2=80=A6=20(#939)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rules/explicit-function-return-type.md | 22 ++++++++++++++ .../rules/explicit-member-accessibility.md | 30 ++++++++++++++++--- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md index 5f729129b7a3..7e3093ebfaa0 100644 --- a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md +++ b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md @@ -78,6 +78,28 @@ const defaults = { }; ``` +### Configuring in a mixed JS/TS codebase + +If you are working on a codebase within which you lint non-TypeScript code (i.e. `.js`/`.jsx`), you should ensure that you should use [ESLint `overrides`](https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files) to only enable the rule on `.ts`/`.tsx` files. If you don't, then you will get unfixable lint errors reported within `.js`/`.jsx` files. + +```jsonc +{ + "rules": { + // disable the rule for all files + "@typescript-eslint/explicit-function-return-type": "off" + }, + "overrides": [ + { + // enable the rule specifically for TypeScript files + "files": ["*.ts", "*.tsx"], + "rules": { + "@typescript-eslint/explicit-function-return-type": ["error"] + } + } + ] +} +``` + ### allowExpressions Examples of **incorrect** code for this rule with `{ allowExpressions: true }`: diff --git a/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md b/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md index ce9163700c56..38be4f21a3c1 100644 --- a/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md +++ b/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md @@ -18,7 +18,7 @@ type AccessibilityLevel = | 'no-public' // don't require public | 'off'; // don't check -interface Config { +type Options = { accessibility?: AccessibilityLevel; overrides?: { accessors?: AccessibilityLevel; @@ -28,14 +28,36 @@ interface Config { parameterProperties?: AccessibilityLevel; }; } + +const defaultOptions: Options = { + accessibility: 'explicit', +}; ``` -Default config: +### Configuring in a mixed JS/TS codebase + +If you are working on a codebase within which you lint non-TypeScript code (i.e. `.js`/`.jsx`), you should ensure that you should use [ESLint `overrides`](https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files) to only enable the rule on `.ts`/`.tsx` files. If you don't, then you will get unfixable lint errors reported within `.js`/`.jsx` files. -```JSON -{ "accessibility": "explicit" } +```jsonc +{ + "rules": { + // disable the rule for all files + "@typescript-eslint/explicit-member-accessibility": "off" + }, + "overrides": [ + { + // enable the rule specifically for TypeScript files + "files": ["*.ts", "*.tsx"], + "rules": { + "@typescript-eslint/explicit-member-accessibility": ["error"] + } + } + ] +} ``` +### `accessibility` + This rule in it's default state requires no configuration and will enforce that every class member has an accessibility modifier. If you would like to allow for some implicit public members then you have the following options: A possible configuration could be: