@api-extractor-tools/eslint-plugin 0.1.0-alpha.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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +183 -0
- package/api-extractor.json +10 -0
- package/dist/configs/index.d.ts +6 -0
- package/dist/configs/index.d.ts.map +1 -0
- package/dist/configs/index.js +11 -0
- package/dist/configs/index.js.map +1 -0
- package/dist/configs/recommended.d.ts +31 -0
- package/dist/configs/recommended.d.ts.map +1 -0
- package/dist/configs/recommended.js +45 -0
- package/dist/configs/recommended.js.map +1 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/rules/index.d.ts +14 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +20 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/missing-release-tag.d.ts +8 -0
- package/dist/rules/missing-release-tag.d.ts.map +1 -0
- package/dist/rules/missing-release-tag.js +148 -0
- package/dist/rules/missing-release-tag.js.map +1 -0
- package/dist/rules/override-keyword.d.ts +8 -0
- package/dist/rules/override-keyword.d.ts.map +1 -0
- package/dist/rules/override-keyword.js +106 -0
- package/dist/rules/override-keyword.js.map +1 -0
- package/dist/rules/package-documentation.d.ts +8 -0
- package/dist/rules/package-documentation.d.ts.map +1 -0
- package/dist/rules/package-documentation.js +70 -0
- package/dist/rules/package-documentation.js.map +1 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +19 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/config-loader.d.ts +47 -0
- package/dist/utils/config-loader.d.ts.map +1 -0
- package/dist/utils/config-loader.js +163 -0
- package/dist/utils/config-loader.js.map +1 -0
- package/dist/utils/entry-point.d.ts +56 -0
- package/dist/utils/entry-point.d.ts.map +1 -0
- package/dist/utils/entry-point.js +198 -0
- package/dist/utils/entry-point.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/tsdoc-parser.d.ts +58 -0
- package/dist/utils/tsdoc-parser.d.ts.map +1 -0
- package/dist/utils/tsdoc-parser.js +137 -0
- package/dist/utils/tsdoc-parser.js.map +1 -0
- package/package.json +44 -0
- package/src/configs/index.ts +6 -0
- package/src/configs/recommended.ts +46 -0
- package/src/index.ts +111 -0
- package/src/rules/index.ts +18 -0
- package/src/rules/missing-release-tag.ts +203 -0
- package/src/rules/override-keyword.ts +139 -0
- package/src/rules/package-documentation.ts +90 -0
- package/src/types.ts +104 -0
- package/src/utils/config-loader.ts +194 -0
- package/src/utils/entry-point.ts +247 -0
- package/src/utils/index.ts +17 -0
- package/src/utils/tsdoc-parser.ts +163 -0
- package/temp/eslint-plugin.api.md +118 -0
- package/test/index.test.ts +66 -0
- package/test/rules/missing-release-tag.test.ts +184 -0
- package/test/rules/override-keyword.test.ts +171 -0
- package/test/rules/package-documentation.test.ts +152 -0
- package/test/tsconfig.json +11 -0
- package/test/utils/config-loader.test.ts +199 -0
- package/test/utils/entry-point.test.ts +172 -0
- package/test/utils/tsdoc-parser.test.ts +113 -0
- package/tsconfig.json +12 -0
- package/vitest.config.mts +25 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utilities for discovering and loading API Extractor configuration.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.findApiExtractorConfig = findApiExtractorConfig;
|
|
8
|
+
exports.loadApiExtractorConfig = loadApiExtractorConfig;
|
|
9
|
+
exports.getMessageLogLevel = getMessageLogLevel;
|
|
10
|
+
exports.resolveConfig = resolveConfig;
|
|
11
|
+
exports.logLevelToSeverity = logLevelToSeverity;
|
|
12
|
+
exports.clearConfigCache = clearConfigCache;
|
|
13
|
+
const fs = require("fs");
|
|
14
|
+
const path = require("path");
|
|
15
|
+
/**
|
|
16
|
+
* Default message configuration when no api-extractor.json is found.
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_MESSAGES_CONFIG = {
|
|
19
|
+
extractorMessageReporting: {
|
|
20
|
+
default: { logLevel: 'warning' },
|
|
21
|
+
'ae-missing-release-tag': { logLevel: 'warning' },
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Cache for loaded configurations to avoid repeated file reads.
|
|
26
|
+
*/
|
|
27
|
+
const configCache = new Map();
|
|
28
|
+
/**
|
|
29
|
+
* Searches upward from the given directory to find api-extractor.json.
|
|
30
|
+
*
|
|
31
|
+
* @param startDir - Directory to start searching from
|
|
32
|
+
* @returns Path to api-extractor.json if found, undefined otherwise
|
|
33
|
+
*/
|
|
34
|
+
function findApiExtractorConfig(startDir) {
|
|
35
|
+
let currentDir = path.resolve(startDir);
|
|
36
|
+
const root = path.parse(currentDir).root;
|
|
37
|
+
while (currentDir !== root) {
|
|
38
|
+
const configPath = path.join(currentDir, 'api-extractor.json');
|
|
39
|
+
if (fs.existsSync(configPath)) {
|
|
40
|
+
return configPath;
|
|
41
|
+
}
|
|
42
|
+
currentDir = path.dirname(currentDir);
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Loads and parses an api-extractor.json file.
|
|
48
|
+
*
|
|
49
|
+
* @param configPath - Path to the api-extractor.json file
|
|
50
|
+
* @returns Parsed configuration or null if file cannot be read
|
|
51
|
+
*/
|
|
52
|
+
function loadApiExtractorConfig(configPath) {
|
|
53
|
+
// Check cache first
|
|
54
|
+
const cached = configCache.get(configPath);
|
|
55
|
+
if (cached !== undefined) {
|
|
56
|
+
return cached;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const content = fs.readFileSync(configPath, 'utf-8');
|
|
60
|
+
// Remove comments (api-extractor.json supports JSON with comments)
|
|
61
|
+
const jsonContent = content.replace(/\/\/.*$|\/\*[\s\S]*?\*\//gm, '');
|
|
62
|
+
const config = JSON.parse(jsonContent);
|
|
63
|
+
// Handle extends
|
|
64
|
+
if (config.extends) {
|
|
65
|
+
const baseConfigPath = path.resolve(path.dirname(configPath), config.extends);
|
|
66
|
+
const baseConfig = loadApiExtractorConfig(baseConfigPath);
|
|
67
|
+
if (baseConfig) {
|
|
68
|
+
// Merge base config with current config
|
|
69
|
+
const merged = mergeConfigs(baseConfig, config);
|
|
70
|
+
configCache.set(configPath, merged);
|
|
71
|
+
return merged;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
configCache.set(configPath, config);
|
|
75
|
+
return config;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
configCache.set(configPath, null);
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Merges two API Extractor configurations, with the override taking precedence.
|
|
84
|
+
*/
|
|
85
|
+
function mergeConfigs(base, override) {
|
|
86
|
+
return {
|
|
87
|
+
...base,
|
|
88
|
+
...override,
|
|
89
|
+
messages: {
|
|
90
|
+
compilerMessageReporting: {
|
|
91
|
+
...base.messages?.compilerMessageReporting,
|
|
92
|
+
...override.messages?.compilerMessageReporting,
|
|
93
|
+
},
|
|
94
|
+
extractorMessageReporting: {
|
|
95
|
+
...base.messages?.extractorMessageReporting,
|
|
96
|
+
...override.messages?.extractorMessageReporting,
|
|
97
|
+
},
|
|
98
|
+
tsdocMessageReporting: {
|
|
99
|
+
...base.messages?.tsdocMessageReporting,
|
|
100
|
+
...override.messages?.tsdocMessageReporting,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Gets the log level for a specific message ID from the configuration.
|
|
107
|
+
*
|
|
108
|
+
* @param config - API Extractor configuration
|
|
109
|
+
* @param messageId - The message ID (e.g., 'ae-missing-release-tag')
|
|
110
|
+
* @returns The configured log level, or 'warning' as default
|
|
111
|
+
*/
|
|
112
|
+
function getMessageLogLevel(config, messageId) {
|
|
113
|
+
if (!config?.messages?.extractorMessageReporting) {
|
|
114
|
+
return (DEFAULT_MESSAGES_CONFIG.extractorMessageReporting?.default?.logLevel ??
|
|
115
|
+
'warning');
|
|
116
|
+
}
|
|
117
|
+
const reporting = config.messages.extractorMessageReporting;
|
|
118
|
+
const messageConfig = reporting[messageId];
|
|
119
|
+
if (messageConfig?.logLevel) {
|
|
120
|
+
return messageConfig.logLevel;
|
|
121
|
+
}
|
|
122
|
+
return reporting.default?.logLevel ?? 'warning';
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Resolves configuration for a file, using auto-discovery or explicit path.
|
|
126
|
+
*
|
|
127
|
+
* @param filePath - Path to the file being linted
|
|
128
|
+
* @param explicitConfigPath - Optional explicit path to api-extractor.json
|
|
129
|
+
* @returns The resolved configuration or null
|
|
130
|
+
*/
|
|
131
|
+
function resolveConfig(filePath, explicitConfigPath) {
|
|
132
|
+
if (explicitConfigPath) {
|
|
133
|
+
return loadApiExtractorConfig(explicitConfigPath);
|
|
134
|
+
}
|
|
135
|
+
const discovered = findApiExtractorConfig(path.dirname(filePath));
|
|
136
|
+
if (discovered) {
|
|
137
|
+
return loadApiExtractorConfig(discovered);
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Maps API Extractor log level to ESLint severity.
|
|
143
|
+
*
|
|
144
|
+
* @param logLevel - API Extractor log level
|
|
145
|
+
* @returns ESLint severity (0 = off, 1 = warn, 2 = error)
|
|
146
|
+
*/
|
|
147
|
+
function logLevelToSeverity(logLevel) {
|
|
148
|
+
switch (logLevel) {
|
|
149
|
+
case 'error':
|
|
150
|
+
return 2;
|
|
151
|
+
case 'warning':
|
|
152
|
+
return 1;
|
|
153
|
+
case 'none':
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Clears the configuration cache. Useful for testing.
|
|
159
|
+
*/
|
|
160
|
+
function clearConfigCache() {
|
|
161
|
+
configCache.clear();
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=config-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../../src/utils/config-loader.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AA+BH,wDAaC;AAQD,wDAoCC;AAoCD,gDAmBC;AASD,sCAcC;AAQD,gDASC;AAKD,4CAEC;AA5LD,yBAAwB;AACxB,6BAA4B;AAO5B;;GAEG;AACH,MAAM,uBAAuB,GAA+B;IAC1D,yBAAyB,EAAE;QACzB,OAAO,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE;QAChC,wBAAwB,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE;KAClD;CACF,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,GAAG,IAAI,GAAG,EAAqC,CAAA;AAEhE;;;;;GAKG;AACH,SAAgB,sBAAsB,CAAC,QAAgB;IACrD,IAAI,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IACvC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CAAA;IAExC,OAAO,UAAU,KAAK,IAAI,EAAE,CAAC;QAC3B,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,oBAAoB,CAAC,CAAA;QAC9D,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9B,OAAO,UAAU,CAAA;QACnB,CAAC;QACD,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IACvC,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB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AO,IAAI,CAAA;AACb,CAAC;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,QAA8B;IAC/D,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,OAAO;YACV,OAAO,CAAC,CAAA;QACV,KAAK,SAAS;YACZ,OAAO,CAAC,CAAA;QACV,KAAK,MAAM;YACT,OAAO,CAAC,CAAA;IACZ,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,WAAW,CAAC,KAAK,EAAE,CAAA;AACrB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for resolving package.json entry points.
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
import type { ResolvedEntryPoints } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Represents the relevant fields from package.json.
|
|
8
|
+
*/
|
|
9
|
+
interface PackageJson {
|
|
10
|
+
main?: string;
|
|
11
|
+
types?: string;
|
|
12
|
+
typings?: string;
|
|
13
|
+
module?: string;
|
|
14
|
+
exports?: PackageExports;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Package.json exports field can be complex.
|
|
18
|
+
*/
|
|
19
|
+
type PackageExports = string | {
|
|
20
|
+
[key: string]: PackageExports | string | undefined;
|
|
21
|
+
} | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Finds the nearest package.json by searching upward from a directory.
|
|
24
|
+
*
|
|
25
|
+
* @param startDir - Directory to start searching from
|
|
26
|
+
* @returns Path to package.json if found, undefined otherwise
|
|
27
|
+
*/
|
|
28
|
+
export declare function findPackageJson(startDir: string): string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Loads and parses a package.json file.
|
|
31
|
+
*
|
|
32
|
+
* @param pkgPath - Path to the package.json file
|
|
33
|
+
* @returns Parsed package.json or null if file cannot be read
|
|
34
|
+
*/
|
|
35
|
+
export declare function loadPackageJson(pkgPath: string): PackageJson | null;
|
|
36
|
+
/**
|
|
37
|
+
* Resolves all entry points from a package.json.
|
|
38
|
+
*
|
|
39
|
+
* @param pkgPath - Path to the package.json file
|
|
40
|
+
* @returns Resolved entry points with absolute paths
|
|
41
|
+
*/
|
|
42
|
+
export declare function resolveEntryPoints(pkgPath: string): ResolvedEntryPoints;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if a file is a package entry point.
|
|
45
|
+
*
|
|
46
|
+
* @param filePath - Absolute path to the file being checked
|
|
47
|
+
* @param pkgPath - Path to the package.json
|
|
48
|
+
* @returns True if the file is an entry point
|
|
49
|
+
*/
|
|
50
|
+
export declare function isEntryPoint(filePath: string, pkgPath: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Clears the package.json cache. Useful for testing.
|
|
53
|
+
*/
|
|
54
|
+
export declare function clearPackageJsonCache(): void;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=entry-point.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-point.d.ts","sourceRoot":"","sources":["../../src/utils/entry-point.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAEnD;;GAEG;AACH,UAAU,WAAW;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,cAAc,CAAA;CACzB;AAED;;GAEG;AACH,KAAK,cAAc,GACf,MAAM,GACN;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,GAAG,MAAM,GAAG,SAAS,CAAA;CAAE,GACtD,SAAS,CAAA;AAOb;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAapE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAenE;AAuBD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB,CA6BvE;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CA6DvE;AAsCD;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utilities for resolving package.json entry points.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.findPackageJson = findPackageJson;
|
|
8
|
+
exports.loadPackageJson = loadPackageJson;
|
|
9
|
+
exports.resolveEntryPoints = resolveEntryPoints;
|
|
10
|
+
exports.isEntryPoint = isEntryPoint;
|
|
11
|
+
exports.clearPackageJsonCache = clearPackageJsonCache;
|
|
12
|
+
const fs = require("fs");
|
|
13
|
+
const path = require("path");
|
|
14
|
+
/**
|
|
15
|
+
* Cache for package.json lookups.
|
|
16
|
+
*/
|
|
17
|
+
const packageJsonCache = new Map();
|
|
18
|
+
/**
|
|
19
|
+
* Finds the nearest package.json by searching upward from a directory.
|
|
20
|
+
*
|
|
21
|
+
* @param startDir - Directory to start searching from
|
|
22
|
+
* @returns Path to package.json if found, undefined otherwise
|
|
23
|
+
*/
|
|
24
|
+
function findPackageJson(startDir) {
|
|
25
|
+
let currentDir = path.resolve(startDir);
|
|
26
|
+
const root = path.parse(currentDir).root;
|
|
27
|
+
while (currentDir !== root) {
|
|
28
|
+
const pkgPath = path.join(currentDir, 'package.json');
|
|
29
|
+
if (fs.existsSync(pkgPath)) {
|
|
30
|
+
return pkgPath;
|
|
31
|
+
}
|
|
32
|
+
currentDir = path.dirname(currentDir);
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Loads and parses a package.json file.
|
|
38
|
+
*
|
|
39
|
+
* @param pkgPath - Path to the package.json file
|
|
40
|
+
* @returns Parsed package.json or null if file cannot be read
|
|
41
|
+
*/
|
|
42
|
+
function loadPackageJson(pkgPath) {
|
|
43
|
+
const cached = packageJsonCache.get(pkgPath);
|
|
44
|
+
if (cached !== undefined) {
|
|
45
|
+
return cached;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const content = fs.readFileSync(pkgPath, 'utf-8');
|
|
49
|
+
const pkg = JSON.parse(content);
|
|
50
|
+
packageJsonCache.set(pkgPath, pkg);
|
|
51
|
+
return pkg;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
packageJsonCache.set(pkgPath, null);
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Extracts all entry point paths from package.json exports field.
|
|
60
|
+
*
|
|
61
|
+
* @param exports - The exports field value
|
|
62
|
+
* @param results - Array to collect results
|
|
63
|
+
*/
|
|
64
|
+
function extractExportPaths(exports, results) {
|
|
65
|
+
if (typeof exports === 'string') {
|
|
66
|
+
results.push(exports);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (exports && typeof exports === 'object') {
|
|
70
|
+
for (const value of Object.values(exports)) {
|
|
71
|
+
if (value !== undefined) {
|
|
72
|
+
extractExportPaths(value, results);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Resolves all entry points from a package.json.
|
|
79
|
+
*
|
|
80
|
+
* @param pkgPath - Path to the package.json file
|
|
81
|
+
* @returns Resolved entry points with absolute paths
|
|
82
|
+
*/
|
|
83
|
+
function resolveEntryPoints(pkgPath) {
|
|
84
|
+
const pkg = loadPackageJson(pkgPath);
|
|
85
|
+
const pkgDir = path.dirname(pkgPath);
|
|
86
|
+
const result = { exports: [] };
|
|
87
|
+
if (!pkg) {
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
// Resolve main entry point
|
|
91
|
+
if (pkg.main) {
|
|
92
|
+
result.main = path.resolve(pkgDir, pkg.main);
|
|
93
|
+
}
|
|
94
|
+
// Resolve types entry point
|
|
95
|
+
if (pkg.types) {
|
|
96
|
+
result.types = path.resolve(pkgDir, pkg.types);
|
|
97
|
+
}
|
|
98
|
+
else if (pkg.typings) {
|
|
99
|
+
result.types = path.resolve(pkgDir, pkg.typings);
|
|
100
|
+
}
|
|
101
|
+
// Resolve exports
|
|
102
|
+
if (pkg.exports) {
|
|
103
|
+
const exportPaths = [];
|
|
104
|
+
extractExportPaths(pkg.exports, exportPaths);
|
|
105
|
+
result.exports = exportPaths.map((p) => path.resolve(pkgDir, p));
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Checks if a file is a package entry point.
|
|
111
|
+
*
|
|
112
|
+
* @param filePath - Absolute path to the file being checked
|
|
113
|
+
* @param pkgPath - Path to the package.json
|
|
114
|
+
* @returns True if the file is an entry point
|
|
115
|
+
*/
|
|
116
|
+
function isEntryPoint(filePath, pkgPath) {
|
|
117
|
+
const entryPoints = resolveEntryPoints(pkgPath);
|
|
118
|
+
const absoluteFilePath = path.resolve(filePath);
|
|
119
|
+
// Check main
|
|
120
|
+
if (entryPoints.main &&
|
|
121
|
+
normalizeForComparison(entryPoints.main) ===
|
|
122
|
+
normalizeForComparison(absoluteFilePath)) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
// Check types
|
|
126
|
+
if (entryPoints.types &&
|
|
127
|
+
normalizeForComparison(entryPoints.types) ===
|
|
128
|
+
normalizeForComparison(absoluteFilePath)) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
// Check exports
|
|
132
|
+
for (const exportPath of entryPoints.exports) {
|
|
133
|
+
if (normalizeForComparison(exportPath) ===
|
|
134
|
+
normalizeForComparison(absoluteFilePath)) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Also check if the TypeScript source file corresponds to the entry point
|
|
139
|
+
// e.g., src/index.ts -> dist/index.js
|
|
140
|
+
const sourceEquivalents = getSourceEquivalents(absoluteFilePath);
|
|
141
|
+
for (const sourcePath of sourceEquivalents) {
|
|
142
|
+
if (entryPoints.main &&
|
|
143
|
+
normalizeForComparison(entryPoints.main) ===
|
|
144
|
+
normalizeForComparison(sourcePath)) {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
if (entryPoints.types &&
|
|
148
|
+
normalizeForComparison(entryPoints.types) ===
|
|
149
|
+
normalizeForComparison(sourcePath)) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
for (const exportPath of entryPoints.exports) {
|
|
153
|
+
if (normalizeForComparison(exportPath) ===
|
|
154
|
+
normalizeForComparison(sourcePath)) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Normalizes a path for comparison by removing extension variations.
|
|
163
|
+
*/
|
|
164
|
+
function normalizeForComparison(filePath) {
|
|
165
|
+
// Remove common extensions and normalize
|
|
166
|
+
return filePath
|
|
167
|
+
.replace(/\.(js|ts|mjs|cjs|mts|cts|d\.ts|d\.mts|d\.cts)$/, '')
|
|
168
|
+
.replace(/\/index$/, '');
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Gets potential source file equivalents for a dist file.
|
|
172
|
+
*/
|
|
173
|
+
function getSourceEquivalents(filePath) {
|
|
174
|
+
const equivalents = [];
|
|
175
|
+
const dir = path.dirname(filePath);
|
|
176
|
+
const base = path.basename(filePath).replace(/\.(ts|tsx|js|jsx|mjs|cjs)$/, '');
|
|
177
|
+
// Try common source directory patterns
|
|
178
|
+
const sourcePatterns = [
|
|
179
|
+
dir.replace('/dist/', '/src/').replace('\\dist\\', '\\src\\'),
|
|
180
|
+
dir.replace('/build/', '/src/').replace('\\build\\', '\\src\\'),
|
|
181
|
+
dir.replace('/lib/', '/src/').replace('\\lib\\', '\\src\\'),
|
|
182
|
+
];
|
|
183
|
+
for (const sourceDir of sourcePatterns) {
|
|
184
|
+
if (sourceDir !== dir) {
|
|
185
|
+
equivalents.push(path.join(sourceDir, `${base}.ts`));
|
|
186
|
+
equivalents.push(path.join(sourceDir, `${base}.tsx`));
|
|
187
|
+
equivalents.push(path.join(sourceDir, `${base}.js`));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return equivalents;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Clears the package.json cache. Useful for testing.
|
|
194
|
+
*/
|
|
195
|
+
function clearPackageJsonCache() {
|
|
196
|
+
packageJsonCache.clear();
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=entry-point.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-point.js","sourceRoot":"","sources":["../../src/utils/entry-point.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAoCH,0CAaC;AAQD,0CAeC;AA6BD,gDA6BC;AASD,oCA6DC;AAyCD,sDAEC;AAjPD,yBAAwB;AACxB,6BAA4B;AAsB5B;;GAEG;AACH,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAA8B,CAAA;AAE9D;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,QAAgB;IAC9C,IAAI,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IACvC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CAAA;IAExC,OAAO,UAAU,KAAK,IAAI,EAAE,CAAC;QAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAA;QACrD,IAAI,EAAE,CAAC,U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AC,CAAA;QACtD,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB;IACnC,gBAAgB,CAAC,KAAK,EAAE,CAAA;AAC1B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility module exports.
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export { resolveConfig, getMessageLogLevel } from './config-loader';
|
|
6
|
+
export { parseTSDocComment, extractReleaseTag, hasOverrideTag, hasPackageDocumentation, getLeadingTSDocComment, findAllTSDocComments, } from './tsdoc-parser';
|
|
7
|
+
export { findPackageJson, isEntryPoint } from './entry-point';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEnE,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,uBAAuB,EACvB,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility module exports.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.isEntryPoint = exports.findPackageJson = exports.findAllTSDocComments = exports.getLeadingTSDocComment = exports.hasPackageDocumentation = exports.hasOverrideTag = exports.extractReleaseTag = exports.parseTSDocComment = exports.getMessageLogLevel = exports.resolveConfig = void 0;
|
|
8
|
+
var config_loader_1 = require("./config-loader");
|
|
9
|
+
Object.defineProperty(exports, "resolveConfig", { enumerable: true, get: function () { return config_loader_1.resolveConfig; } });
|
|
10
|
+
Object.defineProperty(exports, "getMessageLogLevel", { enumerable: true, get: function () { return config_loader_1.getMessageLogLevel; } });
|
|
11
|
+
var tsdoc_parser_1 = require("./tsdoc-parser");
|
|
12
|
+
Object.defineProperty(exports, "parseTSDocComment", { enumerable: true, get: function () { return tsdoc_parser_1.parseTSDocComment; } });
|
|
13
|
+
Object.defineProperty(exports, "extractReleaseTag", { enumerable: true, get: function () { return tsdoc_parser_1.extractReleaseTag; } });
|
|
14
|
+
Object.defineProperty(exports, "hasOverrideTag", { enumerable: true, get: function () { return tsdoc_parser_1.hasOverrideTag; } });
|
|
15
|
+
Object.defineProperty(exports, "hasPackageDocumentation", { enumerable: true, get: function () { return tsdoc_parser_1.hasPackageDocumentation; } });
|
|
16
|
+
Object.defineProperty(exports, "getLeadingTSDocComment", { enumerable: true, get: function () { return tsdoc_parser_1.getLeadingTSDocComment; } });
|
|
17
|
+
Object.defineProperty(exports, "findAllTSDocComments", { enumerable: true, get: function () { return tsdoc_parser_1.findAllTSDocComments; } });
|
|
18
|
+
var entry_point_1 = require("./entry-point");
|
|
19
|
+
Object.defineProperty(exports, "findPackageJson", { enumerable: true, get: function () { return entry_point_1.findPackageJson; } });
|
|
20
|
+
Object.defineProperty(exports, "isEntryPoint", { enumerable: true, get: function () { return entry_point_1.isEntryPoint; } });
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iDAAmE;AAA1D,8GAAA,aAAa,OAAA;AAAE,mHAAA,kBAAkB,OAAA;AAE1C,+CAOuB;AANrB,iHAAA,iBAAiB,OAAA;AACjB,iHAAA,iBAAiB,OAAA;AACjB,8GAAA,cAAc,OAAA;AACd,uHAAA,uBAAuB,OAAA;AACvB,sHAAA,sBAAsB,OAAA;AACtB,oHAAA,oBAAoB,OAAA;AAGtB,6CAA6D;AAApD,8GAAA,eAAe,OAAA;AAAE,2GAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for parsing TSDoc comments.
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
import { ParserContext, DocComment } from '@microsoft/tsdoc';
|
|
6
|
+
import type { TSESTree } from '@typescript-eslint/utils';
|
|
7
|
+
import type { ReleaseTag } from '../types';
|
|
8
|
+
/**
|
|
9
|
+
* Parses a TSDoc comment string.
|
|
10
|
+
*
|
|
11
|
+
* @param commentText - The full comment text including delimiters
|
|
12
|
+
* @returns Parser context with the parsed doc comment
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseTSDocComment(commentText: string): ParserContext;
|
|
15
|
+
/**
|
|
16
|
+
* Extracts a release tag from a parsed TSDoc comment.
|
|
17
|
+
*
|
|
18
|
+
* @param docComment - The parsed doc comment
|
|
19
|
+
* @returns The release tag if found, undefined otherwise
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractReleaseTag(docComment: DocComment): ReleaseTag | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Checks if a TSDoc comment has the @override tag.
|
|
24
|
+
*
|
|
25
|
+
* @param docComment - The parsed doc comment
|
|
26
|
+
* @returns True if @override tag is present
|
|
27
|
+
*/
|
|
28
|
+
export declare function hasOverrideTag(docComment: DocComment): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a TSDoc comment has the @packageDocumentation tag.
|
|
31
|
+
*
|
|
32
|
+
* @param docComment - The parsed doc comment
|
|
33
|
+
* @returns True if @packageDocumentation tag is present
|
|
34
|
+
*/
|
|
35
|
+
export declare function hasPackageDocumentation(docComment: DocComment): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Gets the leading comment for a node, if it's a TSDoc comment.
|
|
38
|
+
*
|
|
39
|
+
* @param sourceCode - ESLint source code object
|
|
40
|
+
* @param node - The AST node to check
|
|
41
|
+
* @returns The comment text if a TSDoc comment exists, undefined otherwise
|
|
42
|
+
*/
|
|
43
|
+
export declare function getLeadingTSDocComment(sourceCode: {
|
|
44
|
+
getCommentsBefore: (node: TSESTree.Node) => TSESTree.Comment[];
|
|
45
|
+
}, node: TSESTree.Node): string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Finds all TSDoc comments in a source file.
|
|
48
|
+
*
|
|
49
|
+
* @param sourceCode - ESLint source code object
|
|
50
|
+
* @returns Array of comment objects with their parsed content
|
|
51
|
+
*/
|
|
52
|
+
export declare function findAllTSDocComments(sourceCode: {
|
|
53
|
+
getAllComments: () => TSESTree.Comment[];
|
|
54
|
+
}): Array<{
|
|
55
|
+
comment: TSESTree.Comment;
|
|
56
|
+
parsed: ParserContext;
|
|
57
|
+
}>;
|
|
58
|
+
//# sourceMappingURL=tsdoc-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsdoc-parser.d.ts","sourceRoot":"","sources":["../../src/utils/tsdoc-parser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAIL,aAAa,EACb,UAAU,EACX,MAAM,kBAAkB,CAAA;AACzB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAqB1C;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,aAAa,CAIpE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,UAAU,GACrB,UAAU,GAAG,SAAS,CAexB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAEvE;AAWD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE;IACV,iBAAiB,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,OAAO,EAAE,CAAA;CAC/D,EACD,IAAI,EAAE,QAAQ,CAAC,IAAI,GAClB,MAAM,GAAG,SAAS,CAyBpB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE;IAC/C,cAAc,EAAE,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAA;CACzC,GAAG,KAAK,CAAC;IAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,CAAC,CAe9D"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utilities for parsing TSDoc comments.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.parseTSDocComment = parseTSDocComment;
|
|
8
|
+
exports.extractReleaseTag = extractReleaseTag;
|
|
9
|
+
exports.hasOverrideTag = hasOverrideTag;
|
|
10
|
+
exports.hasPackageDocumentation = hasPackageDocumentation;
|
|
11
|
+
exports.getLeadingTSDocComment = getLeadingTSDocComment;
|
|
12
|
+
exports.findAllTSDocComments = findAllTSDocComments;
|
|
13
|
+
const tsdoc_1 = require("@microsoft/tsdoc");
|
|
14
|
+
/**
|
|
15
|
+
* TSDoc parser instance configured for API Extractor compatibility.
|
|
16
|
+
*/
|
|
17
|
+
let parserInstance;
|
|
18
|
+
/**
|
|
19
|
+
* Gets or creates a TSDoc parser instance.
|
|
20
|
+
*/
|
|
21
|
+
function getParser() {
|
|
22
|
+
if (!parserInstance) {
|
|
23
|
+
const config = new tsdoc_1.TSDocConfiguration();
|
|
24
|
+
// API Extractor's custom tags are defined via tsdoc.json extends
|
|
25
|
+
// For our purposes, the default configuration suffices as we're
|
|
26
|
+
// checking for standard modifier tags
|
|
27
|
+
parserInstance = new tsdoc_1.TSDocParser(config);
|
|
28
|
+
}
|
|
29
|
+
return parserInstance;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parses a TSDoc comment string.
|
|
33
|
+
*
|
|
34
|
+
* @param commentText - The full comment text including delimiters
|
|
35
|
+
* @returns Parser context with the parsed doc comment
|
|
36
|
+
*/
|
|
37
|
+
function parseTSDocComment(commentText) {
|
|
38
|
+
const parser = getParser();
|
|
39
|
+
const textRange = tsdoc_1.TextRange.fromString(commentText);
|
|
40
|
+
return parser.parseRange(textRange);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Extracts a release tag from a parsed TSDoc comment.
|
|
44
|
+
*
|
|
45
|
+
* @param docComment - The parsed doc comment
|
|
46
|
+
* @returns The release tag if found, undefined otherwise
|
|
47
|
+
*/
|
|
48
|
+
function extractReleaseTag(docComment) {
|
|
49
|
+
// Check for modifier tags
|
|
50
|
+
if (docComment.modifierTagSet.isPublic()) {
|
|
51
|
+
return 'public';
|
|
52
|
+
}
|
|
53
|
+
if (docComment.modifierTagSet.isBeta()) {
|
|
54
|
+
return 'beta';
|
|
55
|
+
}
|
|
56
|
+
if (docComment.modifierTagSet.isAlpha()) {
|
|
57
|
+
return 'alpha';
|
|
58
|
+
}
|
|
59
|
+
if (docComment.modifierTagSet.isInternal()) {
|
|
60
|
+
return 'internal';
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Checks if a TSDoc comment has the @override tag.
|
|
66
|
+
*
|
|
67
|
+
* @param docComment - The parsed doc comment
|
|
68
|
+
* @returns True if @override tag is present
|
|
69
|
+
*/
|
|
70
|
+
function hasOverrideTag(docComment) {
|
|
71
|
+
return docComment.modifierTagSet.isOverride();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Checks if a TSDoc comment has the @packageDocumentation tag.
|
|
75
|
+
*
|
|
76
|
+
* @param docComment - The parsed doc comment
|
|
77
|
+
* @returns True if @packageDocumentation tag is present
|
|
78
|
+
*/
|
|
79
|
+
function hasPackageDocumentation(docComment) {
|
|
80
|
+
return docComment.modifierTagSet.isPackageDocumentation();
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Checks if a comment is a block comment (TSDoc style).
|
|
84
|
+
*/
|
|
85
|
+
function isBlockComment(comment) {
|
|
86
|
+
// TSESTree.Comment.type is 'Line' | 'Block' - comparing to string literal
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
88
|
+
return comment.type === 'Block';
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Gets the leading comment for a node, if it's a TSDoc comment.
|
|
92
|
+
*
|
|
93
|
+
* @param sourceCode - ESLint source code object
|
|
94
|
+
* @param node - The AST node to check
|
|
95
|
+
* @returns The comment text if a TSDoc comment exists, undefined otherwise
|
|
96
|
+
*/
|
|
97
|
+
function getLeadingTSDocComment(sourceCode, node) {
|
|
98
|
+
const comments = sourceCode.getCommentsBefore(node);
|
|
99
|
+
if (comments.length === 0) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
// Get the last comment before the node (closest to it)
|
|
103
|
+
const lastComment = comments[comments.length - 1];
|
|
104
|
+
if (!lastComment) {
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
// TSDoc comments must be block comments starting with /**
|
|
108
|
+
if (!isBlockComment(lastComment)) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
// Check if it's a TSDoc comment (starts with *)
|
|
112
|
+
const value = lastComment.value;
|
|
113
|
+
if (!value.startsWith('*')) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
// Reconstruct the full comment
|
|
117
|
+
return `/*${value}*/`;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Finds all TSDoc comments in a source file.
|
|
121
|
+
*
|
|
122
|
+
* @param sourceCode - ESLint source code object
|
|
123
|
+
* @returns Array of comment objects with their parsed content
|
|
124
|
+
*/
|
|
125
|
+
function findAllTSDocComments(sourceCode) {
|
|
126
|
+
const results = [];
|
|
127
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
128
|
+
if (!isBlockComment(comment) || !comment.value.startsWith('*')) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const commentText = `/*${comment.value}*/`;
|
|
132
|
+
const parsed = parseTSDocComment(commentText);
|
|
133
|
+
results.push({ comment, parsed });
|
|
134
|
+
}
|
|
135
|
+
return results;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=tsdoc-parser.js.map
|