2424import com .google .javascript .jscomp .DiagnosticGroup ;
2525import com .google .javascript .jscomp .DiagnosticType ;
2626import com .google .javascript .jscomp .ExportTestFunctions ;
27+ import com .google .javascript .jscomp .JSError ;
2728import com .google .javascript .jscomp .NodeTraversal ;
2829import com .google .javascript .jscomp .NodeTraversal .AbstractPostOrderCallback ;
2930import com .google .javascript .jscomp .NodeTraversal .AbstractPreOrderCallback ;
@@ -55,7 +56,7 @@ public final class CheckJSDocStyle extends AbstractPostOrderCallback implements
5556 + " instead?" );
5657
5758 public static final DiagnosticType MISSING_PARAMETER_JSDOC =
58- DiagnosticType .disabled ("JSC_MISSING_PARAMETER_JSDOC" , "Parameter must have JSDoc." );
59+ DiagnosticType .disabled ("JSC_MISSING_PARAMETER_JSDOC" , "Parameter must have JSDoc.{0} " );
5960
6061 public static final DiagnosticType MIXED_PARAM_JSDOC_STYLES =
6162 DiagnosticType .disabled ("JSC_MIXED_PARAM_JSDOC_STYLES" ,
@@ -64,7 +65,7 @@ public final class CheckJSDocStyle extends AbstractPostOrderCallback implements
6465 public static final DiagnosticType MISSING_RETURN_JSDOC =
6566 DiagnosticType .disabled (
6667 "JSC_MISSING_RETURN_JSDOC" ,
67- "Function with non-trivial return must have JSDoc indicating the return type." );
68+ "Function with non-trivial return must have JSDoc indicating the return type.{0} " );
6869
6970 public static final DiagnosticType MUST_BE_PRIVATE =
7071 DiagnosticType .disabled (
@@ -234,7 +235,7 @@ private void visitFunction(NodeTraversal t, Node function) {
234235 checkParams (t , function , jsDoc );
235236 }
236237 checkNoTypeOnGettersAndSetters (t , function , jsDoc );
237- checkReturn (t , function , jsDoc );
238+ checkReturn (function , jsDoc );
238239 }
239240 }
240241
@@ -308,10 +309,6 @@ private boolean isConstructorWithoutParameters(Node function) {
308309 }
309310
310311 private void checkParams (NodeTraversal t , Node function , JSDocInfo jsDoc ) {
311- if (jsDoc != null && jsDoc .isOverride ()) {
312- return ;
313- }
314-
315312 if (jsDoc != null && jsDoc .getType () != null ) {
316313 // Sometimes functions are declared with @type {function(Foo, Bar)} instead of
317314 // @param {Foo} foo
@@ -329,7 +326,17 @@ private void checkParams(NodeTraversal t, Node function, JSDocInfo jsDoc) {
329326 } else {
330327 Node paramList = NodeUtil .getFunctionParameters (function );
331328 if (!paramList .hasXChildren (paramsFromJsDoc .size ())) {
332- t .report (paramList , WRONG_NUMBER_OF_PARAMS );
329+ compiler .report (
330+ JSError .make (
331+ paramList ,
332+ WRONG_NUMBER_OF_PARAMS ,
333+ jsDoc .isOverride ()
334+ ?
335+ // moe:begin_strip
336+ " Please see go/tsjs-problematic-patterns for why @overrides require explicit"
337+ + " @param types."
338+ // moe:end_strip_and_replace ""
339+ : "" ));
333340 return ;
334341 }
335342
@@ -429,12 +436,8 @@ private boolean hasAnyInlineJsDoc(Node function) {
429436 return false ;
430437 }
431438
432- private void checkReturn (NodeTraversal t , Node function , JSDocInfo jsDoc ) {
433- if (jsDoc != null
434- && (jsDoc .hasType ()
435- || jsDoc .isConstructor ()
436- || jsDoc .hasReturnType ()
437- || jsDoc .isOverride ())) {
439+ private void checkReturn (Node function , JSDocInfo jsDoc ) {
440+ if (jsDoc != null && (jsDoc .hasType () || jsDoc .isConstructor () || jsDoc .hasReturnType ())) {
438441 return ;
439442 }
440443
@@ -450,7 +453,17 @@ private void checkReturn(NodeTraversal t, Node function, JSDocInfo jsDoc) {
450453 FindNonTrivialReturn finder = new FindNonTrivialReturn ();
451454 NodeTraversal .traverse (compiler , function .getLastChild (), finder );
452455 if (finder .found ) {
453- t .report (function , MISSING_RETURN_JSDOC );
456+ compiler .report (
457+ JSError .make (
458+ function ,
459+ MISSING_RETURN_JSDOC ,
460+ jsDoc != null && jsDoc .isOverride ()
461+ ?
462+ // moe:begin_strip
463+ " Please see go/tsjs-problematic-patterns for why @overrides require explicit"
464+ + " @return types.."
465+ // moe:end_strip_and_replace ""
466+ : "" ));
454467 }
455468 }
456469
0 commit comments