You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by Cassie <do...@apache.org> on 2008/02/22 02:30:02 UTC

Try to use a single 'var' statement per scope.

When running the shindig server these days we are now getting tons and tons
of js warnings. It seems to be linting for some very weird things, the most
prevalent being "Try to use a single 'var' statement per scope."

Does anyone know how to turn off this particular warning? I don't think it
is useful at all (using more than one var per scope in js is perfectly
reasonable) and is hiding some of the hopefully more valuable warnings.

Thanks!

- Cassie

Re: Try to use a single 'var' statement per scope.

Posted by Kevin Brown <et...@google.com>.
This has disabled compression entirely, because 0.6 does not put files in
the correct output location (it's putting everything directly under classes/
instead of retaining directory structure). I upgraded to 0.6.2, which was
the first version that corrects this path.

On Mon, Feb 25, 2008 at 8:45 AM, Cassie <do...@apache.org> wrote:

> Thanks! I put us back to version 0.6 so that the warnings actually mean
> something.
> Perhaps we can re-upgrade if we find a way to selectively turn that error
> off.
>
> - Cassie
>
>
> On Mon, Feb 25, 2008 at 4:23 AM, Martin Webb <ma...@gmail.com>
> wrote:
>
> > To temporarily suppress the "Try to use a single 'var' statement per
> > scope."
> > you can try changing the pom.xml to use an older version, ie. from:
> >
> >        <groupId>net.sf.alchim</groupId>
> >        <artifactId>yuicompressor-maven-plugin</artifactId>
> >
> >
> > to:
> >
> >        <groupId>net.sf.alchim</groupId>
> >        <artifactId>yuicompressor-maven-plugin</artifactId>
> >        <version>0.6</version>
> >
> > Martin
> >
> > --
> > Internet Related Technologies - http://www.irt.org
> >
>



-- 
~Kevin

If you received this email by mistake, please delete it, cancel your mail
account, destroy your hard drive, silence any witnesses, and burn down the
building that you're in.

Re: Try to use a single 'var' statement per scope.

Posted by Cassie <do...@apache.org>.
Thanks! I put us back to version 0.6 so that the warnings actually mean
something.
Perhaps we can re-upgrade if we find a way to selectively turn that error
off.

- Cassie


On Mon, Feb 25, 2008 at 4:23 AM, Martin Webb <ma...@gmail.com>
wrote:

> To temporarily suppress the "Try to use a single 'var' statement per
> scope."
> you can try changing the pom.xml to use an older version, ie. from:
>
>        <groupId>net.sf.alchim</groupId>
>        <artifactId>yuicompressor-maven-plugin</artifactId>
>
>
> to:
>
>        <groupId>net.sf.alchim</groupId>
>        <artifactId>yuicompressor-maven-plugin</artifactId>
>        <version>0.6</version>
>
> Martin
>
> --
> Internet Related Technologies - http://www.irt.org
>

Re: Try to use a single 'var' statement per scope.

Posted by Martin Webb <ma...@gmail.com>.
To temporarily suppress the "Try to use a single 'var' statement per scope."
you can try changing the pom.xml to use an older version, ie. from:

        <groupId>net.sf.alchim</groupId>
        <artifactId>yuicompressor-maven-plugin</artifactId>


to:

        <groupId>net.sf.alchim</groupId>
        <artifactId>yuicompressor-maven-plugin</artifactId>
        <version>0.6</version>

Martin

-- 
Internet Related Technologies - http://www.irt.org

Re: Try to use a single 'var' statement per scope.

Posted by Kevin Brown <et...@google.com>.
On Thu, Feb 21, 2008 at 6:38 PM, Cassie <do...@apache.org> wrote:
>
>
> I'll +1 this. Also, if we can't use more than one var in a scope when
> coding, our js code is going to look ridiculously ugly. Better to just get
> a
> robust compiler in here to do a better job.


No need to avoid it if you know what you're doing, though the warnings are a
bit annoying. If someone finds a better minifier that can automatically
coalesce var declarations we should definitely consider it.

