Skip to content

Commit af4e33f

Browse files
authored
fix(eslint): improve JSDoc config for TS (#317)
## Summary Improved JSDoc ESLint configuration to better support TypeScript projects by using TypeScript-specific recommended rules and adding explicit file targeting. ## Changes - Switched from `flat/recommended` to `flat/recommended-typescript` config - Added explicit file targeting with `GLOB_JS` and `GLOB_TS` - Removed `jsdoc/no-restricted-syntax` rule - Updated `jsdoc/require-jsdoc` to not require JSDoc on ArrowFunctionExpression or FunctionDeclaration ## Motivation The previous configuration used generic JSDoc recommended rules which were not optimized for TypeScript. The TypeScript-specific preset provides better defaults for TypeScript projects. Additionally, requiring JSDoc on arrow functions (which are more commonly used in modern codebases) while making it optional for function declarations provides better documentation coverage without being overly restrictive. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Style** * Switched JSDoc linting to a TypeScript-focused baseline. * JSDoc is no longer required on arrow functions or function declarations. * Removed a restrictive JSDoc syntax rule. * **Chores** * Improved JavaScript/TypeScript file targeting in lint configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent e9ce00c commit af4e33f

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

.changeset/whole-cobras-knock.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@mheob/eslint-config': patch
3+
---
4+
5+
Updated JSDoc rules:
6+
- Added explicit file targeting with GLOB_JS and GLOB_TS
7+
- Switched from flat/recommended to flat/recommended-typescript config
8+
- Removed jsdoc/no-restricted-syntax rule
9+
- Updated jsdoc/require-jsdoc to not require JSDoc on ArrowFunctionExpression or FunctionDeclaration

.claude/commands/create-commit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ description: Create a git commit
1212

1313
## Your tasks
1414

15-
- create changeset if needed (at least an empty changeset); write the change message in a full sentence
15+
- create changeset if needed (at least an empty changeset); don't write the change message too short
1616
- create a single git commit based on the above changes
1717

1818
Use conventional commits with a title length of max 50 characters. See @commitlint.config.js for more details.

packages/eslint-config/src/configs/jsdoc.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { GLOB_JS, GLOB_TS } from '../globs';
12
import type { TypedFlatConfigItem } from '../types';
23
import { interopDefault } from '../utils';
34

@@ -6,28 +7,31 @@ import { interopDefault } from '../utils';
67
*
78
* This function sets up the necessary ESLint plugin for JSDoc,
89
* including the `eslint-plugin-jsdoc`. It also configures the rules for JSDoc,
9-
* including the recommended rules, no-restricted-syntax, reject-any-type,
10-
* reject-function-type, require-jsdoc, require-next-type, and tag-lines rules.
10+
* including the recommended rules, reject-any-type, reject-function-type, require-jsdoc,
11+
* require-next-type, and tag-lines rules.
1112
*
1213
* @returns Promise that resolves once the JSDoc ESLint rules are configured.
1314
*/
1415
export async function jsdoc(): Promise<TypedFlatConfigItem[]> {
1516
const jsdocPlugin = await interopDefault(import('eslint-plugin-jsdoc'));
16-
const recommendedRules = jsdocPlugin.configs['flat/recommended'].rules;
17+
const recommendedRules = jsdocPlugin.configs['flat/recommended-typescript'].rules;
1718

1819
return [
1920
{
21+
files: [GLOB_JS, GLOB_TS],
2022
name: 'mheob/jsdoc/rules',
2123
plugins: {
2224
jsdoc: jsdocPlugin,
2325
},
2426
rules: {
2527
...recommendedRules,
2628

27-
'jsdoc/no-restricted-syntax': 'warn',
2829
'jsdoc/reject-any-type': 'warn',
2930
'jsdoc/reject-function-type': 'warn',
30-
'jsdoc/require-jsdoc': 'warn',
31+
'jsdoc/require-jsdoc': [
32+
'warn',
33+
{ require: { ArrowFunctionExpression: false, FunctionDeclaration: false } },
34+
],
3135
'jsdoc/require-next-type': 'warn',
3236
'jsdoc/tag-lines': ['warn', 'always', { count: 0, startLines: 1 }],
3337
},

0 commit comments

Comments
 (0)