Skip to content

Commit

Permalink
feat: add recommended-typescript-flavor configs
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed May 28, 2023
1 parent ec41b90 commit 6042b77
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 24 deletions.
30 changes: 18 additions & 12 deletions .README/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,33 +118,39 @@ 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"]
}
```

...or to report with failing errors instead of mere warnings:

```json
{
"extends": ["plugin:jsdoc/recommended-typescript-error"]
"extends": ["plugin:jsdoc/recommended-typescript-flavor-error"]
}
```

Expand Down
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,33 +131,39 @@ 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"]
}
```

...or to report with failing errors instead of mere warnings:

```json
{
"extends": ["plugin:jsdoc/recommended-typescript-error"]
"extends": ["plugin:jsdoc/recommended-typescript-flavor-error"]
}
```

Expand Down
20 changes: 20 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;

0 comments on commit 6042b77

Please sign in to comment.