Re: Try to use a single 'var' statement per scope.

Posted by Cassie <do...@apache.org>.
On Thu, Feb 21, 2008 at 6:23 PM, Kevin Brown <et...@google.com> wrote:

> On Thu, Feb 21, 2008 at 6:03 PM, Paul Lindner <pl...@hi5.com> wrote:
>
> > Here's what's going on:
> >
> >
> > YUI Compressor 2.3.5, 2008-02-08
> > --------------------------------
> >
> > + Added a warning when more than one 'var' statement is used in a single
> > scope.
> >  Automatic coalescence is extremely complicated, and would be unsafe if
> > not
> >  done properly.
> >
> >
> > At first I thought it was bogus, but it turns out it's correct.  Try
> > running this code and guess what the output is:
> >
> >  for (var i=0; i< 10; i++) {
> >    document.write(i + " ");
> >    document.write(" ");
> >  }
> >  document.write("<br>result is " + i);
> >
> > 1 2 3 4 5 6 7 8 9
> > result is 10
> >
> >
> > Digging deeper I find that javascript's local scope is only local to
> > the function.  ... shudder ....
>
>
> Not quite; it doesn't have a "local" scope, it only has closure scope (and
> a
> function produces a closure). Javascript does not support anonymous scopes
> as seen in languages such as java and C++ (what you're really doing when
> you
> put brackets after a control statement). This is the same as in C and most
> functional programming languages.
>
> That being said, I disagree with the YUI compressor comment's assertion
> that
> it's difficult, because there are at least two minifiers that I've used
> that
> do it without issue (unfortunately, we can't use them on this project).
> I'd
> love to see support for this added anyway though, as it's also got
> performance benefits.


I'll +1 this. Also, if we can't use more than one var in a scope when
coding, our js code is going to look ridiculously ugly. Better to just get a
robust compiler in here to do a better job.



>
>
>
> >
> >
> > On Thu, Feb 21, 2008 at 05:30:02PM -0800, Cassie wrote:
> > > When running the shindig server these days we are now getting tons and
> > tons
> > > of js warnings. It seems to be linting for some very weird things, the
> > most
> > > prevalent being "Try to use a single 'var' statement per scope."
> > >
> > > Does anyone know how to turn off this particular warning? I don't
> think
> > it
> > > is useful at all (using more than one var per scope in js is perfectly
> > > reasonable) and is hiding some of the hopefully more valuable
> warnings.
> > >
> > > Thanks!
> > >
> > > - Cassie
> >
> > --
> > Paul Lindner
> > hi5 Architect
> > plindner@hi5.com
> >
>
>
>
> --
> ~Kevin
>
> If you received this email by mistake, please delete it, cancel your mail
> account, destroy your hard drive, silence any witnesses, and burn down the
> building that you're in.
>

Re: Try to use a single 'var' statement per scope.

Posted by Kevin Brown <et...@google.com>.
On Thu, Feb 21, 2008 at 6:03 PM, Paul Lindner <pl...@hi5.com> wrote:

> Here's what's going on:
>
>
> YUI Compressor 2.3.5, 2008-02-08
> --------------------------------
>
> + Added a warning when more than one 'var' statement is used in a single
> scope.
>  Automatic coalescence is extremely complicated, and would be unsafe if
> not
>  done properly.
>
>
> At first I thought it was bogus, but it turns out it's correct.  Try
> running this code and guess what the output is:
>
>  for (var i=0; i< 10; i++) {
>    document.write(i + " ");
>    document.write(" ");
>  }
>  document.write("<br>result is " + i);
>
> 1 2 3 4 5 6 7 8 9
> result is 10
>
>
> Digging deeper I find that javascript's local scope is only local to
> the function.  ... shudder ....


Not quite; it doesn't have a "local" scope, it only has closure scope (and a
function produces a closure). Javascript does not support anonymous scopes
as seen in languages such as java and C++ (what you're really doing when you
put brackets after a control statement). This is the same as in C and most
functional programming languages.

