Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-undefined-types and TypeScript #1098

Merged
merged 2 commits into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
21 changes: 21 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ const createRecommendedTypeScriptRuleset = (warnOrError) => {
},
],
'jsdoc/no-types': warnOrError,
'jsdoc/no-undefined-types': 'off',
'jsdoc/require-param-type': 'off',
'jsdoc/require-property-type': 'off',
'jsdoc/require-returns-type': 'off',
Expand All @@ -204,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 @@ -213,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;
Loading