From 6042b7751ff7cc7915eec1473ee743042155d22a Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Fri, 26 May 2023 10:17:39 -0700 Subject: [PATCH] feat: add recommended-typescript-flavor configs --- .README/README.md | 30 ++++++++++++++++++------------ README.md | 30 ++++++++++++++++++------------ src/index.js | 20 ++++++++++++++++++++ 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/.README/README.md b/.README/README.md index 92c363e24..d92e9a146 100644 --- a/.README/README.md +++ b/.README/README.md @@ -118,25 +118,31 @@ as failing errors, you may use the "recommended-error" config: ``` If you plan to use TypeScript syntax (and not just "typescript" -`mode` to indicate the JSDoc flavor is TypeScript), you can configure -the following: +`mode` to indicate the JSDoc flavor is TypeScript), you can use: -```javascript +```json { - "rules": { - "jsdoc/no-types": 1, - "jsdoc/require-param-type": 0, - "jsdoc/require-property-type": 0, - "jsdoc/require-returns-type": 0, - } + "extends": ["plugin:jsdoc/recommended-typescript"] } ``` -...or just use: +...or to report with failing errors instead of mere warnings: ```json { - "extends": ["plugin:jsdoc/recommended-typescript"] + "extends": ["plugin:jsdoc/recommended-typescript-error"] +} +``` + +If you are not using TypeScript syntax (your source files are still `.js` files) +but you are using the TypeScript flavor within JSDoc (i.e., the default +"typescript" `mode` in `eslint-plugin-jsdoc`) and you are perhaps using +`allowJs` and `checkJs` options of TypeScript's `tsconfig.json`), you may +use: + +```json +{ + "extends": ["plugin:jsdoc/recommended-typescript-flavor"] } ``` @@ -144,7 +150,7 @@ the following: ```json { - "extends": ["plugin:jsdoc/recommended-typescript-error"] + "extends": ["plugin:jsdoc/recommended-typescript-flavor-error"] } ``` diff --git a/README.md b/README.md index e30e8a1b2..28d468515 100644 --- a/README.md +++ b/README.md @@ -131,25 +131,31 @@ as failing errors, you may use the "recommended-error" config: ``` If you plan to use TypeScript syntax (and not just "typescript" -`mode` to indicate the JSDoc flavor is TypeScript), you can configure -the following: +`mode` to indicate the JSDoc flavor is TypeScript), you can use: -```javascript +```json { - "rules": { - "jsdoc/no-types": 1, - "jsdoc/require-param-type": 0, - "jsdoc/require-property-type": 0, - "jsdoc/require-returns-type": 0, - } + "extends": ["plugin:jsdoc/recommended-typescript"] } ``` -...or just use: +...or to report with failing errors instead of mere warnings: ```json { - "extends": ["plugin:jsdoc/recommended-typescript"] + "extends": ["plugin:jsdoc/recommended-typescript-error"] +} +``` + +If you are not using TypeScript syntax (your source files are still `.js` files) +but you are using the TypeScript flavor within JSDoc (i.e., the default +"typescript" `mode` in `eslint-plugin-jsdoc`) and you are perhaps using +`allowJs` and `checkJs` options of TypeScript's `tsconfig.json`), you may +use: + +```json +{ + "extends": ["plugin:jsdoc/recommended-typescript-flavor"] } ``` @@ -157,7 +163,7 @@ the following: ```json { - "extends": ["plugin:jsdoc/recommended-typescript-error"] + "extends": ["plugin:jsdoc/recommended-typescript-flavor-error"] } ``` diff --git a/src/index.js b/src/index.js index bbb22d616..052833df6 100644 --- a/src/index.js +++ b/src/index.js @@ -205,6 +205,24 @@ const createRecommendedTypeScriptRuleset = (warnOrError) => { }; }; +/** + * @param {"warn"|"error"} warnOrError + * @returns {import('eslint').ESLint.ConfigData} + */ +const createRecommendedTypeScriptFlavorRuleset = (warnOrError) => { + const ruleset = createRecommendedRuleset(warnOrError); + + return { + ...ruleset, + rules: { + ...ruleset.rules, + /* eslint-disable indent -- Extra indent to avoid use by auto-rule-editing */ + 'jsdoc/no-undefined-types': 'off', + /* eslint-enable indent */ + }, + }; +}; + /* istanbul ignore if -- TS */ if (!index.configs) { throw new Error('TypeScript guard'); @@ -214,5 +232,7 @@ index.configs.recommended = createRecommendedRuleset('warn'); index.configs['recommended-error'] = createRecommendedRuleset('error'); index.configs['recommended-typescript'] = createRecommendedTypeScriptRuleset('warn'); index.configs['recommended-typescript-error'] = createRecommendedTypeScriptRuleset('error'); +index.configs['recommended-typescript-flavor'] = createRecommendedTypeScriptFlavorRuleset('warn'); +index.configs['recommended-typescript-flavor-error'] = createRecommendedTypeScriptFlavorRuleset('error'); export default index;