Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve type signature of cli plugin #13

Merged
merged 2 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/plugin/compiler-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ function isFilenameMatched(patterns: string[], filename: string): boolean {
export const before: (
options: Record<string, any> | undefined,
program: ts.Program,
) => (ctx: ts.TransformationContext) => ts.Transformer<any> = (
) => ts.TransformerFactory<ts.SourceFile> | ts.CustomTransformerFactory = (
options,
program,
) => {
const mergedOption = mergePluginOptions(options);

return (ctx: ts.TransformationContext): ts.Transformer<any> => {
return (sf: ts.SourceFile) => {
return (ctx) => {
return (sourceFile) => {
if (
isFilenameMatched(
mergedOption.interfaceFilenameSuffix as string[],
sf.fileName,
sourceFile.fileName,
)
) {
return httpInterfaceVisitor.visit(sf, ctx, program);
return httpInterfaceVisitor.visit(sourceFile, ctx, program);
}

return sf;
return sourceFile;
};
};
};
4 changes: 2 additions & 2 deletions lib/plugin/visitors/http-interface.visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class HttpInterfaceVisitor {
sourceFile: ts.SourceFile,
ctx: ts.TransformationContext,
program: ts.Program,
): ts.Node {
): ts.SourceFile {
this.importSet.clear();
const factory = ctx.factory;
const typeChecker = program.getTypeChecker();
Expand All @@ -61,7 +61,7 @@ export class HttpInterfaceVisitor {
return ts.visitEachChild(node, visitNode, ctx);
};

return ts.visitNode(sourceFile, visitNode);
return ts.visitNode(sourceFile, visitNode) as ts.SourceFile;
}

private updateSourceFile(
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sonar.projectKey=r2don_nest-http-interface
sonar.organization=r2don
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.coverage.exclusions=**.spec.ts,plugin.js
sonar.coverage.exclusions=**.spec.ts,plugin.js,example/**/*
Loading