Skip to content

Commit e9b0877

Browse files
authored
fix: jsdocProcessorPlugin types (#1441)
1 parent 8451201 commit e9b0877

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

src/getJsdocProcessorPlugin.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ import {
1616
join,
1717
} from 'node:path';
1818

19+
/**
20+
* @import {
21+
* Integer,
22+
* JsdocBlockWithInline,
23+
* } from './iterateJsdoc.js';
24+
* @import {
25+
* ESLint,
26+
* Linter,
27+
* } from 'eslint';
28+
*/
29+
1930
const {
2031
version,
2132
} = JSON.parse(
@@ -43,7 +54,7 @@ const escapeStringRegexp = (str) => {
4354
/**
4455
* @param {string} str
4556
* @param {string} ch
46-
* @returns {import('./iterateJsdoc.js').Integer}
57+
* @returns {Integer}
4758
*/
4859
const countChars = (str, ch) => {
4960
return (str.match(new RegExp(escapeStringRegexp(ch), 'gv')) || []).length;
@@ -52,8 +63,8 @@ const countChars = (str, ch) => {
5263
/**
5364
* @param {string} text
5465
* @returns {[
55-
* import('./iterateJsdoc.js').Integer,
56-
* import('./iterateJsdoc.js').Integer
66+
* Integer,
67+
* Integer
5768
* ]}
5869
*/
5970
const getLinesCols = (text) => {
@@ -95,6 +106,7 @@ const getLinesCols = (text) => {
95106
* We use a function for the ability of the user to pass in a config, but
96107
* without requiring all users of the plugin to do so.
97108
* @param {JsdocProcessorOptions} [options]
109+
* @returns {ESLint.Plugin}
98110
*/
99111
export const getJsdocProcessorPlugin = (options = {}) => {
100112
const {
@@ -150,7 +162,7 @@ export const getJsdocProcessorPlugin = (options = {}) => {
150162
let extraMessages = [];
151163

152164
/**
153-
* @param {import('./iterateJsdoc.js').JsdocBlockWithInline} jsdoc
165+
* @param {JsdocBlockWithInline} jsdoc
154166
* @param {string} jsFileName
155167
* @param {[number, number]} commentLineCols
156168
*/
@@ -170,19 +182,19 @@ export const getJsdocProcessorPlugin = (options = {}) => {
170182
* source: string,
171183
* targetTagName: string,
172184
* rules?: import('eslint').Linter.RulesRecord|undefined,
173-
* lines?: import('./iterateJsdoc.js').Integer,
174-
* cols?: import('./iterateJsdoc.js').Integer,
185+
* lines?: Integer,
186+
* cols?: Integer,
175187
* skipInit?: boolean,
176188
* ext: string,
177189
* sources?: {
178-
* nonJSPrefacingCols: import('./iterateJsdoc.js').Integer,
179-
* nonJSPrefacingLines: import('./iterateJsdoc.js').Integer,
190+
* nonJSPrefacingCols: Integer,
191+
* nonJSPrefacingLines: Integer,
180192
* string: string,
181193
* }[],
182194
* tag?: import('comment-parser').Spec & {
183-
* line?: import('./iterateJsdoc.js').Integer,
195+
* line?: Integer,
184196
* }|{
185-
* line: import('./iterateJsdoc.js').Integer,
197+
* line: Integer,
186198
* }
187199
* }} cfg
188200
*/
@@ -210,8 +222,8 @@ export const getJsdocProcessorPlugin = (options = {}) => {
210222

211223
/**
212224
* @param {{
213-
* nonJSPrefacingCols: import('./iterateJsdoc.js').Integer,
214-
* nonJSPrefacingLines: import('./iterateJsdoc.js').Integer,
225+
* nonJSPrefacingCols: Integer,
226+
* nonJSPrefacingLines: Integer,
215227
* string: string
216228
* }} cfg
217229
*/
@@ -234,7 +246,7 @@ export const getJsdocProcessorPlugin = (options = {}) => {
234246
// NOTE: `tag.line` can be 0 if of form `/** @tag ... */`
235247
const codeStartLine = /**
236248
* @type {import('comment-parser').Spec & {
237-
* line: import('./iterateJsdoc.js').Integer,
249+
* line: Integer,
238250
* }}
239251
*/ (tag).line + nonJSPrefacingLines;
240252
const codeStartCol = likelyNestedJSDocIndentSpace;
@@ -567,6 +579,7 @@ export const getJsdocProcessorPlugin = (options = {}) => {
567579
/**
568580
* @param {string} text
569581
* @param {string} filename
582+
* @returns {(string | Linter.ProcessorFile)[]}
570583
*/
571584
preprocess (text, filename) {
572585
try {
@@ -634,7 +647,14 @@ export const getJsdocProcessorPlugin = (options = {}) => {
634647
filename,
635648
commentLineCols[idx],
636649
);
637-
}).filter(Boolean),
650+
}).filter(
651+
/**
652+
* @returns {file is Linter.ProcessorFile}
653+
*/
654+
(file) => {
655+
return file !== null && file !== undefined;
656+
},
657+
),
638658
];
639659
/* c8 ignore next 6 */
640660
} catch (error) {

0 commit comments

Comments
 (0)