That being said, I disagree with the YUI compressor comment's assertion that
it's difficult, because there are at least two minifiers that I've used that
do it without issue (unfortunately, we can't use them on this project). I'd
love to see support for this added anyway though, as it's also got
performance benefits.


>
>
> On Thu, Feb 21, 2008 at 05:30:02PM -0800, Cassie wrote:
> > When running the shindig server these days we are now getting tons and
> tons
> > of js warnings. It seems to be linting for some very weird things, the
> most
> > prevalent being "Try to use a single 'var' statement per scope."
> >
> > Does anyone know how to turn off this particular warning? I don't think
> it
> > is useful at all (using more than one var per scope in js is perfectly
> > reasonable) and is hiding some of the hopefully more valuable warnings.
> >
> > Thanks!
> >
> > - Cassie
>
> --
> Paul Lindner
> hi5 Architect
> plindner@hi5.com
>



-- 
~Kevin

If you received this email by mistake, please delete it, cancel your mail
account, destroy your hard drive, silence any witnesses, and burn down the
building that you're in.

Re: Try to use a single 'var' statement per scope.

Posted by Paul Lindner <pl...@hi5.com>.
Here's what's going on:


YUI Compressor 2.3.5, 2008-02-08
--------------------------------

+ Added a warning when more than one 'var' statement is used in a single scope.
  Automatic coalescence is extremely complicated, and would be unsafe if not
  done properly.


At first I thought it was bogus, but it turns out it's correct.  Try
running this code and guess what the output is:

  for (var i=0; i< 10; i++) {
    document.write(i + " ");
    document.write(" ");
  }
  document.write("<br>result is " + i);

1 2 3 4 5 6 7 8 9
result is 10


Digging deeper I find that javascript's local scope is only local to
the function.  ... shudder ....


On Thu, Feb 21, 2008 at 05:30:02PM -0800, Cassie wrote:
> When running the shindig server these days we are now getting tons and tons
> of js warnings. It seems to be linting for some very weird things, the most
> prevalent being "Try to use a single 'var' statement per scope."
> 
> Does anyone know how to turn off this particular warning? I don't think it
> is useful at all (using more than one var per scope in js is perfectly
> reasonable) and is hiding some of the hopefully more valuable warnings.
> 
> Thanks!
> 
> - Cassie

-- 
Paul Lindner
hi5 Architect
plindner@hi5.com

Re: Try to use a single 'var' statement per scope.

Posted by Kevin Brown <et...@google.com>.
On Thu, Feb 21, 2008 at 5:30 PM, Cassie <do...@apache.org> wrote:

> When running the shindig server these days we are now getting tons and
> tons
> of js warnings. It seems to be linting for some very weird things, the
> most
> prevalent being "Try to use a single 'var' statement per scope."


This is a legitimate problem, actually. "var" is not a free operation (see
Doug Crockford's javascript language tech talk on google video for details)
. Ideally a compressor or compiler should do this for you automatically and
you wouldn't have to think about it. (dojo does, but YUI and jsmin do not).
You're right that we should be able to disable it when it's getting in the
way of other, more serious issues though.

In this case it looks like the warning is actually coming from jslint
though, not the compressor. I'm not familiar enough with the extension to
know if we can disable individual jslint warnings (the jslint program DOES
support this though, so I'd assume that you could...somehow). Full list of
JSLint checks here: http://www.jslint.com/lint.html

I haven't figured out a way to disable specific warnings yet, but Ideally
I'd want to get away from using the yui compressor and use the codehaus
javascript compressor -- unfortunately, codehaus only has this feature in
their sandbox today and there's no way to automatically depend on it (you
have to check out the source and do a mvn install). The codehaus tool is
supposed to allow you to disable individual warnings.


>
> Does anyone know how to turn off this particular warning? I don't think it
> is useful at all (using more than one var per scope in js is perfectly
> reasonable) and is hiding some of the hopefully more valuable warnings.
>
> Thanks!
>
> - Cassie
>



-- 
~Kevin

If you received this email by mistake, please delete it, cancel your mail
account, destroy your hard drive, silence any witnesses, and burn down the
building that you're in.