Skip to content

Commit d71ce12

Browse files
committed
fix(documentation): do not remove JSDoc types in Vue JS files
Signed-off-by: Grigorii K. Shartsev <[email protected]>
1 parent a85a1e3 commit d71ce12

File tree

1 file changed

+44
-7
lines changed

1 file changed

+44
-7
lines changed

lib/configs/documentation.ts

+44-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ import {
1313
} from '../globs.ts'
1414
import jsdocPlugin from 'eslint-plugin-jsdoc'
1515

16+
const TS_FUNCTION_CONTEXTS = [
17+
'FunctionDeclaration:has(TSTypeAnnotation)',
18+
'FunctionExpression:has(TSTypeAnnotation)',
19+
'ArrowFunctionExpression:has(TSTypeAnnotation)',
20+
'MethodDefinition:has(TSTypeAnnotation)',
21+
]
22+
23+
const JS_FUNCTION_CONTEXTS = [
24+
'FunctionDeclaration:not(:has(TSTypeAnnotation))',
25+
'FunctionExpression:not(:has(TSTypeAnnotation))',
26+
'ArrowFunctionExpression:not(:has(TSTypeAnnotation))',
27+
'MethodDefinition:not(:has(TSTypeAnnotation))',
28+
]
29+
1630
/**
1731
* Config factory for code documentation related rules (JSDoc)
1832
*
@@ -56,7 +70,7 @@ export function documentation(options: ConfigOptions): Linter.Config[] {
5670

5771
{
5872
rules: {
59-
// Force proper documentation
73+
// Force proper documentation
6074
'jsdoc/check-tag-names': 'error',
6175
// But ignore return values
6276
'jsdoc/require-returns': 'off',
@@ -86,16 +100,39 @@ export function documentation(options: ConfigOptions): Linter.Config[] {
86100

87101
{
88102
rules: {
89-
// Overwrites for documentation as types are already provided by Typescript
103+
// Overwrites for documentation as types are already provided by Typescript
104+
'jsdoc/no-types': 'error',
90105
'jsdoc/require-param-type': 'off',
91-
'jsdoc/require-property-type': 'off',
92106
'jsdoc/require-returns-type': 'off',
93107
},
94-
files: [
95-
...GLOB_FILES_TYPESCRIPT,
96-
...(options.vueIsTypescript ? GLOB_FILES_VUE : []),
97-
],
108+
files: [...GLOB_FILES_TYPESCRIPT],
98109
name: 'nextcloud/documentation/rules-typescript',
99110
},
111+
112+
...(options.vueIsTypescript
113+
? [
114+
{
115+
rules: {
116+
// Vue files can be both Javascript and Typescript
117+
// Try to apply TS files only for functions with TS definitions
118+
'jsdoc/no-types': [
119+
'error',
120+
{ contexts: TS_FUNCTION_CONTEXTS },
121+
],
122+
'jsdoc/require-param-type': [
123+
'error',
124+
{ contexts: JS_FUNCTION_CONTEXTS },
125+
],
126+
// Unlike params, return values are often inferred and not explicitly typed
127+
'jsdoc/require-returns-type': 'off',
128+
// Unfortunately, we cannot check when it is used in TS context and when not
129+
'jsdoc/check-tag-names': ['error', { typed: false }],
130+
},
131+
files: [...(options.vueIsTypescript ? GLOB_FILES_VUE : [])],
132+
name: 'nextcloud/documentation/rules-vue',
133+
} satisfies Linter.Config,
134+
]
135+
: []
136+
),
100137
]
101138
}

0 commit comments

Comments
 (0)