tsfmt 0.2.3 → 0.2.4

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.
Files changed (53) hide show
  1. package/dist/build-plugins/index.d.ts +1 -0
  2. package/dist/build-plugins/transformGenericsPlugin.d.ts +4 -0
  3. package/dist/cli.d.ts +1 -0
  4. package/dist/core/ast/ASTAnalyzer.d.ts +16 -0
  5. package/dist/core/ast/ASTTransformer.d.ts +9 -0
  6. package/dist/core/ast/DependencyResolver.d.ts +16 -0
  7. package/dist/core/ast/index.d.ts +3 -0
  8. package/dist/core/config/ConfigDefaults.d.ts +82 -0
  9. package/dist/core/config/ConfigLoader.d.ts +20 -0
  10. package/dist/core/config/ConfigMerger.d.ts +6 -0
  11. package/dist/core/config/ConfigTypes.d.ts +97 -0
  12. package/dist/core/config/ConfigValidator.d.ts +10 -0
  13. package/dist/core/config/index.d.ts +5 -0
  14. package/dist/core/di/Container.d.ts +17 -0
  15. package/dist/core/di/ServiceRegistration.d.ts +5 -0
  16. package/dist/core/di/index.d.ts +2 -0
  17. package/dist/core/formatters/BaseFormattingRule.d.ts +16 -0
  18. package/dist/core/formatters/IFormattingRule.d.ts +4 -0
  19. package/dist/core/formatters/index.d.ts +3 -0
  20. package/dist/core/formatters/rules/ast/ClassMemberSortingRule.d.ts +34 -0
  21. package/dist/core/formatters/rules/ast/FileDeclarationSortingRule.d.ts +33 -0
  22. package/dist/core/formatters/rules/ast/index.d.ts +2 -0
  23. package/dist/core/formatters/rules/imports/ImportOrganizationRule.d.ts +15 -0
  24. package/dist/core/formatters/rules/imports/index.d.ts +1 -0
  25. package/dist/core/formatters/rules/index-generation/IndexGenerationRule.d.ts +26 -0
  26. package/dist/core/formatters/rules/index-generation/index.d.ts +1 -0
  27. package/dist/core/formatters/rules/index.d.ts +5 -0
  28. package/dist/core/formatters/rules/spacing/BlankLineBeforeReturnsRule.d.ts +5 -0
  29. package/dist/core/formatters/rules/spacing/BlankLineBetweenDeclarationsRule.d.ts +6 -0
  30. package/dist/core/formatters/rules/spacing/BlankLineBetweenStatementTypesRule.d.ts +6 -0
  31. package/dist/core/formatters/rules/spacing/BlockSpacingRule.d.ts +5 -0
  32. package/dist/core/formatters/rules/spacing/BracketSpacingRule.d.ts +5 -0
  33. package/dist/core/formatters/rules/spacing/index.d.ts +5 -0
  34. package/dist/core/formatters/rules/style/DocBlockCommentRule.d.ts +5 -0
  35. package/dist/core/formatters/rules/style/IndentationRule.d.ts +5 -0
  36. package/dist/core/formatters/rules/style/QuoteStyleRule.d.ts +5 -0
  37. package/dist/core/formatters/rules/style/SemicolonRule.d.ts +5 -0
  38. package/dist/core/formatters/rules/style/StructuralIndentationRule.d.ts +11 -0
  39. package/dist/core/formatters/rules/style/index.d.ts +5 -0
  40. package/dist/core/index.d.ts +5 -0
  41. package/dist/core/pipeline/FormatterPipeline.d.ts +42 -0
  42. package/dist/core/pipeline/index.d.ts +1 -0
  43. package/dist/formatters/index.d.ts +1 -0
  44. package/dist/formatters/package.d.ts +1 -0
  45. package/dist/index.d.ts +5 -0
  46. package/dist/index.js +2 -0
  47. package/dist/shared/index.d.ts +1 -0
  48. package/dist/shared/types.d.ts +7 -0
  49. package/dist/sortPackage.d.ts +3 -0
  50. package/dist/sortTSConfig.d.ts +3 -0
  51. package/dist/tsfmt.d.ts +2 -0
  52. package/dist/tsfmt.js +9 -0
  53. package/package.json +10 -3
