fcis 0.1.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.
Files changed (151) hide show
  1. package/.plans/001-fcis-analyzer.md +832 -0
  2. package/.plans/002-fcis-analyzer-improvements.md +205 -0
  3. package/README.md +272 -0
  4. package/TECHNICAL.md +386 -0
  5. package/dist/cli.d.ts +1 -0
  6. package/dist/cli.js +1836 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/index.d.ts +709 -0
  9. package/dist/index.js +1845 -0
  10. package/dist/index.js.map +1 -0
  11. package/package.json +47 -0
  12. package/pnpm-workspace.yaml +0 -0
  13. package/src/analyzer.ts +266 -0
  14. package/src/classification/classifier.ts +156 -0
  15. package/src/classification/derive-status.ts +171 -0
  16. package/src/classification/quality-scorer.ts +481 -0
  17. package/src/cli.ts +286 -0
  18. package/src/detection/detect-markers.ts +480 -0
  19. package/src/detection/markers.ts +332 -0
  20. package/src/extraction/extract-functions.ts +570 -0
  21. package/src/extraction/extractor.ts +188 -0
  22. package/src/index.ts +111 -0
  23. package/src/reporting/report-console.ts +416 -0
  24. package/src/reporting/report-json.ts +232 -0
  25. package/src/scoring/scorer.ts +504 -0
  26. package/src/types.ts +248 -0
  27. package/tests/classifier.test.ts +480 -0
  28. package/tests/derive-status.test.ts +464 -0
  29. package/tests/detect-markers.test.ts +639 -0
  30. package/tests/extractor.test.ts +155 -0
  31. package/tests/integration.test.ts +706 -0
  32. package/tests/quality-scorer.test.ts +650 -0
  33. package/tests/scorer.test.ts +768 -0
  34. package/tsconfig.json +34 -0
  35. package/tsup.config.ts +17 -0
  36. package/vendor/ts-morph/.editorconfig +10 -0
  37. package/vendor/ts-morph/.gitattributes +11 -0
  38. package/vendor/ts-morph/.github/CODE_OF_CONDUCT.md +77 -0
  39. package/vendor/ts-morph/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
  40. package/vendor/ts-morph/.github/ISSUE_TEMPLATE/custom.md +4 -0
  41. package/vendor/ts-morph/.github/ISSUE_TEMPLATE/feature_request.md +18 -0
  42. package/vendor/ts-morph/.github/workflows/ci.yml +50 -0
  43. package/vendor/ts-morph/.github/workflows/publish.yml +53 -0
  44. package/vendor/ts-morph/.vscode/settings.json +10 -0
  45. package/vendor/ts-morph/CONTRIBUTING.md +23 -0
  46. package/vendor/ts-morph/DEVELOPMENT.md +32 -0
  47. package/vendor/ts-morph/LICENSE +21 -0
  48. package/vendor/ts-morph/deno.json +8 -0
  49. package/vendor/ts-morph/deno.lock +1233 -0
  50. package/vendor/ts-morph/docs/CNAME +1 -0
  51. package/vendor/ts-morph/docs/Gemfile +2 -0
  52. package/vendor/ts-morph/docs/_config.yml +5 -0
  53. package/vendor/ts-morph/docs/_layouts/default.html +159 -0
  54. package/vendor/ts-morph/docs/_script-templates/main.ts +116 -0
  55. package/vendor/ts-morph/docs/assets/css/style.scss +212 -0
  56. package/vendor/ts-morph/docs/details/ambient.md +38 -0
  57. package/vendor/ts-morph/docs/details/async.md +31 -0
  58. package/vendor/ts-morph/docs/details/classes.md +314 -0
  59. package/vendor/ts-morph/docs/details/comment-ranges.md +7 -0
  60. package/vendor/ts-morph/docs/details/comments.md +122 -0
  61. package/vendor/ts-morph/docs/details/decorators.md +119 -0
  62. package/vendor/ts-morph/docs/details/documentation.md +73 -0
  63. package/vendor/ts-morph/docs/details/enums.md +117 -0
  64. package/vendor/ts-morph/docs/details/exports.md +308 -0
  65. package/vendor/ts-morph/docs/details/expressions.md +46 -0
  66. package/vendor/ts-morph/docs/details/functions.md +150 -0
  67. package/vendor/ts-morph/docs/details/generators.md +27 -0
  68. package/vendor/ts-morph/docs/details/identifiers.md +79 -0
  69. package/vendor/ts-morph/docs/details/imports.md +191 -0
  70. package/vendor/ts-morph/docs/details/index.md +52 -0
  71. package/vendor/ts-morph/docs/details/initializers.md +40 -0
  72. package/vendor/ts-morph/docs/details/interfaces.md +218 -0
  73. package/vendor/ts-morph/docs/details/literals.md +20 -0
  74. package/vendor/ts-morph/docs/details/modifiers.md +38 -0
  75. package/vendor/ts-morph/docs/details/modules.md +113 -0
  76. package/vendor/ts-morph/docs/details/namespaces.md +7 -0
  77. package/vendor/ts-morph/docs/details/object-literal-expressions.md +106 -0
  78. package/vendor/ts-morph/docs/details/parameters.md +64 -0
  79. package/vendor/ts-morph/docs/details/signatures.md +41 -0
  80. package/vendor/ts-morph/docs/details/source-files.md +292 -0
  81. package/vendor/ts-morph/docs/details/type-aliases.md +34 -0
  82. package/vendor/ts-morph/docs/details/type-parameters.md +72 -0
  83. package/vendor/ts-morph/docs/details/types.md +254 -0
  84. package/vendor/ts-morph/docs/details/variables.md +110 -0
  85. package/vendor/ts-morph/docs/emitting.md +151 -0
  86. package/vendor/ts-morph/docs/index.md +25 -0
  87. package/vendor/ts-morph/docs/manipulation/code-writer.md +20 -0
  88. package/vendor/ts-morph/docs/manipulation/formatting.md +76 -0
  89. package/vendor/ts-morph/docs/manipulation/index.md +136 -0
  90. package/vendor/ts-morph/docs/manipulation/order.md +14 -0
  91. package/vendor/ts-morph/docs/manipulation/performance.md +222 -0
  92. package/vendor/ts-morph/docs/manipulation/removing.md +31 -0
  93. package/vendor/ts-morph/docs/manipulation/renaming.md +106 -0
  94. package/vendor/ts-morph/docs/manipulation/settings.md +76 -0
  95. package/vendor/ts-morph/docs/manipulation/structures.md +117 -0
  96. package/vendor/ts-morph/docs/manipulation/transforms.md +84 -0
  97. package/vendor/ts-morph/docs/metrics/performance.json +4 -0
  98. package/vendor/ts-morph/docs/navigation/ambient-modules.md +22 -0
  99. package/vendor/ts-morph/docs/navigation/compiler-nodes.md +82 -0
  100. package/vendor/ts-morph/docs/navigation/directories.md +287 -0
  101. package/vendor/ts-morph/docs/navigation/example.md +50 -0
  102. package/vendor/ts-morph/docs/navigation/finding-references.md +53 -0
  103. package/vendor/ts-morph/docs/navigation/getting-source-files.md +59 -0
  104. package/vendor/ts-morph/docs/navigation/images/getChildrenVsForEachChild.gif +0 -0
  105. package/vendor/ts-morph/docs/navigation/index.md +94 -0
  106. package/vendor/ts-morph/docs/navigation/language-service.md +23 -0
  107. package/vendor/ts-morph/docs/navigation/program.md +25 -0
  108. package/vendor/ts-morph/docs/navigation/type-checker.md +33 -0
  109. package/vendor/ts-morph/docs/setup/adding-source-files.md +145 -0
  110. package/vendor/ts-morph/docs/setup/ast-viewers.md +46 -0
  111. package/vendor/ts-morph/docs/setup/diagnostics.md +109 -0
  112. package/vendor/ts-morph/docs/setup/file-system.md +106 -0
  113. package/vendor/ts-morph/docs/setup/images/atom-ast.png +0 -0
  114. package/vendor/ts-morph/docs/setup/images/atom-ast_small.png +0 -0
  115. package/vendor/ts-morph/docs/setup/images/atom-command-palette.png +0 -0
  116. package/vendor/ts-morph/docs/setup/images/atom-file.png +0 -0
  117. package/vendor/ts-morph/docs/setup/images/ts-ast-viewer.png +0 -0
  118. package/vendor/ts-morph/docs/setup/index.md +94 -0
  119. package/vendor/ts-morph/docs/utilities.md +55 -0
  120. package/vendor/ts-morph/dprint.json +23 -0
  121. package/vendor/ts-morph/package.json +30 -0
  122. package/vendor/ts-morph/packages/bootstrap/LICENSE +21 -0
  123. package/vendor/ts-morph/packages/bootstrap/lib/ts-morph-bootstrap.d.ts +397 -0
  124. package/vendor/ts-morph/packages/bootstrap/package.json +46 -0
  125. package/vendor/ts-morph/packages/bootstrap/readme.md +200 -0
  126. package/vendor/ts-morph/packages/common/LICENSE +21 -0
  127. package/vendor/ts-morph/packages/common/lib/ts-morph-common.d.ts +1082 -0
  128. package/vendor/ts-morph/packages/common/lib/typescript.d.ts +11439 -0
  129. package/vendor/ts-morph/packages/common/package.json +65 -0
  130. package/vendor/ts-morph/packages/common/readme.md +5 -0
  131. package/vendor/ts-morph/packages/scripts/changeTypeScriptVersion.ts +28 -0
  132. package/vendor/ts-morph/packages/scripts/createDeclarationProject.ts +47 -0
  133. package/vendor/ts-morph/packages/scripts/deps.ts +2 -0
  134. package/vendor/ts-morph/packages/scripts/execScript.ts +31 -0
  135. package/vendor/ts-morph/packages/scripts/folders.ts +11 -0
  136. package/vendor/ts-morph/packages/scripts/getDevCompilerVersions.ts +19 -0
  137. package/vendor/ts-morph/packages/scripts/mod.ts +7 -0
  138. package/vendor/ts-morph/packages/scripts/utils/Memoize.ts +36 -0
  139. package/vendor/ts-morph/packages/scripts/utils/forEachTypeText.ts +23 -0
  140. package/vendor/ts-morph/packages/scripts/utils/makeConstructorsPrivate.ts +26 -0
  141. package/vendor/ts-morph/packages/scripts/utils/mod.ts +4 -0
  142. package/vendor/ts-morph/packages/scripts/utils/printDiagnostics.ts +10 -0
  143. package/vendor/ts-morph/packages/ts-morph/LICENSE +21 -0
  144. package/vendor/ts-morph/packages/ts-morph/lib/ts-morph.d.ts +11198 -0
  145. package/vendor/ts-morph/packages/ts-morph/package.json +78 -0
  146. package/vendor/ts-morph/packages/ts-morph/readme.md +111 -0
  147. package/vendor/ts-morph/readme.md +14 -0
  148. package/vendor/ts-morph/rfcs/README.md +13 -0
  149. package/vendor/ts-morph/rfcs/RFC-0001 - Inserting Into Statements Handling Comments.md +181 -0
  150. package/vendor/ts-morph/tsconfig.common.json +17 -0
  151. package/vitest.config.ts +16 -0
