@@ -13,6 +13,20 @@ import {
13
13
} from '../globs.ts'
14
14
import jsdocPlugin from 'eslint-plugin-jsdoc'
15
15
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
+
16
30
/**
17
31
* Config factory for code documentation related rules (JSDoc)
18
32
*
@@ -56,7 +70,7 @@ export function documentation(options: ConfigOptions): Linter.Config[] {
56
70
57
71
{
58
72
rules : {
59
- // Force proper documentation
73
+ // Force proper documentation
60
74
'jsdoc/check-tag-names' : 'error' ,
61
75
// But ignore return values
62
76
'jsdoc/require-returns' : 'off' ,
@@ -86,16 +100,39 @@ export function documentation(options: ConfigOptions): Linter.Config[] {
86
100
87
101
{
88
102
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' ,
90
105
'jsdoc/require-param-type' : 'off' ,
91
- 'jsdoc/require-property-type' : 'off' ,
92
106
'jsdoc/require-returns-type' : 'off' ,
93
107
} ,
94
- files : [
95
- ...GLOB_FILES_TYPESCRIPT ,
96
- ...( options . vueIsTypescript ? GLOB_FILES_VUE : [ ] ) ,
97
- ] ,
108
+ files : [ ...GLOB_FILES_TYPESCRIPT ] ,
98
109
name : 'nextcloud/documentation/rules-typescript' ,
99
110
} ,
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
+ ) ,
100
137
]
101
138
}
0 commit comments