eslint-plugin-jsdoc 55.1.2 → 55.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/generateRule.cjs +4 -4
- package/dist/generateRule.cjs.map +1 -1
- package/dist/index-cjs.cjs +3 -0
- package/dist/index-cjs.cjs.map +1 -1
- package/dist/index-esm.cjs +53 -10
- package/dist/index-esm.cjs.map +1 -1
- package/dist/index-esm.d.ts +3 -2
- package/dist/index.cjs +55 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/rules/typeFormatting.cjs +289 -0
- package/dist/rules/typeFormatting.cjs.map +1 -0
- package/dist/rules/typeFormatting.d.ts +3 -0
- package/dist/rules.d.ts +22 -0
- package/package.json +6 -6
- package/src/index-cjs.js +3 -0
- package/src/index-esm.js +58 -11
- package/src/index.js +61 -11
- package/src/rules/typeFormatting.js +348 -0
- package/src/rules.d.ts +22 -0
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"url": "http://gajus.com"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@es-joy/jsdoccomment": "~0.
|
|
8
|
+
"@es-joy/jsdoccomment": "~0.57.0",
|
|
9
9
|
"are-docs-informative": "^0.0.2",
|
|
10
10
|
"comment-parser": "1.4.1",
|
|
11
11
|
"debug": "^4.4.1",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@types/node": "^24.3.1",
|
|
43
43
|
"@types/semver": "^7.7.1",
|
|
44
44
|
"@types/spdx-expression-parse": "^3.0.5",
|
|
45
|
-
"@typescript-eslint/types": "^8.
|
|
45
|
+
"@typescript-eslint/types": "^8.43.0",
|
|
46
46
|
"babel-plugin-add-module-exports": "^1.0.4",
|
|
47
47
|
"babel-plugin-istanbul": "^7.0.1",
|
|
48
48
|
"babel-plugin-transform-import-meta": "^2.3.3",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"eslint-config-canonical": "~45.0.0",
|
|
55
55
|
"gitdown": "^4.1.1",
|
|
56
56
|
"glob": "^11.0.3",
|
|
57
|
-
"globals": "^16.
|
|
57
|
+
"globals": "^16.4.0",
|
|
58
58
|
"husky": "^9.1.7",
|
|
59
|
-
"jsdoc-type-pratt-parser": "^5.
|
|
59
|
+
"jsdoc-type-pratt-parser": "^5.2.0",
|
|
60
60
|
"json-schema": "^0.4.0",
|
|
61
61
|
"json-schema-to-typescript": "^15.0.4",
|
|
62
62
|
"lint-staged": "^16.1.6",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"rimraf": "^6.0.1",
|
|
67
67
|
"semantic-release": "^24.2.7",
|
|
68
68
|
"typescript": "5.9.2",
|
|
69
|
-
"typescript-eslint": "^8.
|
|
69
|
+
"typescript-eslint": "^8.43.0"
|
|
70
70
|
},
|
|
71
71
|
"engines": {
|
|
72
72
|
"node": ">=20.11.0"
|
|
@@ -160,5 +160,5 @@
|
|
|
160
160
|
"test-cov": "TIMING=1 c8 --reporter text pnpm run test-no-cov",
|
|
161
161
|
"test-index": "pnpm run test-no-cov test/rules/index.js"
|
|
162
162
|
},
|
|
163
|
-
"version": "55.
|
|
163
|
+
"version": "55.3.0"
|
|
164
164
|
}
|
package/src/index-cjs.js
CHANGED
|
@@ -57,6 +57,7 @@ import requireYieldsCheck from './rules/requireYieldsCheck.js';
|
|
|
57
57
|
import sortTags from './rules/sortTags.js';
|
|
58
58
|
import tagLines from './rules/tagLines.js';
|
|
59
59
|
import textEscaping from './rules/textEscaping.js';
|
|
60
|
+
import typeFormatting from './rules/typeFormatting.js';
|
|
60
61
|
import validTypes from './rules/validTypes.js';
|
|
61
62
|
|
|
62
63
|
/* eslint-disable jsdoc/valid-types -- Bug */
|
|
@@ -129,6 +130,7 @@ index.rules = {
|
|
|
129
130
|
'sort-tags': sortTags,
|
|
130
131
|
'tag-lines': tagLines,
|
|
131
132
|
'text-escaping': textEscaping,
|
|
133
|
+
'type-formatting': typeFormatting,
|
|
132
134
|
'valid-types': validTypes,
|
|
133
135
|
};
|
|
134
136
|
|
|
@@ -206,6 +208,7 @@ const createRecommendedRuleset = (warnOrError, flatName) => {
|
|
|
206
208
|
'jsdoc/sort-tags': 'off',
|
|
207
209
|
'jsdoc/tag-lines': warnOrError,
|
|
208
210
|
'jsdoc/text-escaping': 'off',
|
|
211
|
+
'jsdoc/type-formatting': 'off',
|
|
209
212
|
'jsdoc/valid-types': warnOrError,
|
|
210
213
|
},
|
|
211
214
|
};
|
package/src/index-esm.js
CHANGED
|
@@ -13,7 +13,7 @@ export default index;
|
|
|
13
13
|
/* eslint-disable jsdoc/valid-types -- Bug */
|
|
14
14
|
/**
|
|
15
15
|
* @type {((
|
|
16
|
-
* cfg?: {
|
|
16
|
+
* cfg?: import('eslint').Linter.Config & {
|
|
17
17
|
* mergeSettings?: boolean,
|
|
18
18
|
* config?: `flat/${import('./index-cjs.js').ConfigGroups}${import('./index-cjs.js').ConfigVariants}${import('./index-cjs.js').ErrorLevelVariants}`,
|
|
19
19
|
* settings?: Partial<import('./iterateJsdoc.js').Settings>,
|
|
@@ -29,19 +29,62 @@ export const jsdoc = function (cfg) {
|
|
|
29
29
|
jsdoc: index,
|
|
30
30
|
},
|
|
31
31
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
|
|
33
|
+
if (cfg) {
|
|
34
|
+
if (cfg.config) {
|
|
35
|
+
// @ts-expect-error Security check
|
|
36
|
+
if (cfg.config === '__proto__') {
|
|
37
|
+
throw new TypeError('Disallowed config value');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
outputConfig = index.configs[cfg.config];
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
if (cfg.rules) {
|
|
44
|
+
outputConfig.rules = {
|
|
45
|
+
...outputConfig.rules,
|
|
46
|
+
...cfg.rules,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (cfg.plugins) {
|
|
51
|
+
outputConfig.plugins = {
|
|
52
|
+
...outputConfig.plugins,
|
|
53
|
+
...cfg.plugins,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (cfg.name) {
|
|
58
|
+
outputConfig.name = cfg.name;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (cfg.basePath) {
|
|
62
|
+
outputConfig.basePath = cfg.basePath;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (cfg.files) {
|
|
66
|
+
outputConfig.files = cfg.files;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (cfg.ignores) {
|
|
70
|
+
outputConfig.ignores = cfg.ignores;
|
|
71
|
+
}
|
|
42
72
|
|
|
43
|
-
|
|
44
|
-
|
|
73
|
+
if (cfg.language) {
|
|
74
|
+
outputConfig.language = cfg.language;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (cfg.languageOptions) {
|
|
78
|
+
outputConfig.languageOptions = cfg.languageOptions;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (cfg.linterOptions) {
|
|
82
|
+
outputConfig.linterOptions = cfg.linterOptions;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (cfg.processor) {
|
|
86
|
+
outputConfig.processor = cfg.processor;
|
|
87
|
+
}
|
|
45
88
|
}
|
|
46
89
|
|
|
47
90
|
outputConfig.settings = {
|
|
@@ -78,3 +121,7 @@ export const jsdoc = function (cfg) {
|
|
|
78
121
|
|
|
79
122
|
return outputConfig;
|
|
80
123
|
};
|
|
124
|
+
|
|
125
|
+
export {
|
|
126
|
+
getJsdocProcessorPlugin,
|
|
127
|
+
} from './getJsdocProcessorPlugin.js';
|
package/src/index.js
CHANGED
|
@@ -63,6 +63,7 @@ import requireYieldsCheck from './rules/requireYieldsCheck.js';
|
|
|
63
63
|
import sortTags from './rules/sortTags.js';
|
|
64
64
|
import tagLines from './rules/tagLines.js';
|
|
65
65
|
import textEscaping from './rules/textEscaping.js';
|
|
66
|
+
import typeFormatting from './rules/typeFormatting.js';
|
|
66
67
|
import validTypes from './rules/validTypes.js';
|
|
67
68
|
|
|
68
69
|
/* eslint-disable jsdoc/valid-types -- Bug */
|
|
@@ -135,6 +136,7 @@ index.rules = {
|
|
|
135
136
|
'sort-tags': sortTags,
|
|
136
137
|
'tag-lines': tagLines,
|
|
137
138
|
'text-escaping': textEscaping,
|
|
139
|
+
'type-formatting': typeFormatting,
|
|
138
140
|
'valid-types': validTypes,
|
|
139
141
|
};
|
|
140
142
|
|
|
@@ -212,6 +214,7 @@ const createRecommendedRuleset = (warnOrError, flatName) => {
|
|
|
212
214
|
'jsdoc/sort-tags': 'off',
|
|
213
215
|
'jsdoc/tag-lines': warnOrError,
|
|
214
216
|
'jsdoc/text-escaping': 'off',
|
|
217
|
+
'jsdoc/type-formatting': 'off',
|
|
215
218
|
'jsdoc/valid-types': warnOrError,
|
|
216
219
|
},
|
|
217
220
|
};
|
|
@@ -536,7 +539,7 @@ export default index;
|
|
|
536
539
|
/* eslint-disable jsdoc/valid-types -- Bug */
|
|
537
540
|
/**
|
|
538
541
|
* @type {((
|
|
539
|
-
* cfg?: {
|
|
542
|
+
* cfg?: import('eslint').Linter.Config & {
|
|
540
543
|
* mergeSettings?: boolean,
|
|
541
544
|
* config?: `flat/${ConfigGroups}${ConfigVariants}${ErrorLevelVariants}`,
|
|
542
545
|
* settings?: Partial<import('./iterateJsdoc.js').Settings>,
|
|
@@ -552,19 +555,62 @@ export const jsdoc = function (cfg) {
|
|
|
552
555
|
jsdoc: index,
|
|
553
556
|
},
|
|
554
557
|
};
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
558
|
+
|
|
559
|
+
if (cfg) {
|
|
560
|
+
if (cfg.config) {
|
|
561
|
+
// @ts-expect-error Security check
|
|
562
|
+
if (cfg.config === '__proto__') {
|
|
563
|
+
throw new TypeError('Disallowed config value');
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
outputConfig = index.configs[cfg.config];
|
|
561
567
|
}
|
|
562
568
|
|
|
563
|
-
|
|
564
|
-
|
|
569
|
+
if (cfg.rules) {
|
|
570
|
+
outputConfig.rules = {
|
|
571
|
+
...outputConfig.rules,
|
|
572
|
+
...cfg.rules,
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
if (cfg.plugins) {
|
|
577
|
+
outputConfig.plugins = {
|
|
578
|
+
...outputConfig.plugins,
|
|
579
|
+
...cfg.plugins,
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
if (cfg.name) {
|
|
584
|
+
outputConfig.name = cfg.name;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
if (cfg.basePath) {
|
|
588
|
+
outputConfig.basePath = cfg.basePath;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
if (cfg.files) {
|
|
592
|
+
outputConfig.files = cfg.files;
|
|
593
|
+
}
|
|
565
594
|
|
|
566
|
-
|
|
567
|
-
|
|
595
|
+
if (cfg.ignores) {
|
|
596
|
+
outputConfig.ignores = cfg.ignores;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
if (cfg.language) {
|
|
600
|
+
outputConfig.language = cfg.language;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
if (cfg.languageOptions) {
|
|
604
|
+
outputConfig.languageOptions = cfg.languageOptions;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
if (cfg.linterOptions) {
|
|
608
|
+
outputConfig.linterOptions = cfg.linterOptions;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
if (cfg.processor) {
|
|
612
|
+
outputConfig.processor = cfg.processor;
|
|
613
|
+
}
|
|
568
614
|
}
|
|
569
615
|
|
|
570
616
|
outputConfig.settings = {
|
|
@@ -601,3 +647,7 @@ export const jsdoc = function (cfg) {
|
|
|
601
647
|
|
|
602
648
|
return outputConfig;
|
|
603
649
|
};
|
|
650
|
+
|
|
651
|
+
export {
|
|
652
|
+
getJsdocProcessorPlugin,
|
|
653
|
+
} from './getJsdocProcessorPlugin.js';
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import iterateJsdoc from '../iterateJsdoc.js';
|
|
2
|
+
import {
|
|
3
|
+
parse as parseType,
|
|
4
|
+
stringify,
|
|
5
|
+
traverse,
|
|
6
|
+
tryParse as tryParseType,
|
|
7
|
+
} from '@es-joy/jsdoccomment';
|
|
8
|
+
|
|
9
|
+
export default iterateJsdoc(({
|
|
10
|
+
context,
|
|
11
|
+
indent,
|
|
12
|
+
jsdoc,
|
|
13
|
+
settings,
|
|
14
|
+
utils,
|
|
15
|
+
}) => {
|
|
16
|
+
const {
|
|
17
|
+
arrayBrackets = 'square',
|
|
18
|
+
enableFixer = true,
|
|
19
|
+
genericDot = false,
|
|
20
|
+
objectFieldIndent = '',
|
|
21
|
+
objectFieldQuote = null,
|
|
22
|
+
objectFieldSeparator = null,
|
|
23
|
+
propertyQuotes = null,
|
|
24
|
+
separatorForSingleObjectField = false,
|
|
25
|
+
stringQuotes = 'single',
|
|
26
|
+
} = context.options[0] || {};
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
mode,
|
|
30
|
+
} = settings;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {import('@es-joy/jsdoccomment').JsdocTagWithInline} tag
|
|
34
|
+
*/
|
|
35
|
+
const checkTypeFormats = (tag) => {
|
|
36
|
+
const potentialType = tag.type;
|
|
37
|
+
let parsedType;
|
|
38
|
+
try {
|
|
39
|
+
parsedType = mode === 'permissive' ?
|
|
40
|
+
tryParseType(/** @type {string} */ (potentialType)) :
|
|
41
|
+
parseType(/** @type {string} */ (potentialType), mode);
|
|
42
|
+
} catch {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const fix = () => {
|
|
47
|
+
const typeLines = stringify(parsedType).split('\n');
|
|
48
|
+
const firstTypeLine = typeLines.shift();
|
|
49
|
+
const lastTypeLine = typeLines.pop();
|
|
50
|
+
|
|
51
|
+
const beginNameOrDescIdx = tag.source.findIndex(({
|
|
52
|
+
tokens,
|
|
53
|
+
}) => {
|
|
54
|
+
return tokens.name || tokens.description;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const nameAndDesc = tag.source.slice(beginNameOrDescIdx);
|
|
58
|
+
const initialNumber = tag.source[0].number;
|
|
59
|
+
const src = [
|
|
60
|
+
// Get inevitably present tag from first `tag.source`
|
|
61
|
+
{
|
|
62
|
+
number: initialNumber,
|
|
63
|
+
source: '',
|
|
64
|
+
tokens: {
|
|
65
|
+
...tag.source[0].tokens,
|
|
66
|
+
...(typeLines.length || lastTypeLine ? {
|
|
67
|
+
end: '',
|
|
68
|
+
name: '',
|
|
69
|
+
postName: '',
|
|
70
|
+
postType: '',
|
|
71
|
+
} : {}),
|
|
72
|
+
type: '{' + firstTypeLine + (!typeLines.length && lastTypeLine === undefined ? '}' : ''),
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
// Get any intervening type lines
|
|
76
|
+
...(typeLines.length ? typeLines.map((typeLine, idx) => {
|
|
77
|
+
return {
|
|
78
|
+
number: initialNumber + idx + 1,
|
|
79
|
+
source: '',
|
|
80
|
+
tokens: {
|
|
81
|
+
// Grab any delimiter info from first item
|
|
82
|
+
...tag.source[0].tokens,
|
|
83
|
+
delimiter: tag.source[0].tokens.delimiter === '/**' ? '*' : tag.source[0].tokens.delimiter,
|
|
84
|
+
end: '',
|
|
85
|
+
name: '',
|
|
86
|
+
postName: '',
|
|
87
|
+
postTag: '',
|
|
88
|
+
postType: '',
|
|
89
|
+
start: indent + ' ',
|
|
90
|
+
tag: '',
|
|
91
|
+
type: typeLine,
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}) : []),
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
// Merge any final type line and name and description
|
|
98
|
+
if (
|
|
99
|
+
// Name and description may be already included if present with the tag
|
|
100
|
+
beginNameOrDescIdx > 0
|
|
101
|
+
) {
|
|
102
|
+
src.push({
|
|
103
|
+
number: src.length + 1,
|
|
104
|
+
source: '',
|
|
105
|
+
tokens: {
|
|
106
|
+
...nameAndDesc[0].tokens,
|
|
107
|
+
type: lastTypeLine + '}',
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (
|
|
112
|
+
// Get any remaining description lines
|
|
113
|
+
nameAndDesc.length > 1
|
|
114
|
+
) {
|
|
115
|
+
src.push(
|
|
116
|
+
...nameAndDesc.slice(1).map(({
|
|
117
|
+
source,
|
|
118
|
+
tokens,
|
|
119
|
+
}, idx) => {
|
|
120
|
+
return {
|
|
121
|
+
number: src.length + idx + 2,
|
|
122
|
+
source,
|
|
123
|
+
tokens,
|
|
124
|
+
};
|
|
125
|
+
}),
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
if (lastTypeLine) {
|
|
130
|
+
src.push({
|
|
131
|
+
number: src.length + 1,
|
|
132
|
+
source: '',
|
|
133
|
+
tokens: {
|
|
134
|
+
...nameAndDesc[0].tokens,
|
|
135
|
+
delimiter: nameAndDesc[0].tokens.delimiter === '/**' ? '*' : nameAndDesc[0].tokens.delimiter,
|
|
136
|
+
postTag: '',
|
|
137
|
+
start: indent + ' ',
|
|
138
|
+
tag: '',
|
|
139
|
+
type: lastTypeLine + '}',
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (
|
|
145
|
+
// Get any remaining description lines
|
|
146
|
+
nameAndDesc.length > 1
|
|
147
|
+
) {
|
|
148
|
+
src.push(
|
|
149
|
+
...nameAndDesc.slice(1).map(({
|
|
150
|
+
source,
|
|
151
|
+
tokens,
|
|
152
|
+
}, idx) => {
|
|
153
|
+
return {
|
|
154
|
+
number: src.length + idx + 2,
|
|
155
|
+
source,
|
|
156
|
+
tokens,
|
|
157
|
+
};
|
|
158
|
+
}),
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
tag.source = src;
|
|
164
|
+
|
|
165
|
+
// Properly rewire `jsdoc.source`
|
|
166
|
+
const firstTagIdx = jsdoc.source.findIndex(({
|
|
167
|
+
tokens: {
|
|
168
|
+
tag: tg,
|
|
169
|
+
},
|
|
170
|
+
}) => {
|
|
171
|
+
return tg;
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
jsdoc.source = [
|
|
175
|
+
...jsdoc.source.slice(0, firstTagIdx),
|
|
176
|
+
...jsdoc.tags.flatMap(({
|
|
177
|
+
source,
|
|
178
|
+
}) => {
|
|
179
|
+
return source;
|
|
180
|
+
}),
|
|
181
|
+
];
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/** @type {string[]} */
|
|
185
|
+
const errorMessages = [];
|
|
186
|
+
let needToReport = false;
|
|
187
|
+
traverse(parsedType, (nde) => {
|
|
188
|
+
let typeFound = true;
|
|
189
|
+
let errorMessage = '';
|
|
190
|
+
const initialType = stringify(
|
|
191
|
+
/** @type {import('jsdoc-type-pratt-parser').RootResult} */ (nde),
|
|
192
|
+
);
|
|
193
|
+
switch (nde.type) {
|
|
194
|
+
case 'JsdocTypeGeneric': {
|
|
195
|
+
const typeNode = /** @type {import('jsdoc-type-pratt-parser').GenericResult} */ (nde);
|
|
196
|
+
if ('value' in typeNode.left && typeNode.left.value === 'Array') {
|
|
197
|
+
typeNode.meta.brackets = arrayBrackets;
|
|
198
|
+
errorMessage = `Array bracket style should be ${arrayBrackets}`;
|
|
199
|
+
} else {
|
|
200
|
+
typeNode.meta.dot = genericDot;
|
|
201
|
+
errorMessage = `Dot usage should be ${genericDot}`;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
case 'JsdocTypeObject': {
|
|
208
|
+
const typeNode = /** @type {import('jsdoc-type-pratt-parser').ObjectResult} */ (nde);
|
|
209
|
+
typeNode.meta.separator = objectFieldSeparator ?? undefined;
|
|
210
|
+
typeNode.meta.separatorForSingleObjectField = separatorForSingleObjectField;
|
|
211
|
+
typeNode.meta.propertyIndent = objectFieldIndent;
|
|
212
|
+
errorMessage = `Inconsistent ${objectFieldSeparator} usage`;
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
case 'JsdocTypeObjectField': {
|
|
217
|
+
const typeNode = /** @type {import('jsdoc-type-pratt-parser').ObjectFieldResult} */ (nde);
|
|
218
|
+
if (objectFieldQuote ||
|
|
219
|
+
(typeof typeNode.key === 'string' && !(/\s/v).test(typeNode.key))
|
|
220
|
+
) {
|
|
221
|
+
typeNode.meta.quote = objectFieldQuote ?? undefined;
|
|
222
|
+
errorMessage = `Inconsistent object field quotes ${objectFieldQuote}`;
|
|
223
|
+
} else {
|
|
224
|
+
typeFound = false;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
case 'JsdocTypeProperty': {
|
|
231
|
+
const typeNode = /** @type {import('jsdoc-type-pratt-parser').PropertyResult} */ (nde);
|
|
232
|
+
|
|
233
|
+
if (propertyQuotes ||
|
|
234
|
+
(typeof typeNode.value === 'string' && !(/\s/v).test(typeNode.value))
|
|
235
|
+
) {
|
|
236
|
+
typeNode.meta.quote = propertyQuotes ?? undefined;
|
|
237
|
+
errorMessage = `Inconsistent ${propertyQuotes} property quotes usage`;
|
|
238
|
+
} else {
|
|
239
|
+
typeFound = false;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
case 'JsdocTypeStringValue': {
|
|
246
|
+
const typeNode = /** @type {import('jsdoc-type-pratt-parser').StringValueResult} */ (nde);
|
|
247
|
+
typeNode.meta.quote = stringQuotes;
|
|
248
|
+
errorMessage = `Inconsistent ${stringQuotes} string quotes usage`;
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
default:
|
|
253
|
+
typeFound = false;
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (typeFound) {
|
|
258
|
+
const convertedType = stringify(/** @type {import('jsdoc-type-pratt-parser').RootResult} */ (nde));
|
|
259
|
+
if (initialType !== convertedType) {
|
|
260
|
+
needToReport = true;
|
|
261
|
+
errorMessages.push(errorMessage);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
if (needToReport) {
|
|
267
|
+
for (const errorMessage of errorMessages) {
|
|
268
|
+
utils.reportJSDoc(
|
|
269
|
+
errorMessage, tag, enableFixer ? fix : null, true,
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const tags = utils.getPresentTags([
|
|
276
|
+
'param',
|
|
277
|
+
'returns',
|
|
278
|
+
]);
|
|
279
|
+
for (const tag of tags) {
|
|
280
|
+
checkTypeFormats(tag);
|
|
281
|
+
}
|
|
282
|
+
}, {
|
|
283
|
+
iterateAllJsdocs: true,
|
|
284
|
+
meta: {
|
|
285
|
+
docs: {
|
|
286
|
+
description: 'Formats JSDoc type values.',
|
|
287
|
+
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/type-formatting.md#repos-sticky-header',
|
|
288
|
+
},
|
|
289
|
+
fixable: 'code',
|
|
290
|
+
schema: [
|
|
291
|
+
{
|
|
292
|
+
additionalProperties: false,
|
|
293
|
+
properties: {
|
|
294
|
+
arrayBrackets: {
|
|
295
|
+
enum: [
|
|
296
|
+
'angle',
|
|
297
|
+
'square',
|
|
298
|
+
],
|
|
299
|
+
},
|
|
300
|
+
enableFixer: {
|
|
301
|
+
type: 'boolean',
|
|
302
|
+
},
|
|
303
|
+
genericDot: {
|
|
304
|
+
type: 'boolean',
|
|
305
|
+
},
|
|
306
|
+
objectFieldIndent: {
|
|
307
|
+
type: 'string',
|
|
308
|
+
},
|
|
309
|
+
objectFieldQuote: {
|
|
310
|
+
enum: [
|
|
311
|
+
'double',
|
|
312
|
+
'single',
|
|
313
|
+
null,
|
|
314
|
+
],
|
|
315
|
+
},
|
|
316
|
+
objectFieldSeparator: {
|
|
317
|
+
enum: [
|
|
318
|
+
'comma',
|
|
319
|
+
'comma-and-linebreak',
|
|
320
|
+
'linebreak',
|
|
321
|
+
'semicolon',
|
|
322
|
+
'semicolon-and-linebreak',
|
|
323
|
+
null,
|
|
324
|
+
],
|
|
325
|
+
},
|
|
326
|
+
propertyQuotes: {
|
|
327
|
+
enum: [
|
|
328
|
+
'double',
|
|
329
|
+
'single',
|
|
330
|
+
null,
|
|
331
|
+
],
|
|
332
|
+
},
|
|
333
|
+
separatorForSingleObjectField: {
|
|
334
|
+
type: 'boolean',
|
|
335
|
+
},
|
|
336
|
+
stringQuotes: {
|
|
337
|
+
enum: [
|
|
338
|
+
'double',
|
|
339
|
+
'single',
|
|
340
|
+
],
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
type: 'object',
|
|
344
|
+
},
|
|
345
|
+
],
|
|
346
|
+
type: 'suggestion',
|
|
347
|
+
},
|
|
348
|
+
});
|
package/src/rules.d.ts
CHANGED
|
@@ -756,6 +756,28 @@ export interface Rules {
|
|
|
756
756
|
}
|
|
757
757
|
];
|
|
758
758
|
|
|
759
|
+
"jsdoc/type-formatting":
|
|
760
|
+
| []
|
|
761
|
+
| [
|
|
762
|
+
{
|
|
763
|
+
arrayBrackets?: "angle" | "square";
|
|
764
|
+
enableFixer?: boolean;
|
|
765
|
+
genericDot?: boolean;
|
|
766
|
+
objectFieldIndent?: string;
|
|
767
|
+
objectFieldQuote?: "double" | "single" | null;
|
|
768
|
+
objectFieldSeparator?:
|
|
769
|
+
| "comma"
|
|
770
|
+
| "comma-and-linebreak"
|
|
771
|
+
| "linebreak"
|
|
772
|
+
| "semicolon"
|
|
773
|
+
| "semicolon-and-linebreak"
|
|
774
|
+
| null;
|
|
775
|
+
propertyQuotes?: "double" | "single" | null;
|
|
776
|
+
separatorForSingleObjectField?: boolean;
|
|
777
|
+
stringQuotes?: "double" | "single";
|
|
778
|
+
}
|
|
779
|
+
];
|
|
780
|
+
|
|
759
781
|
"jsdoc/valid-types":
|
|
760
782
|
| []
|
|
761
783
|
| [
|