Skip to content

Commit 0b5fd4c

Browse files
committed
refactor: add prettier-plugin-jsdoc
1 parent 6f0a280 commit 0b5fd4c

File tree

14 files changed

+425
-90
lines changed

14 files changed

+425
-90
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"eslint": "9.x",
7474
"globals": "^15.9.0",
7575
"prettier": "^3.3.3",
76+
"prettier-plugin-jsdoc": "^1.3.0",
7677
"ts-patch": "^3.2.1",
7778
"typescript": "^5.5.4",
7879
"typescript-eslint": "^8.0.1"
@@ -83,5 +84,10 @@
8384
"dependencies": {
8485
"minimatch": "^10.0.1"
8586
},
87+
"prettier": {
88+
"plugins": [
89+
"prettier-plugin-jsdoc"
90+
]
91+
},
8692
"packageManager": "[email protected]+sha512.91d93b445d9284e7ed52931369bc89a663414e5582d00eea45c67ddc459a2582919eece27c412d6ffd1bd0793ff35399381cb229326b961798ce4f4cc60ddfdb"
8793
}

src/harmony/harmony-factory.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ export interface HarmonyFactory extends TS.NodeFactory {}
1414
// region: Utilities
1515
/* ****************************************************************************************************************** */
1616

17-
/**
18-
* Creates a node factory compatible with TS v3+
19-
*/
17+
/** Creates a node factory compatible with TS v3+ */
2018
export function createHarmonyFactory(context: TsTransformPathsContext): HarmonyFactory {
2119
return new Proxy(context.tsFactory ?? context.tsInstance, {
2220
get(target, prop) {

src/harmony/versions/four-seven.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/**
2-
* Changes after this point: https://github.com/microsoft/TypeScript/wiki/API-Breaking-Changes#typescript-48
3-
*/
1+
/** Changes after this point: https://github.com/microsoft/TypeScript/wiki/API-Breaking-Changes#typescript-48 */
42
import type {
53
default as TsCurrentModule,
64
AssertClause,

src/harmony/versions/three-eight.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/**
2-
* Changes after this point: https://github.com/microsoft/TypeScript/wiki/API-Breaking-Changes#typescript-40
3-
*/
1+
/** Changes after this point: https://github.com/microsoft/TypeScript/wiki/API-Breaking-Changes#typescript-40 */
42
import type {
53
default as TsCurrentModule,
64
EntityName,

src/transformer.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ export default function transformer(
7979
program?: ts.Program,
8080
pluginConfig?: TsTransformPathsConfig,
8181
transformerExtras?: TransformerExtras,
82-
/**
83-
* Supply if manually transforming with compiler API via 'transformNodes' / 'transformModule'
84-
*/
82+
/** Supply if manually transforming with compiler API via 'transformNodes' / 'transformModule' */
8583
manualTransformOptions?: {
8684
compilerOptions?: ts.CompilerOptions;
8785
fileNames?: string[];

src/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ export interface TsTransformPathsConfig extends PluginConfig {
2929
/* ****************************************************************************************************************** */
3030

3131
export interface TsTransformPathsContext {
32-
/**
33-
* TS Instance passed from ts-patch / ttypescript
34-
*/
32+
/** TS Instance passed from ts-patch / ttypescript */
3533
readonly tsInstance: typeof ts;
3634
readonly tsVersionMajor: number;
3735
readonly tsVersionMinor: number;

src/utils/elide-import-export.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
11
/**
2-
* ----------------------------------------------------------------------------
32
* UPDATE:
43
*
54
* TODO - In next major version, we can remove this file entirely due to TS PR 57223
65
* https://github.com/microsoft/TypeScript/pull/57223
7-
* ----------------------------------------------------------------------------
86
*
9-
* This file and its contents are due to an issue in TypeScript (affecting *at least* up to 4.1) which causes type
7+
* This file and its contents are due to an issue in TypeScript (affecting _at least_ up to 4.1) which causes type
108
* elision to break during emit for nodes which have been transformed. Specifically, if the 'original' property is set,
119
* elision functionality no longer works.
1210
*
13-
* This results in module specifiers for types being output in import/export declarations in the compiled *JS files*
11+
* This results in module specifiers for types being output in import/export declarations in the compiled _JS files_
1412
*
1513
* The logic herein compensates for that issue by recreating type elision separately so that the transformer can update
1614
* the clause with the properly elided information
1715
*
1816
* Issues:
19-
* @see https://github.com/LeDDGroup/typescript-transform-paths/issues/184
20-
* @see https://github.com/microsoft/TypeScript/issues/40603
21-
* @see https://github.com/microsoft/TypeScript/issues/31446
17+
*
18+
* - See https://github.com/LeDDGroup/typescript-transform-paths/issues/184
19+
* - See https://github.com/microsoft/TypeScript/issues/40603
20+
* - See https://github.com/microsoft/TypeScript/issues/31446
2221
*
2322
* @example
24-
* // a.ts
25-
* export type A = string
26-
* export const B = 2
23+
* // a.ts
24+
* export type A = string;
25+
* export const B = 2;
2726
*
28-
* // b.ts
29-
* import { A, B } from './b'
30-
* export { A } from './b'
27+
* // b.ts
28+
* import { A, B } from "./b";
29+
* export { A } from "./b";
3130
*
32-
* // Expected output for b.js
33-
* import { B } from './b'
31+
* // Expected output for b.js
32+
* import { B } from "./b";
3433
*
35-
* // Actual output for b.js
36-
* import { A, B } from './b'
37-
* export { A } from './b'
34+
* // Actual output for b.js
35+
* import { A, B } from "./b";
36+
* export { A } from "./b";
3837
*/
3938
import { ImportOrExportDeclaration, VisitorContext } from "../types";
4039
import {
@@ -60,10 +59,10 @@ import {
6059
/* ****************************************************************************************************************** */
6160

6261
/**
63-
* Get import / export clause for node (replicates TS elision behaviour for js files)
64-
* See notes in get-import-export-clause.ts header for why this is necessary
62+
* Get import / export clause for node (replicates TS elision behaviour for js files) See notes in
63+
* get-import-export-clause.ts header for why this is necessary
6564
*
66-
* @returns import or export clause or undefined if it entire declaration should be elided
65+
* @returns Import or export clause or undefined if it entire declaration should be elided
6766
*/
6867
export function elideImportOrExportDeclaration<T extends ImportOrExportDeclaration>(
6968
context: VisitorContext,
@@ -208,10 +207,7 @@ export function elideImportOrExportDeclaration(
208207
return !node.isTypeOnly && shouldEmitAliasDeclaration(node) ? node : undefined;
209208
}
210209

211-
/**
212-
* Visits named exports, eliding it if it does not contain an export specifier that
213-
* resolves to a value.
214-
*/
210+
/** Visits named exports, eliding it if it does not contain an export specifier that resolves to a value. */
215211
function visitNamedExports(node: NamedExports, allowEmpty: boolean): VisitResult<NamedExports> | undefined {
216212
// Elide the named exports if all of its export specifiers were elided.
217213
const elements = visitNodes(node.elements, <Visitor>visitExportSpecifier, isExportSpecifier);

src/utils/resolve-module-name.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,11 @@ import { getRelativePath } from "./get-relative-path";
1010
/* ****************************************************************************************************************** */
1111

1212
export interface ResolvedModule {
13-
/**
14-
* Absolute path to resolved module
15-
*/
13+
/** Absolute path to resolved module */
1614
resolvedPath: string | undefined;
17-
/**
18-
* Output path
19-
*/
15+
/** Output path */
2016
outputPath: string;
21-
/**
22-
* Resolved to URL
23-
*/
17+
/** Resolved to URL */
2418
isURL: boolean;
2519
}
2620

@@ -117,9 +111,7 @@ function getResolvedSourceFile(context: VisitorContext, fileName: string): Sourc
117111
// region: Utils
118112
/* ****************************************************************************************************************** */
119113

120-
/**
121-
* Resolve a module name
122-
*/
114+
/** Resolve a module name */
123115
export function resolveModuleName(context: VisitorContext, moduleName: string): ResolvedModule | undefined {
124116
const { tsInstance, compilerOptions, sourceFile, config, rootDirs } = context;
125117

src/utils/resolve-path-update-node.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import { resolveModuleName } from "./resolve-module-name";
88
// region: Node Updater Utility
99
/* ****************************************************************************************************************** */
1010

11-
/**
12-
* Gets proper path and calls updaterFn to get the new node if it should be updated
13-
*/
11+
/** Gets proper path and calls updaterFn to get the new node if it should be updated */
1412
export function resolvePathAndUpdateNode(
1513
context: VisitorContext,
1614
node: ts.Node,

src/utils/ts-helpers.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import type { REGISTER_INSTANCE } from "ts-node";
77
// region: TS Helpers
88
/* ****************************************************************************************************************** */
99

10-
/**
11-
* Determine output file path for source file
12-
*/
10+
/** Determine output file path for source file */
1311
export function getOutputDirForSourceFile(context: VisitorContext, sourceFile: SourceFile): string {
1412
const {
1513
tsInstance,
@@ -45,9 +43,7 @@ export function getOutputDirForSourceFile(context: VisitorContext, sourceFile: S
4543
return tsInstance.normalizePath(res);
4644
}
4745

48-
/**
49-
* Determine if moduleName matches config in paths
50-
*/
46+
/** Determine if moduleName matches config in paths */
5147
export function isModulePathsMatch(context: VisitorContext, moduleName: string): boolean {
5248
const {
5349
pathsPatterns,
@@ -56,9 +52,7 @@ export function isModulePathsMatch(context: VisitorContext, moduleName: string):
5652
return !!(pathsPatterns && matchPatternOrExact(pathsPatterns as readonly string[], moduleName));
5753
}
5854

59-
/**
60-
* Create barebones EmitHost (for no-Program transform)
61-
*/
55+
/** Create barebones EmitHost (for no-Program transform) */
6256
export function createSyntheticEmitHost(
6357
compilerOptions: ts.CompilerOptions,
6458
tsInstance: typeof ts,
@@ -77,9 +71,7 @@ export function createSyntheticEmitHost(
7771
} as unknown as ts.EmitHost;
7872
}
7973

80-
/**
81-
* Get ts-node register info
82-
*/
74+
/** Get ts-node register info */
8375
export function getTsNodeRegistrationProperties(tsInstance: typeof ts) {
8476
let tsNodeSymbol: typeof REGISTER_INSTANCE;
8577
try {

0 commit comments

Comments
 (0)