@@ -0,0 +1 @@
1
+ export * from "./transformGenericsPlugin";
@@ -0,0 +1,4 @@
1
+ export declare function transformGenericsPlugin(): {
2
+ name: string;
3
+ generateBundle(options: any, bundle: any): void;
4
+ };
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ import "reflect-metadata";
@@ -0,0 +1,16 @@
1
+ import * as ts from "typescript";
2
+ export interface ReferenceInfo {
3
+ identifiers: Set<string>;
4
+ thisReferences: Set<string>;
5
+ directCalls: Set<string>;
6
+ }
7
+ export declare class ASTAnalyzer {
8
+ static extractReferences(node: ts.Node, scopeFilter?: (name: string) => boolean): ReferenceInfo;
9
+ static extractClassMemberReferences(member: ts.ClassElement, availableMembers: Set<string>): Set<string>;
10
+ static extractFileDeclarationReferences(declaration: ts.Statement, availableDeclarations: Set<string>): Set<string>;
11
+ static getClassMemberName(member: ts.ClassElement): string;
12
+ static getDeclarationName(declaration: ts.Statement): string;
13
+ static hasModifier(node: ts.Node, kind: ts.SyntaxKind): boolean;
14
+ static isDefaultExport(node: ts.Statement): boolean;
15
+ static isExported(node: ts.Statement): boolean;
16
+ }
@@ -0,0 +1,9 @@
1
+ import * as ts from "typescript";
2
+ export declare class ASTTransformer {
3
+ static createSourceFile(source: string, filePath: string): ts.SourceFile;
4
+ static printNode(node: ts.Node, sourceFile: ts.SourceFile, removeComments?: boolean): string;
5
+ static printSourceFile(sourceFile: ts.SourceFile): string;
6
+ static reorderClassMembers(classNode: ts.ClassDeclaration, orderedMembers: ts.ClassElement[]): ts.ClassDeclaration;
7
+ static reorderSourceFileStatements(sourceFile: ts.SourceFile, orderedStatements: ts.Statement[]): ts.SourceFile;
8
+ static transformSourceFile(sourceFile: ts.SourceFile, visitor: (node: ts.Node) => ts.Node | undefined): ts.SourceFile;
9
+ }
@@ -0,0 +1,16 @@
1
+ export interface DependencyNode {
2
+ name: string;
3
+ dependencies: Set<string>;
4
+ originalIndex: number;
5
+ sortedIndex: number;
6
+ }
7
+ export interface DependencyGraph {
8
+ nodes: Map<string, DependencyNode>;
9
+ circularGroups: Set<string>[];
10
+ }
11
+ export declare class DependencyResolver {
12
+ private static findStronglyConnectedComponents;
13
+ static buildGraph<T>(items: T[], getName: (item: T) => string, getDependencies: (item: T) => Set<string>): DependencyGraph;
14
+ static topologicalSort(graph: DependencyGraph, sortedNames: string[]): string[];
15
+ static reorderWithDependencies<T>(items: T[], getName: (item: T) => string): T[];
16
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./ASTAnalyzer";
2
+ export * from "./ASTTransformer";
3
+ export * from "./DependencyResolver";
@@ -0,0 +1,82 @@
1
+ import { CoreConfig, FormatterOrder } from "./ConfigTypes";
2
+ export declare class ConfigDefaults {
3
+ static readonly DEFAULT_EXCLUDE_PATTERNS: readonly ["node_modules/**", "dist/**", "vendor/**", "bin/**"];
4
+ static readonly DEFAULT_INDEX_DIRECTORIES: readonly ["src/", "packages/"];
5
+ static readonly DEFAULT_JS_INCLUDE_PATTERNS: readonly ["**/*.{js,ts,jsx,tsx}"];
6
+ static readonly DEFAULT_TS_INCLUDE_PATTERNS: readonly ["**/*.{ts,tsx}"];
7
+ static getDefaultCodeStyleConfig(): {
8
+ enabled: boolean;
9
+ quoteStyle: "double";
10
+ semicolons: "always";
11
+ bracketSpacing: boolean;
12
+ indentStyle: "space";
13
+ indentWidth: number;
14
+ lineWidth: number;
15
+ trailingCommas: "all";
16
+ arrowParens: "avoid";
17
+ };
18
+ static getDefaultIndexDirectories(): string[];
19
+ static getDefaultIndexGenerationConfig(): {
20
+ enabled: boolean;
21
+ directories: string[];
22
+ options: {
23
+ fileExtension: string;
24
+ indexFileName: string;
25
+ recursive: boolean;
26
+ };
27
+ updateMainIndex: boolean;
28
+ };
29
+ static getDefaultImportConfig(): {
30
+ enabled: boolean;
31
+ sortImports: boolean;
32
+ removeUnused: boolean;
33
+ removeSideEffects: boolean;
34
+ groupImports: boolean;
35
+ groupOrder: string[];
36
+ separateGroups: boolean;
37
+ };
38
+ static getDefaultIncludePatterns(): string[];
39
+ static getDefaultExcludePatterns(): string[];
40
+ static getDefaultSortingConfig(): {
41
+ enabled: boolean;
42
+ classMembers: {
43
+ enabled: boolean;
44
+ order: import("../").MemberType[];
45
+ groupByVisibility: boolean;
46
+ respectDependencies: boolean;
47
+ };
48
+ reactComponents: {
49
+ enabled: boolean;
50
+ order: import("../").MemberType[];
51
+ groupByVisibility: boolean;
52
+ respectDependencies: boolean;
53
+ };
54
+ fileDeclarations: {
55
+ enabled: boolean;
56
+ order: import("../").DeclarationType[];
57
+ respectDependencies: boolean;
58
+ };
59
+ include: string[];
60
+ exclude: string[];
61
+ };
62
+ static getDefaultSpacingConfig(): {
63
+ enabled: boolean;
64
+ betweenDeclarations: boolean;
65
+ beforeReturns: boolean;
66
+ betweenStatementTypes: boolean;
67
+ };
68
+ static getDefaultPackageJsonConfig(): {
69
+ enabled: boolean;
70
+ customSortOrder: string[] | undefined;
71
+ indentation: number;
72
+ };
73
+ static getDefaultTsConfigConfig(): {
74
+ enabled: boolean;
75
+ indentation: number;
76
+ };
77
+ static getDefaultFormatterOrder(): FormatterOrder[];
78
+ static getDefaultConfig(): CoreConfig;
79
+ static getDefaultJavaScriptIncludePatterns(): string[];
80
+ static getDisabledConfig(): CoreConfig;
81
+ static getMinimalConfig(): CoreConfig;
82
+ }
@@ -0,0 +1,20 @@
1
+ import { CoreConfig } from "./ConfigTypes";
2
+ export declare class ConfigLoader {
3
+ static readonly CONFIG_FILE_NAME = "tsfmt.config.ts";
4
+ private static configCache;
5
+ static clearCache(): void;
6
+ static getConfigFilePath(projectRoot?: string): string;
7
+ static createSampleConfig(projectRoot?: string, overwrite?: boolean): void;
8
+ static getCacheStats(): {
9
+ size: number;
10
+ keys: string[];
11
+ };
12
+ private static getFileModTime;
13
+ static hasConfigFile(projectRoot?: string): boolean;
14
+ private static transpileTypeScript;
15
+ private static loadTypeScriptConfig;
16
+ private static loadConfigWithCache;
17
+ static loadConfig(projectRoot?: string, validate?: boolean): CoreConfig;
18
+ static loadConfigWithoutValidation(projectRoot?: string): CoreConfig;
19
+ static reloadConfig(projectRoot?: string): CoreConfig;
20
+ }
@@ -0,0 +1,6 @@
1
+ import { CoreConfig } from "./ConfigTypes";
2
+ export declare class ConfigMerger {
3
+ private static deepMerge;
4
+ static merge(userConfig: Partial<CoreConfig>): CoreConfig;
5
+ static mergeMultiple(...configs: Partial<CoreConfig>[]): CoreConfig;
6
+ }
@@ -0,0 +1,97 @@
1
+ import { MemberType } from "../";
2
+ import { DeclarationType } from "../";
3
+ import { IndexGenerationConfig } from "../";
4
+ export interface ClassMemberConfig {
5
+ enabled?: boolean;
6
+ order?: MemberType[];
7
+ groupByVisibility?: boolean;
8
+ respectDependencies?: boolean;
9
+ }
10
+ export interface CodeStyleConfig {
11
+ enabled?: boolean;
12
+ quoteStyle?: "single" | "double";
13
+ semicolons?: "always" | "never";
14
+ bracketSpacing?: boolean;
15
+ indentStyle?: "tab" | "space";
16
+ indentWidth?: number;
17
+ lineWidth?: number;
18
+ trailingCommas?: "none" | "es5" | "all";
19
+ arrowParens?: "always" | "avoid";
20
+ }
21
+ export interface ImportConfig {
22
+ enabled?: boolean;
23
+ sortImports?: boolean;
24
+ removeUnused?: boolean;
25
+ removeSideEffects?: boolean;
26
+ groupImports?: boolean;
27
+ groupOrder?: string[];
28
+ separateGroups?: boolean;
29
+ }
30
+ export interface ReactComponentConfig {
31
+ enabled?: boolean;
32
+ order?: MemberType[];
33
+ groupByVisibility?: boolean;
34
+ respectDependencies?: boolean;
35
+ }
36
+ export interface FileDeclarationConfig {
37
+ enabled?: boolean;
38
+ order?: DeclarationType[];
39
+ respectDependencies?: boolean;
40
+ }
41
+ export interface SortingConfig {
42
+ enabled?: boolean;
43
+ classMembers?: ClassMemberConfig;
44
+ reactComponents?: ReactComponentConfig;
45
+ fileDeclarations?: FileDeclarationConfig;
46
+ include?: string[];
47
+ exclude?: string[];
48
+ }
49
+ export interface SpacingConfig {
50
+ enabled?: boolean;
51
+ betweenDeclarations?: boolean;
52
+ beforeReturns?: boolean;
53
+ betweenStatementTypes?: boolean;
54
+ }
55
+ export interface PackageJsonConfig {
56
+ enabled?: boolean;
57
+ customSortOrder?: string[];
58
+ indentation?: number;
59
+ }
60
+ export interface TsConfigConfig {
61
+ enabled?: boolean;
62
+ indentation?: number;
63
+ }
64
+ export declare enum FormatterOrder {
65
+ IndexGeneration = "IndexGeneration",
66
+ CodeStyle = "CodeStyle",
67
+ ImportOrganization = "ImportOrganization",
68
+ ASTTransformation = "ASTTransformation",
69
+ Spacing = "Spacing"
70
+ }
71
+ export interface CoreConfig {
72
+ indexGeneration?: IndexGenerationConfig;
73
+ codeStyle?: CodeStyleConfig;
74
+ imports?: ImportConfig;
75
+ sorting?: SortingConfig;
76
+ spacing?: SpacingConfig;
77
+ packageJson?: PackageJsonConfig;
78
+ tsConfig?: TsConfigConfig;
79
+ formatterOrder?: FormatterOrder[];
80
+ skipReactFiles?: boolean;
81
+ }
82
+ export declare class ConfigTypes {
83
+ static getArrowParenOptions(): Array<"always" | "avoid">;
84
+ static getFormatterOrderOptions(): FormatterOrder[];
85
+ static getImportGroupOptions(): string[];
86
+ static getIndentStyleOptions(): Array<"tab" | "space">;
87
+ static getQuoteStyleOptions(): Array<"single" | "double">;
88
+ static getSemicolonOptions(): Array<"always" | "never">;
89
+ static getTrailingCommaOptions(): Array<"none" | "es5" | "all">;
90
+ static isRecommendedLineWidth(width: number): boolean;
91
+ static isValidArrowParenOption(option: string): option is "always" | "avoid";
92
+ static isValidIndentStyle(style: string): style is "tab" | "space";
93
+ static isValidIndentWidth(width: number): boolean;
94
+ static isValidQuoteStyle(style: string): style is "single" | "double";
95
+ static isValidSemicolonOption(option: string): option is "always" | "never";
96
+ static isValidTrailingCommaOption(option: string): option is "none" | "es5" | "all";
97
+ }
@@ -0,0 +1,10 @@
1
+ import { CoreConfig } from "./ConfigTypes";
2
+ export interface ValidationResult {
3
+ valid: boolean;
4
+ errors: string[];
5
+ warnings: string[];
6
+ }
7
+ export declare class ConfigValidator {
8
+ static validate(config: CoreConfig): ValidationResult;
9
+ static validateOrThrow(config: CoreConfig): void;
10
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./ConfigDefaults";
2
+ export * from "./ConfigLoader";
3
+ export * from "./ConfigMerger";
4
+ export * from "./ConfigTypes";
5
+ export * from "./ConfigValidator";
@@ -0,0 +1,17 @@
1
+ import "reflect-metadata";
2
+ export declare class Container {
3
+ private factories;
4
+ private services;
5
+ private singletons;
6
+ static inject(...dependencies: string[]): (target: any) => any;
7
+ clear(): void;
8
+ private extractGenericTypeName;
9
+ private extractGenericTypeNameForRegistration;
10
+ has(name: string): boolean;
11
+ private isConstructorFunction;
12
+ register<T>(name: string, instance: T): void;
13
+ private resolveByKey;
14
+ resolve<T>(name?: string): T;
15
+ private resolveDependencies;
16
+ singleton<T>(nameOrInstanceOrConstructor: string | T | (() => T) | (new (...args: any[]) => T), instance?: T | (() => T)): void;
17
+ }
@@ -0,0 +1,5 @@
1
+ import { CoreConfig } from "../config";
2
+ import { Container } from "./Container";
3
+ export declare class ServiceRegistration {
4
+ static registerServices(container: Container, config: CoreConfig): void;
5
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./Container";
2
+ export * from "./ServiceRegistration";
@@ -0,0 +1,16 @@
1
+ import { CoreConfig } from "../config";
2
+ import { Container } from "../di";
3
+ import { IFormattingRule } from "./IFormattingRule";
4
+ export declare abstract class BaseFormattingRule implements IFormattingRule {
5
+ protected readonly container: Container;
6
+ protected readonly config: CoreConfig;
7
+ abstract readonly name: string;
8
+ constructor(container: Container, config?: CoreConfig);
9
+ abstract apply(source: string, filePath?: string): string;
10
+ protected getConfig(): CoreConfig;
11
+ protected getCodeStyleConfig(): import("../config").CodeStyleConfig | undefined;
12
+ protected getImportsConfig(): import("../config").ImportConfig | undefined;
13
+ protected getIndexGenerationConfig(): import("./rules").IndexGenerationConfig | undefined;
14
+ protected getSortingConfig(): import("../config").SortingConfig | undefined;
15
+ protected getSpacingConfig(): import("../config").SpacingConfig | undefined;
16
+ }
@@ -0,0 +1,4 @@
1
+ export interface IFormattingRule {
2
+ readonly name: string;
3
+ apply(source: string, filePath?: string): string;
4
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./BaseFormattingRule";
2
+ export * from "./IFormattingRule";
3
+ export * from "./rules";
@@ -0,0 +1,34 @@
1
+ import * as ts from "typescript";
2
+ import { BaseFormattingRule } from "../../BaseFormattingRule";
3
+ export declare enum MemberType {
4
+ StaticProperty = "static_property",
5
+ InstanceProperty = "instance_property",
6
+ Constructor = "constructor",
7
+ StaticMethod = "static_method",
8
+ InstanceMethod = "instance_method",
9
+ GetAccessor = "get_accessor",
10
+ SetAccessor = "set_accessor"
11
+ }
12
+ export interface ClassMember {
13
+ node: ts.ClassElement;
14
+ type: MemberType;
15
+ name: string;
16
+ isPublic: boolean;
17
+ isProtected: boolean;
18
+ isPrivate: boolean;
19
+ isStatic: boolean;
20
+ hasDecorator: boolean;
21
+ text: string;
22
+ dependencies?: Set<string>;
23
+ originalIndex?: number;
24
+ }
25
+ export declare const DEFAULT_CLASS_ORDER: MemberType[];
26
+ export declare class ClassMemberSortingRule extends BaseFormattingRule {
27
+ readonly name = "ClassMemberSortingRule";
28
+ private getMemberType;
29
+ private analyzeClassMember;
30
+ private createSourceFile;
31
+ private compareMembers;
32
+ private sortClassMembers;
33
+ apply(source: string, filePath?: string): string;
34
+ }
@@ -0,0 +1,33 @@
1
+ import * as ts from "typescript";
2
+ import { BaseFormattingRule } from "../../BaseFormattingRule";
3
+ export declare enum DeclarationType {
4
+ Interface = "interface",
5
+ TypeAlias = "type_alias",
6
+ Enum = "enum",
7
+ HelperFunction = "helper_function",
8
+ HelperVariable = "helper_variable",
9
+ ExportedFunction = "exported_function",
10
+ ExportedVariable = "exported_variable",
11
+ ExportedClass = "exported_class",
12
+ DefaultExport = "default_export",
13
+ Other = "other"
14
+ }
15
+ export interface FileDeclaration {
16
+ node: ts.Statement;
17
+ type: DeclarationType;
18
+ name: string;
19
+ isExported: boolean;
20
+ isDefaultExport: boolean;
21
+ text: string;
22
+ dependencies?: Set<string>;
23
+ originalIndex?: number;
24
+ }
25
+ export declare const DEFAULT_FILE_ORDER: DeclarationType[];
26
+ export declare class FileDeclarationSortingRule extends BaseFormattingRule {
27
+ readonly name = "FileDeclarationSortingRule";
28
+ private getDeclarationType;
29
+ private analyzeDeclaration;
30
+ private createSourceFile;
31
+ private sortFileDeclarations;
32
+ apply(source: string, filePath?: string): string;
33
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./ClassMemberSortingRule";
2
+ export * from "./FileDeclarationSortingRule";
@@ -0,0 +1,15 @@
1
+ import { BaseFormattingRule } from "../../BaseFormattingRule";
2
+ export declare class ImportOrganizationRule extends BaseFormattingRule {
3
+ readonly name = "ImportOrganizationRule";
4
+ private createSourceFile;
5
+ private determineImportGroup;
6
+ private extractImports;
7
+ private getImportedIdentifiers;
8
+ private isIdentifierUsed;
9
+ private isImportUsed;
10
+ private filterUnusedImports;
11
+ private sortImports;
12
+ private groupImports;
13
+ private reconstructSource;
14
+ apply(source: string, filePath?: string): string;
15
+ }
@@ -0,0 +1 @@
1
+ export * from "./ImportOrganizationRule";
@@ -0,0 +1,26 @@
1
+ import { BaseFormattingRule } from "../../BaseFormattingRule";
2
+ export interface IndexGenerationOptions {
3
+ fileExtension: string;
4
+ indexFileName: string;
5
+ recursive: boolean;
6
+ }
7
+ export interface IndexGenerationConfig {
8
+ enabled?: boolean;
9
+ directories?: string[];
10
+ options?: Partial<IndexGenerationOptions>;
11
+ updateMainIndex?: boolean;
12
+ }
13
+ export declare class IndexGenerationRule extends BaseFormattingRule {
14
+ private readonly defaultOptions;
15
+ readonly name = "IndexGenerationRule";
16
+ private findProjectRoot;
17
+ private isTestDirectory;
18
+ private isTestFile;
19
+ private generateSingleDirectoryIndex;
20
+ private generateIndexExportRecursive;
21
+ private generateIndexExport;
22
+ private discoverExportableModules;
23
+ private updateMainIndex;
24
+ private generateIndexFiles;
25
+ apply(source: string, filePath?: string): string;
26
+ }
@@ -0,0 +1 @@
1
+ export * from "./IndexGenerationRule";
@@ -0,0 +1,5 @@
1
+ export * from "./ast";
2
+ export * from "./imports";
3
+ export * from "./index-generation";
4
+ export * from "./spacing";
5
+ export * from "./style";
@@ -0,0 +1,5 @@
1
+ import { BaseFormattingRule } from "../../BaseFormattingRule";
2
+ export declare class BlankLineBeforeReturnsRule extends BaseFormattingRule {
3
+ readonly name = "BlankLineBeforeReturnsRule";
4
+ apply(source: string, filePath?: string): string;
5
+ }
@@ -0,0 +1,6 @@
1
+ import { BaseFormattingRule } from "../../BaseFormattingRule";
2
+ export declare class BlankLineBetweenDeclarationsRule extends BaseFormattingRule {
3
+ readonly name = "BlankLineBetweenDeclarationsRule";
4
+ private getDeclarationKeyword;
5
+ apply(source: string, filePath?: string): string;
6
+ }
@@ -0,0 +1,6 @@
1
+ import { BaseFormattingRule } from "../../BaseFormattingRule";
2
+ export declare class BlankLineBetweenStatementTypesRule extends BaseFormattingRule {
3
+ readonly name = "BlankLineBetweenStatementTypesRule";
4
+ private getStatementType;
5
+ apply(source: string, filePath?: string): string;
6
+ }
@@ -0,0 +1,5 @@
1
+ import { BaseFormattingRule } from "../../BaseFormattingRule";
2
+ export declare class BlockSpacingRule extends BaseFormattingRule {
3
+ readonly name = "BlockSpacingRule";
4
+ apply(source: string, filePath?: string): string;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { BaseFormattingRule } from "../../BaseFormattingRule";
2
+ export declare class BracketSpacingRule extends BaseFormattingRule {
3
+ readonly name = "BracketSpacingRule";
4
+ apply(source: string, filePath?: string): string;
5
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./BlankLineBeforeReturnsRule";
2
+ export * from "./BlankLineBetweenDeclarationsRule";
3
+ export * from "./BlankLineBetweenStatementTypesRule";
4
+ export * from "./BlockSpacingRule";
5
+ export * from "./BracketSpacingRule";
@@ -0,0 +1,5 @@
1
+ import { BaseFormattingRule } from "../../BaseFormattingRule";
2
+ export declare class DocBlockCommentRule extends BaseFormattingRule {
3
+ readonly name = "DocBlockCommentRule";
4
+ apply(source: string, filePath?: string): string;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { BaseFormattingRule } from "../../BaseFormattingRule";
2
+ export declare class IndentationRule extends BaseFormattingRule {
3
+ readonly name = "IndentationRule";
4
+ apply(source: string, filePath?: string): string;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { BaseFormattingRule } from "../../BaseFormattingRule";
2
+ export declare class QuoteStyleRule extends BaseFormattingRule {
3
+ readonly name = "QuoteStyleRule";
4
+ apply(source: string, filePath?: string): string;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { BaseFormattingRule } from "../../BaseFormattingRule";
2
+ export declare class SemicolonRule extends BaseFormattingRule {
3
+ readonly name = "SemicolonRule";
4
+ apply(source: string, filePath?: string): string;
5
+ }
@@ -0,0 +1,11 @@
1
+ import { BaseFormattingRule } from "../../BaseFormattingRule";
2
+ export declare class StructuralIndentationRule extends BaseFormattingRule {
3
+ readonly name = "StructuralIndentationRule";
4
+ private skipString;
5
+ private isRegexStart;
6
+ private skipRegex;
7
+ private getLineIndentLevel;
8
+ private startsWithClosingBracket;
9
+ private findBracketFixes;
10
+ apply(source: string, filePath?: string): string;
11
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./DocBlockCommentRule";
2
+ export * from "./IndentationRule";
3
+ export * from "./QuoteStyleRule";
4
+ export * from "./SemicolonRule";
5
+ export * from "./StructuralIndentationRule";
@@ -0,0 +1,5 @@
1
+ export * from "./ast";
2
+ export * from "./config";
3
+ export * from "./di";
4
+ export * from "./formatters";
5
+ export * from "./pipeline";
@@ -0,0 +1,42 @@
1
+ import { CoreConfig, FormatterOrder } from "../config";
2
+ import { Container } from "../di";
3
+ import { IFormattingRule } from "../formatters";
4
+ export interface FormatterExecution {
5
+ formatterName: string;
6
+ order: FormatterOrder;
7
+ changed: boolean;
8
+ error?: Error;
9
+ }
10
+ export interface PipelineContext {
11
+ filePath: string;
12
+ originalSource: string;
13
+ currentSource: string;
14
+ executions: FormatterExecution[];
15
+ changed: boolean;
16
+ dryRun: boolean;
17
+ }
18
+ export declare class FormatterError extends Error {
19
+ readonly formatterName: string;
20
+ readonly filePath: string;
21
+ readonly originalError: Error;
22
+ constructor(formatterName: string, filePath: string, originalError: Error);
23
+ }
24
+ export declare class FormatterPipeline {
25
+ private readonly config;
26
+ private readonly container;
27
+ private formatterOrder;
28
+ private rules;
29
+ constructor(config: CoreConfig, container: Container);
30
+ private extractTypeNameFromStack;
31
+ private addRule;
32
+ private addRuleByName;
33
+ private getFilesRecursively;
34
+ private shouldIgnoreFile;
35
+ formatFile(filePath: string, dryRun?: boolean): Promise<PipelineContext>;
36
+ formatFiles(filePaths: string[], dryRun?: boolean): Promise<PipelineContext[]>;
37
+ formatDirectory(dirPath: string, dryRun?: boolean, extensions?: string[]): Promise<PipelineContext[]>;
38
+ getFormatterOrder(): FormatterOrder[];
39
+ getRulesAtOrder(order: FormatterOrder): IFormattingRule[];
40
+ hasRules(): boolean;
41
+ private initializeRules;
42
+ }
@@ -0,0 +1 @@
1
+ export * from "./FormatterPipeline";
@@ -0,0 +1 @@
1
+ export * from "./package";
@@ -0,0 +1 @@
1
+ export declare function sortExportsKeys(exports: Record<string, any>): Record<string, any>;
@@ -0,0 +1,5 @@
1
+ export * from "./build-plugins";
2
+ export * from "./core";
3
+ export * from "./formatters";
4
+ export * from "./shared";
5
+ export { tsfmt } from "./tsfmt";
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ const StructuralIndentationRule = require("./core/formatters/rules/style/Structu
29
29
  const FormatterPipeline = require("./core/pipeline/FormatterPipeline.js");
30
30
  const _package = require("./formatters/package.js");
31
31
  const types = require("./shared/types.js");
32
+ const tsfmt = require("./tsfmt.js");
32
33
  exports.transformGenericsPlugin = transformGenericsPlugin.transformGenericsPlugin;
33
34
  exports.ASTAnalyzer = ASTAnalyzer.ASTAnalyzer;
34
35
  exports.ASTTransformer = ASTTransformer.ASTTransformer;
@@ -64,3 +65,4 @@ exports.FormatterError = FormatterPipeline.FormatterError;
64
65
  exports.FormatterPipeline = FormatterPipeline.FormatterPipeline;
65
66
  exports.sortExportsKeys = _package.sortExportsKeys;
66
67
  exports.DefaultSortOptions = types.DefaultSortOptions;
68
+ exports.tsfmt = tsfmt.tsfmt;
@@ -0,0 +1 @@
1
+ export * from "./types";
@@ -0,0 +1,7 @@
1
+ export interface SortOptions {
2
+ customSortOrder?: string[];
3
+ indentation?: number;
4
+ filePath?: string;
5
+ dryRun?: boolean;
6
+ }
7
+ export declare const DefaultSortOptions: SortOptions;
@@ -0,0 +1,3 @@
1
+ import { SortOptions } from "./shared";
2
+ export declare function sortPackageJson(packageObj: Record<string, any>, options?: SortOptions): Record<string, any>;
3
+ export declare function sortPackageFile(filePath?: string, options?: SortOptions): Record<string, any>;
@@ -0,0 +1,3 @@
1
+ import { SortOptions } from "./shared/types";
2
+ export declare function sortTsConfig(tsConfig: Record<string, any>): Record<string, any>;
3
+ export declare function sortTsConfigFile(filePath?: string, options?: SortOptions): Record<string, any>;
@@ -0,0 +1,2 @@
1
+ import { CoreConfig } from "./core/config";
2
+ export declare function tsfmt(config?: Partial<CoreConfig>): CoreConfig;
package/dist/tsfmt.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ require("./core/config/ConfigDefaults.js");
4
+ require("./core/config/ConfigLoader.js");
5
+ const ConfigMerger = require("./core/config/ConfigMerger.js");
6
+ function tsfmt(config = {}) {
7
+ return ConfigMerger.ConfigMerger.merge(config);
8
+ }
9
+ exports.tsfmt = tsfmt;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tsfmt",
3
3
  "author": "Encore Digital Group",
4
- "version": "0.2.3",
4
+ "version": "0.2.4",
5
5
  "description": "An opinionated TypeScript code formatter",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -25,12 +25,19 @@
25
25
  "vite": "^7.0.0"
26
26
  },
27
27
  "scripts": {
28
- "build": "vite build",
28
+ "build": "vite build && tsc --emitDeclarationOnly --declarationDir dist",
29
29
  "dev": "tsx src/cli.ts",
30
30
  "format": "node dist/cli.js",
31
31
  "test": "jest"
32
32
  },
33
- "main": "dist/cli.js",
33
+ "types": "dist/index.d.ts",
34
+ "main": "dist/index.js",
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "require": "./dist/index.js"
39
+ }
40
+ },
34
41
  "files": [
35
42
  "dist",
36
43
  "README.md"