New issue
Advanced search Search tips

Issue 892530 link

Starred by 1 user

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , Windows , Chrome , Mac
Pri: 3
Type: Bug



Sign in to add a comment

Compile/typecheck Chrome's JS code with jscomp_warning=lintChecks and other things

Project Member Reported by tapted@chromium.org, Oct 5

Issue description

Chrome Version       : 71.0.3559.6

I keep running into type errors that aren't picked up by typechecking. The most common case seems to be for callback arguments. E.g.

 something.getFoo(function(ihavenotype) {... });

these need to be documented like

 something.getFoo(function /** ReturnType */ (/** TheType */ ihaveatype) {... });

see https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#param-type-varname-description
and https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#return-type-description


That's _if_ closure can't figure out the argument for itself. Often it already knows the type of a callback arg, but doesn't tell you.

There's jsdocMissingType, but it doesn't seem to do anything. The only way to catch these seems to be to compile with linkChecks, but that emits a bunch of stuff we don't care about like


 ../../ui/webui/resources/js/cr/event_target.js:23: WARNING - Missing semicolon
  function EventTarget() {}
  ^^^^^^^^^^^^^^^^^^^^^^^^

(I think we even have a presubmit that ensures we _don't_ have a semicolon there?)

There's a ton of legitimate errors though. A whole bunch in third_party/jstemplate

It's probably not realistic to add jscomp_warning=lintChecks to default build args, but I'm making this bug to track work towards linting javascript in various bits of Chrome's codebase.

There are some other useful things we should probably add. I'm currently toying with

+  closure_flags = default_closure_args + [
+    "jscomp_error=misplacedTypeAnnotation",
+    "jscomp_error=jsdocMissingType",
+    "jscomp_error=functionParams",
+    "jscomp_error=unusedPrivateMembers",
+    "jscomp_error=unusedLocalVariables",
+    "jscomp_warning=lintChecks",
+  ]


 
Note to self - reportUnknownTypes for flushing out undocumented things. Also go/compiler-flag-reference to find more flags and documentation for them. It doesn't have the juicy undocumented stuff like lintChecks

Go to the source for that, which is open:

https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/DiagnosticGroups.java

Sign in to add a comment