|
2 | 2 | // See LICENSE in the project root for license information. |
3 | 3 |
|
4 | 4 | import * as tsdoc from '@microsoft/tsdoc'; |
| 5 | +import * as path from 'path'; |
5 | 6 | import { ExtractorMessageId } from './ExtractorMessageId'; |
| 7 | +import { Path, Text } from '@microsoft/node-core-library'; |
6 | 8 |
|
7 | 9 | /** |
8 | 10 | * Specifies a category of messages for use with {@link ExtractorMessage}. |
@@ -97,4 +99,50 @@ export class ExtractorMessage { |
97 | 99 | this.sourceFileLine = options.sourceFileLine; |
98 | 100 | this.sourceFileColumn = options.sourceFileColumn; |
99 | 101 | } |
| 102 | + |
| 103 | + /** |
| 104 | + * Returns the message formatted with its identifier and file position. |
| 105 | + * @remarks |
| 106 | + * Example: |
| 107 | + * ``` |
| 108 | + * src/folder/File.ts:123:4 - (ae-extra-release-tag) The doc comment should not contain more than one release tag. |
| 109 | + * ``` |
| 110 | + */ |
| 111 | + public formatMessageAndLocation(workingPackageFolderPath: string): string { |
| 112 | + let result: string = ''; |
| 113 | + |
| 114 | + if (this.sourceFilePath) { |
| 115 | + // Make the path relative to the workingPackageFolderPath |
| 116 | + let scrubbedPath: string = this.sourceFilePath; |
| 117 | + |
| 118 | + // If it's under the working folder, make it a relative path |
| 119 | + if (Path.isUnderOrEqual(this.sourceFilePath, workingPackageFolderPath)) { |
| 120 | + scrubbedPath = path.relative(workingPackageFolderPath, this.sourceFilePath); |
| 121 | + } |
| 122 | + |
| 123 | + // Convert it to a Unix-style path |
| 124 | + scrubbedPath = Text.replaceAll(scrubbedPath, '\\', '/'); |
| 125 | + result += scrubbedPath; |
| 126 | + |
| 127 | + if (this.sourceFileLine) { |
| 128 | + result += `:${this.sourceFileLine}`; |
| 129 | + |
| 130 | + if (this.sourceFileColumn) { |
| 131 | + result += `:${this.sourceFileColumn}`; |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + if (result.length > 0) { |
| 136 | + result += ' - '; |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + result += this.formatMessageWithoutLocation(); |
| 141 | + |
| 142 | + return result; |
| 143 | + } |
| 144 | + |
| 145 | + public formatMessageWithoutLocation(): string { |
| 146 | + return `(${this.messageId}) ${this.text}`; |
| 147 | + } |
100 | 148 | } |
0 commit comments