Loading ...
Sorry, an error occurred while loading the content.

Re: combining Closure Compiler type casting with JSLint

Expand Messages
  • douglascrockford
    ... I may add option.closure. Is there any more weirdness?
    Message 1 of 3 , Mar 26, 2013
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, Jos van den Oever <jos.van.den.oever@...> wrote:
      >
      > In WebODF, we've been happily using JSLint for some time. It is a
      > terrific tool for non-trivial JavaScript project. In addition to JSLint
      > we are using Closure Compiler, mainly for type checking.
      >
      > Closure Compiler can keep track of data types and allows casting between
      > data types. Here is an example:
      >
      > var a = /**@type{!number}*/(b);
      >
      > Here, the variable a is assigned the value of b, cast to a non-null
      > number (a !== null && a !== undefined).
      >
      > When setting JSLint loose on this fragment, the following error occurs:
      > error: Unexpected '('.
      >
      > JSLint is not aware of the Closure Compiler idiom of specifying types. A
      > smaller example that results in the same error is this:
      >
      > function x(b) {
      > "use strict";
      > var a = (b);
      > }
      >
      > In Closure Compiler, the parentheses are obligatory; in JSLint (version
      > 2013-03-19) they are forbidden.
      >
      > Is there a way to make JSLint accept the unneeded parentheses?

      I may add option.closure. Is there any more weirdness?
    • Jos van den Oever
      ... Writing var a = /**@type{!number}*/(b); also has effect on the white-space. JSLint expects the b to be much closer to the = . This is a check that can
      Message 2 of 3 , Mar 27, 2013
      • 0 Attachment
        On 03/26/2013 11:23 PM, douglascrockford wrote:
        > --- In jslint_com@yahoogroups.com <mailto:jslint_com%40yahoogroups.com>,
        > Jos van den Oever <jos.van.den.oever@...> wrote:
        > >
        > > In WebODF, we've been happily using JSLint for some time. It is a
        > > terrific tool for non-trivial JavaScript project. In addition to JSLint
        > > we are using Closure Compiler, mainly for type checking.
        > >
        > > Closure Compiler can keep track of data types and allows casting between
        > > data types. Here is an example:
        > >
        > >
        > >
        > > Here, the variable a is assigned the value of b, cast to a non-null
        > > number (a !== null && a !== undefined).
        > >
        > > When setting JSLint loose on this fragment, the following error occurs:
        > > error: Unexpected '('.
        > >
        > > JSLint is not aware of the Closure Compiler idiom of specifying types. A
        > > smaller example that results in the same error is this:
        > >
        > > function x(b) {
        > > "use strict";
        > > var a = (b);
        > > }
        > >
        > > In Closure Compiler, the parentheses are obligatory; in JSLint (version
        > > 2013-03-19) they are forbidden.
        > >
        > > Is there a way to make JSLint accept the unneeded parentheses?
        >
        > I may add option.closure. Is there any more weirdness?

        Writing
        var a = /**@type{!number}*/(b);
        also has effect on the white-space. JSLint expects the 'b' to be much
        closer to the '='. This is a check that can be disabled.

        Type definitions in Closure Compiler are empty statements:

        /** @typedef {(string|number)} */
        goog.NumberLike;

        For simple types, one can get around this by adding an initializer or
        doing type definitions in a small file that is excluded from the JSLint
        step.

        Cheers,
        Jos

        https://developers.google.com/closure/compiler/docs/js-for-compiler
      Your message has been successfully submitted and would be delivered to recipients shortly.