@@ -0,0 +1,106 @@
1
+ ---
2
+ title: Object Literal Expressions
3
+ ---
4
+
5
+ ## Object Literal Expressions
6
+
7
+ Object literal expressions look like the [initializer](initializers) for this variable declaration:
8
+
9
+ ```ts
10
+ const obj = {
11
+ propertyAssignment: 5,
12
+ shorthandPropertyAssignment,
13
+ ...spreadAssignment,
14
+ get getAccessor() {
15
+ return 5;
16
+ },
17
+ set setAccessor(value: number) {
18
+ // do something
19
+ },
20
+ method() {
21
+ return "some string";
22
+ },
23
+ };
24
+ ```
25
+
26
+ ### Properties
27
+
28
+ Once you have retrieved the object literal expression, get it's properties via:
29
+
30
+ ```ts
31
+ const properties = objectLiteralExpression.getProperties();
32
+ // or
33
+ const property = objectLiteralExpression.getProperty("propertyAssignment");
34
+ // or
35
+ const spreadAssignment = objectLiteralExpression.getProperty(
36
+ p => p.getText() === "...spreadAssignment",
37
+ );
38
+ // or
39
+ const method = objectLiteralExpression.getPropertyOrThrow("method");
40
+ ```
41
+
42
+ ### Property Assignments
43
+
44
+ Add a property assignment via the `insertPropertyAssignment`, `insertPropertyAssignments`, `addPropertyAssignment`, or `addPropertyAssignments` methods.
45
+
46
+ ```ts
47
+ const propertyAssignment = objectLiteralExpression.addPropertyAssignment({
48
+ name: "propertyAssignment",
49
+ initializer: "5",
50
+ });
51
+ ```
52
+
53
+ ### Shorthand Property Assignments
54
+
55
+ Add a shorthand property assignment via the `insertShorthandPropertyAssignment`, `insertShorthandPropertyAssignments`,
56
+ `addShorthandPropertyAssignment`, or `addShorthandPropertyAssignments` methods.
57
+
58
+ ```ts
59
+ const shorthandPropertyAssignment = objectLiteralExpression.addShorthandPropertyAssignment({
60
+ name: "shorthandPropertyAssignment",
61
+ });
62
+ ```
63
+
64
+ ### Spread Assignments
65
+
66
+ Add a spread assignment via the `insertSpreadAssignment`, `insertSpreadAssignments`, `addSpreadAssignment`, or `addSpreadAssignments` methods.
67
+
68
+ ```ts
69
+ const spreadAssignment = objectLiteralExpression.addSpreadAssignment({ expression: "spreadAssignment" });
70
+ ```
71
+
72
+ ### Accessors
73
+
74
+ Add get and set accessors via the `insertGetAccessor`, `insertGetAccessors`, `addGetAccessor`, `addGetAccessors`, or similarly named methods for set accessors.
75
+
76
+ ```ts
77
+ const getAccessor = objectLiteralExpression.addGetAccessor({
78
+ name: "someNumber",
79
+ returnType: "number",
80
+ statements: ["return someNumber;"],
81
+ });
82
+ const setAccessor = objectLiteralExpression.addSetAccessor({
83
+ name: "someNumber",
84
+ parameters: [{ name: "value", type: "number" }],
85
+ statements: ["someNumber = value;"],
86
+ });
87
+ ```
88
+
89
+ ### Methods
90
+
91
+ Add a method via the `insertMethod`, `insertMethods`, `addMethod`, or `addMethods` methods.
92
+
93
+ ```ts
94
+ const method = objectLiteralExpression.addMethod({
95
+ name: "method",
96
+ statements: [`return "some string";`],
97
+ });
98
+ ```
99
+
100
+ ### Removing
101
+
102
+ Remove a member by calling `.remove()` on it.
103
+
104
+ ```ts setup: const obj: ObjectLiteralExpression;
105
+ obj.getPropertyOrThrow("prop1").remove();
106
+ ```
@@ -0,0 +1,64 @@
1
+ ---
2
+ title: Parameters
3
+ ---
4
+
5
+ ## Parameters
6
+
7
+ Parameters can be retreived from nodes by calling `getParameters()`:
8
+
9
+ ```ts
10
+ const parameters = functionDeclaration.getParameters();
11
+ ```
12
+
13
+ ### Inserting/Adding
14
+
15
+ Insert or add parameters by calling `insertParameter()`, `insertParameters()`, `addParameter()`, or `addParameters()`.
16
+
17
+ For example:
18
+
19
+ ```ts
20
+ const parameter = functionDeclaration.insertParameter(1, {
21
+ name: "param1",
22
+ type: "string",
23
+ });
24
+ ```
25
+
26
+ ### Removing
27
+
28
+ Remove a parameter by calling `.remove()` on it:
29
+
30
+ ```ts
31
+ parameter.remove();
32
+ ```
33
+
34
+ ### Rest parameter
35
+
36
+ Tell if a parameter is a rest parameter:
37
+
38
+ ```ts
39
+ const isRestParameter = parameter.isRestParameter(); // returns: boolean
40
+ ```
41
+
42
+ Or set a parameter as a rest parameter:
43
+
44
+ ```ts
45
+ parameter.setIsRestParameter(true);
46
+ ```
47
+
48
+ ### Parameter Property
49
+
50
+ Constructor parameters may be properties when they have a scope and/or are readonly. You can tell if one is by calling:
51
+
52
+ ```ts
53
+ const isParameterProperty = parameter.isParameterProperty(); // returns: boolean
54
+ ```
55
+
56
+ ### Optional
57
+
58
+ A parameter can be optional if it is marked so with a question mark, is a rest parameter, or has an initializer.
59
+
60
+ `isOptional()` can be used to tell if any of these are true:
61
+
62
+ ```ts
63
+ const isOptional = parameter.isOptional(); // returns: boolean
64
+ ```
@@ -0,0 +1,41 @@
1
+ ---
2
+ title: Signatures
3
+ ---
4
+
5
+ ## Signatures
6
+
7
+ ### Type Parameters
8
+
9
+ ```ts
10
+ const typeParams = signature.getTypeParameters(); // returns: TypeParameter[]
11
+ ```
12
+
13
+ ### Parameters
14
+
15
+ ```ts
16
+ const params = signature.getParameters(); // returns: Symbol[]
17
+ ```
18
+
19
+ ### Return Type
20
+
21
+ ```ts
22
+ const returnType = signature.getReturnType();
23
+ ```
24
+
25
+ ### Documentation Comments
26
+
27
+ ```ts
28
+ const docs = signature.getDocumentationComments();
29
+ ```
30
+
31
+ ### JS Doc Tags
32
+
33
+ ```ts
34
+ const tags = signature.getJsDocTags();
35
+ ```
36
+
37
+ ### Declaration
38
+
39
+ ```ts
40
+ const declaration = signature.getDeclaration();
41
+ ```
@@ -0,0 +1,292 @@
1
+ ---
2
+ title: Source Files
3
+ ---
4
+
5
+ ## Source Files
6
+
7
+ Source files are the root nodes of the AST. They can be created or added to a `Project` instance
8
+ by following the instructions at [Adding Source Files](../setup/adding-source-files).
9
+
10
+ ### File path and name
11
+
12
+ Use:
13
+
14
+ ```ts
15
+ // returns the file path (ex. /home/david/file.ts)
16
+ sourceFile.getFilePath();
17
+
18
+ // returns only the file name (ex. file.ts)
19
+ sourceFile.getBaseName();
20
+ ```
21
+
22
+ ### Other Information
23
+
24
+ Check if it's a declaration file:
25
+
26
+ ```ts
27
+ sourceFile.isDeclarationFile(); // returns: boolean
28
+ ```
29
+
30
+ Check if it was discovered from an external module:
31
+
32
+ ```ts
33
+ sourceFile.isFromExternalLibrary();
34
+ ```
35
+
36
+ Check if it's a descendant of a `node_modules` directory:
37
+
38
+ ```ts
39
+ sourceFile.isInNodeModules();
40
+ ```
41
+
42
+ ### Save
43
+
44
+ Save a source file to the file system using one of the following commands:
45
+
46
+ ```ts
47
+ await sourceFile.save();
48
+ sourceFile.saveSync();
49
+ ```
50
+
51
+ Note: This does not emit the files (see [Emitting](../emitting.md)).
52
+
53
+ ### Unsaved files
54
+
55
+ Use the `sourceFile.isSaved()` method that will tell you if the file is saved to the file system.
56
+
57
+ ### Delete
58
+
59
+ The `sourceFile.delete()` method will queue up deletions to the file system. When done call `project.save()`. For example:
60
+
61
+ ```ts
62
+ import { Project } from "ts-morph";
63
+
64
+ // queue up all the source files to be deleted
65
+ const project = new Project();
66
+ project.addSourceFilesAtPaths("folder/**/*.ts");
67
+
68
+ project.getSourceFileOrThrow("someFile.ts").delete();
69
+ project.getSourceFileOrThrow("someOtherFile.ts").delete();
70
+
71
+ // after you're all done, finally save your changes to the file system
72
+ await project.save();
73
+ ```
74
+
75
+ #### Deleting Immediately
76
+
77
+ It's possible to delete a source file from the file system immediately by calling one of the following methods:
78
+
79
+ ```ts
80
+ await sourceFile.deleteImmediately();
81
+ sourceFile.deleteImmediatelySync();
82
+ ```
83
+
84
+ This isn't recommended though because it could possibly leave the file system in a halfway state if your code errors before it's done.
85
+
86
+ ### Copy
87
+
88
+ Copy a source file to a new file by specifying a new relative or absolute path:
89
+
90
+ ```ts setup: const someDirectoryObject: Directory
91
+ const newSourceFile = sourceFile.copy("newFileName.ts");
92
+ // this won't throw if a file exists at the specified path
93
+ const otherSourceFile = sourceFile.copy("other.ts", { overwrite: true });
94
+ // or specify directory to copy to
95
+ sourceFile.copyToDirectory("/some/dir");
96
+ sourceFile.copyToDirectory(someDirectoryObject);
97
+ ```
98
+
99
+ Note: If necessary, this will automatically update the module specifiers of the relative import and export declarations
100
+ in the copied file.
101
+
102
+ #### Copying Immediately
103
+
104
+ As with `.deleteImmediately()` it's possible to immediately copy a file and have the changes reflected on the file system:
105
+
106
+ ```ts
107
+ await sourceFile.copyImmediately("NewFile.ts");
108
+ sourceFile.copyImmediatelySync("NewFile2.ts");
109
+ ```
110
+
111
+ ### Move
112
+
113
+ Moves a source file to a new file by specifying a new relative or absolute path:
114
+
115
+ ```ts setup: const someDirectoryObject: Directory
116
+ sourceFile.move("newFileName.ts");
117
+ // this won't throw if a file exists at the specified path
118
+ sourceFile.move("other.ts", { overwrite: true });
119
+ // or specify directory to move to
120
+ sourceFile.moveToDirectory("/some/dir");
121
+ sourceFile.moveToDirectory(someDirectoryObject);
122
+ ```
123
+
124
+ Note: If necessary, this will automatically update the module specifiers of the relative import and export declarations
125
+ in the moving file and the relative import and export declarations in other files to point to the new location.
126
+
127
+ #### Moving Immediately
128
+
129
+ As with `.deleteImmediately()` it's possible to immediately move a file and have the changes reflected on the file system:
130
+
131
+ ```ts
132
+ await sourceFile.moveImmediately("NewFile.ts");
133
+ sourceFile.moveImmediatelySync("NewFile2.ts");
134
+ ```
135
+
136
+ ### Refresh from file system
137
+
138
+ Refresh the source file from the file system:
139
+
140
+ ```ts
141
+ import { FileSystemRefreshResult } from "ts-morph";
142
+
143
+ // returns: FileSystemRefreshResult (NoChange, Updated, Deleted)
144
+ const result = await sourceFile.refreshFromFileSystem(); // or refreshFromFileSystemSync()
145
+ ```
146
+
147
+ This is useful when you are using a file system watcher and want to refresh a source file from the file system based on changes.
148
+
149
+ If the file was _updated_: All the child nodes of the source file will be forgotten and you will have to renavigate the file.
150
+ If the file was _deleted_: The source file will be removed and all its nodes forgotten.
151
+
152
+ ### Remove
153
+
154
+ Remove a source file from the project by calling:
155
+
156
+ ```ts
157
+ sourceFile.forget();
158
+ ```
159
+
160
+ Or alternatively:
161
+
162
+ ```ts
163
+ project.removeSourceFile(sourceFile); // returns: boolean (true if was removed)
164
+ ```
165
+
166
+ Note: This does not delete the file from the file system. To do delete it, call `#delete()`.
167
+
168
+ ### Reference comments
169
+
170
+ ```ts
171
+ // gets `/// <reference path="..." />` comments
172
+ const pathReferenceDirectives = sourceFile.getPathReferenceDirectives();
173
+ // gets `/// <reference types="..." />` comments
174
+ const typeReferenceDirectives = sourceFile.getTypeReferenceDirectives();
175
+ // gets `/// <reference lib="..." />` comments
176
+ const libReferenceDirectives = sourceFile.getLibReferenceDirectives();
177
+ ```
178
+
179
+ ### Import Declarations
180
+
181
+ See [Import Declarations](imports).
182
+
183
+ ### Export Declarations
184
+
185
+ See [Export Declarations](exports).
186
+
187
+ ### Indenting / Unindenting
188
+
189
+ Call the `.indent` or `.unindent` methods.
190
+
191
+ <!-- dprint-ignore -->
192
+ ```ts
193
+ sourceFile.indent(5); // indent line containing position 5
194
+ sourceFile.indent([5, 10]); // indent line or lines within position range [5-10]
195
+ sourceFile.indent(10, 3); // indent line containing position 10, 3 times
196
+
197
+ sourceFile.unindent(10); // unindent line containing position 10
198
+
199
+ sourceFile.indent(10, -1); // unindent line containing position 10 (specify negative times)
200
+ sourceFile.unindent(10, -1); // indent line containing position 10 (specify negative times)
201
+ ```
202
+
203
+ This will indent and unindent based on your [manipulation settings](../manipulation/settings).
204
+
205
+ ### Getting referencing files
206
+
207
+ Getting the source files that reference this source file in nodes like import declarations, export declarations, import equals declarations, and dynamic imports can be found by using the following:
208
+
209
+ ```ts
210
+ const referencingSourceFiles = sourceFile.getReferencingSourceFiles();
211
+ ```
212
+
213
+ To get the nodes that reference the source file in other source files:
214
+
215
+ ```ts
216
+ const referencingNodes = sourceFile.getReferencingNodesInOtherSourceFiles();
217
+ ```
218
+
219
+ To get the string literals that reference this source file in other source files:
220
+
221
+ ```ts
222
+ const referencingLiterals = sourceFile.getReferencingLiteralsInOtherSourceFiles();
223
+ ```
224
+
225
+ ### Getting referenced files
226
+
227
+ The opposite of the referencing files, is the referenced files—files that are referenced in nodes within the current file.
228
+
229
+ ```ts
230
+ const referencedSourceFiles = sourceFile.getReferencedSourceFiles();
231
+ ```
232
+
233
+ To get the nodes that reference other source files:
234
+
235
+ ```ts
236
+ const nodesReferencingOtherSourceFiles = sourceFile.getNodesReferencingOtherSourceFiles();
237
+ ```
238
+
239
+ To get the string literals that reference other source files:
240
+
241
+ ```ts
242
+ const literalsReferencingOtherSourceFiles = sourceFile.getLiteralsReferencingOtherSourceFiles();
243
+ // or to get all the literals that reference a module (and may not have been resolved to a source file)
244
+ const importLiterals = sourceFile.getImportStringLiterals();
245
+ ```
246
+
247
+ ### Relative File Paths
248
+
249
+ It might be useful to get the relative path from one source file to another source file or directory.
250
+
251
+ ```ts setup: let sourceFileFrom: SourceFile, sourceFileTo: SourceFile;
252
+ const relativePath = sourceFileFrom.getRelativePathTo(sourceFileTo);
253
+ ```
254
+
255
+ Or to get the module specifier text from one source file to another source file or directory.
256
+
257
+ ```ts setup: let sourceFileFrom: SourceFile, sourceFileTo: SourceFile;
258
+ const moduleSpecifier = sourceFileFrom.getRelativePathAsModuleSpecifierTo(sourceFileTo);
259
+ ```
260
+
261
+ ## Source File Code Fixes
262
+
263
+ ### Organizing Imports
264
+
265
+ It's possible to organize all the imports in a source file via the ["organize imports"](https://blogs.msdn.microsoft.com/typescript/2018/03/27/announcing-typescript-2-8/)
266
+ feature from TypeScript 2.8.
267
+
268
+ ```ts
269
+ sourceFile.organizeImports();
270
+ ```
271
+
272
+ Note: This will forget all the previously navigated nodes so it's recommended to make this either the first or last action you do to a source file.
273
+
274
+ ### Add Missing Imports
275
+
276
+ To add all the missing import declarations to a source file, use the following method:
277
+
278
+ ```ts
279
+ sourceFile.fixMissingImports();
280
+ ```
281
+
282
+ ### Fix Unused Identifiers
283
+
284
+ To remove all unused declarations (ex. variables, classes, etc..) from a source file, use the following method:
285
+
286
+ ```ts
287
+ sourceFile.fixUnusedIdentifiers();
288
+ ```
289
+
290
+ Tip: For optimal results, sometimes this method needs to be called more than once. There could be nodes that are only referenced in unused declarations and in this case another call would remove them.
291
+
292
+ Note: This will forget all the previously navigated nodes so it's recommended to make this either the first or last action you do to a source file.
@@ -0,0 +1,34 @@
1
+ ---
2
+ title: Type Aliases
3
+ ---
4
+
5
+ ## Type Aliases
6
+
7
+ Type aliases can be retrieved from source files, namespaces, or function bodies:
8
+
9
+ ```ts
10
+ const typeAliases = sourceFile.getTypeAliases();
11
+ const typeAlias = sourceFile.getTypeAlias("TypeAlias");
12
+ const firstExportedTypeAlias = sourceFile.getTypeAlias(a => a.hasExportKeyword());
13
+ ```
14
+
15
+ Most of the information you can get about type aliases is covered in other sections.
16
+
17
+ ### Add/Insert
18
+
19
+ Add or insert type aliases to a source file, namespace, or function like declarations by calling `addTypeAlias()`, `addTypeAliases()`, `insertTypeAlias()`, or `insertTypeAliases()`.
20
+
21
+ ```ts
22
+ const typeAliasDeclaration = sourceFile.addTypeAlias({
23
+ name: "TypeAliasName",
24
+ type: "string",
25
+ });
26
+ ```
27
+
28
+ ### Remove
29
+
30
+ Call `.remove()`:
31
+
32
+ ```ts
33
+ typeAliasDeclaration.remove();
34
+ ```
@@ -0,0 +1,72 @@
1
+ ---
2
+ title: Type Parameters
3
+ ---
4
+
5
+ ## Type Parameters
6
+
7
+ Type parameters can be retreived from nodes by calling `getTypeParameters()`:
8
+
9
+ ```ts
10
+ const typeParameters = classDeclaration.getTypeParameters();
11
+ ```
12
+
13
+ ### Inserting/Adding
14
+
15
+ Insert or add type parameters by calling `insertTypeParameter()`, `insertTypeParameters()`, `addTypeParameter()`, or `addTypeParameters()`.
16
+
17
+ For example:
18
+
19
+ ```ts
20
+ const typeParameter = classDeclaration.insertTypeParameter(1, {
21
+ name: "T",
22
+ constraint: "string", // optional
23
+ });
24
+ ```
25
+
26
+ ### Removing
27
+
28
+ Remove a type parameter by calling `.remove()` on it:
29
+
30
+ ```ts
31
+ typeParameter.remove();
32
+ ```
33
+
34
+ ### Constraint
35
+
36
+ Get the constraint type node:
37
+
38
+ ```ts
39
+ const constraint = typeParameter.getConstraint(); // returns: TypeNode | undefined
40
+ ```
41
+
42
+ Or set the constraint:
43
+
44
+ ```ts
45
+ typeParameter.setConstraint("string");
46
+ ```
47
+
48
+ Or remove it:
49
+
50
+ ```ts
51
+ typeParameter.removeConstraint();
52
+ ```
53
+
54
+ ### Default
55
+
56
+ Get the default type node:
57
+
58
+ ```ts
59
+ const defaultNode = typeParameter.getDefault(); // returns: TypeNode | undefined
60
+ ```
61
+
62
+ Or set the default type node:
63
+
64
+ ```ts
65
+ typeParameter.setDefault("string");
66
+ ```
67
+
68
+ Or remove it:
69
+
70
+ ```ts
71
+ typeParameter.removeDefault();
72
+ ```