33
44import * as ts from 'typescript' ;
55import * as tsdoc from '@microsoft/tsdoc' ;
6+ import { Sort } from '@microsoft/node-core-library' ;
67
78import { TypeScriptMessageFormatter } from '../analyzer/TypeScriptMessageFormatter' ;
89import { AstDeclaration } from '../analyzer/AstDeclaration' ;
@@ -19,7 +20,7 @@ import {
1920 IExtractorMessageReportingRuleConfig
2021} from '../api/IExtractorConfig' ;
2122import { AedocDefinitions } from '../aedoc/AedocDefinitions' ;
22- import { Sort } from '@microsoft/node-core-library ' ;
23+ import { ILogger } from '../api/ILogger ' ;
2324
2425interface IReportingRule {
2526 logLevel : ExtractorMessageLogLevel ;
@@ -146,8 +147,8 @@ export class MessageRouter {
146147 diagnostic . start || 0 ) ;
147148
148149 options . sourceFilePath = sourceFile . fileName ;
149- options . sourceFileLine = lineAndCharacter . line ;
150- options . sourceFileColumn = lineAndCharacter . character ;
150+ options . sourceFileLine = lineAndCharacter . line + 1 ;
151+ options . sourceFileColumn = lineAndCharacter . character + 1 ;
151152 }
152153
153154 this . _messages . push ( new ExtractorMessage ( options ) ) ;
@@ -189,8 +190,8 @@ export class MessageRouter {
189190 messageId : message . messageId ,
190191 text : message . unformattedText ,
191192 sourceFilePath : sourceFile . fileName ,
192- sourceFileLine : lineAndCharacter . line ,
193- sourceFileColumn : lineAndCharacter . character
193+ sourceFileLine : lineAndCharacter . line + 1 ,
194+ sourceFileColumn : lineAndCharacter . character + 1
194195 } ) ;
195196
196197 if ( astDeclaration ) {
@@ -231,8 +232,8 @@ export class MessageRouter {
231232 messageId,
232233 text : messageText ,
233234 sourceFilePath : sourceFile . fileName ,
234- sourceFileLine : lineAndCharacter . line ,
235- sourceFileColumn : lineAndCharacter . character
235+ sourceFileLine : lineAndCharacter . line + 1 ,
236+ sourceFileColumn : lineAndCharacter . character + 1
236237 } ;
237238
238239 const extractorMessage : ExtractorMessage = new ExtractorMessage ( options ) ;
@@ -298,6 +299,40 @@ export class MessageRouter {
298299 return messagesForApiReviewFile ;
299300 }
300301
302+ /**
303+ * This returns the list of remaining messages that were not already processed by
304+ * `fetchAssociatedMessagesForReviewFile()` or `fetchUnassociatedMessagesForReviewFile()`.
305+ * These messages will be shown on the console.
306+ */
307+ public reportMessagesToLogger ( logger : ILogger , workingPackageFolderPath : string ) : ExtractorMessage [ ] {
308+ const messagesForLogger : ExtractorMessage [ ] = [ ] ;
309+
310+ for ( const message of this . messages ) {
311+
312+ // Make sure we didn't already report this message
313+ if ( ! this . _messagesAddedToApiReviewFile . has ( message ) ) {
314+ messagesForLogger . push ( message ) ;
315+ }
316+ }
317+
318+ this . _sortMessagesForOutput ( messagesForLogger ) ;
319+
320+ for ( const message of messagesForLogger ) {
321+ // Is this message type configured to go to the console?
322+ const reportingRule : IReportingRule = this . _getRuleForMessage ( message ) ;
323+ switch ( reportingRule . logLevel ) {
324+ case ExtractorMessageLogLevel . Error :
325+ logger . logError ( 'Error: ' + message . formatMessageAndLocation ( workingPackageFolderPath ) ) ;
326+ break ;
327+ case ExtractorMessageLogLevel . Warning :
328+ logger . logWarning ( 'Warning: ' + message . formatMessageAndLocation ( workingPackageFolderPath ) ) ;
329+ break ;
330+ }
331+ }
332+
333+ return messagesForLogger ;
334+ }
335+
301336 /**
302337 * For a given message, determine the IReportingRule based on the rule tables.
303338 */
@@ -320,7 +355,20 @@ export class MessageRouter {
320355 * Sorts an array of messages according to a reasonable ordering
321356 */
322357 private _sortMessagesForOutput ( messages : ExtractorMessage [ ] ) : void {
323- // Sort by filename, then by line number
324- Sort . sortBy ( messages , x => ( x . sourceFilePath || '' ) + '#' + ( x . sourceFileLine || '' ) ) ;
358+ messages . sort ( ( a , b ) => {
359+ let diff : number ;
360+ // First sort by file name
361+ diff = Sort . compareByValue ( a . sourceFilePath , b . sourceFilePath ) ;
362+ if ( diff !== 0 ) {
363+ return diff ;
364+ }
365+ // Then sort by line number
366+ diff = Sort . compareByValue ( a . sourceFileLine , b . sourceFileLine ) ;
367+ if ( diff !== 0 ) {
368+ return diff ;
369+ }
370+ // Then sort by messageId
371+ return Sort . compareByValue ( a . messageId , b . messageId ) ;
372+ } ) ;
325373 }
326374}
0 commit comments