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

return statement flagged as syntax error

Expand Messages
  • octavpo
    I have a statement in one of my functions: return serverInstanceId = response; JSLint flags it as: Expected ; and instead saw = . Unreachable = after
    Message 1 of 10 , Oct 3, 2012
    • 0 Attachment
      I have a statement in one of my functions:

      return serverInstanceId = response;

      JSLint flags it as:

      Expected ';' and instead saw '='.
      Unreachable '=' after 'return'.
      Expected '=' at column 9, not column 33.
      Expected an identifier and instead saw '='.

      It seems it doesn't accept assignments inside return expressions. However assignments are expressions in JS, so this should be a valid statement. I would agree this might be considered bad style, and it could be flagged as such, but that's another matter. The messages indicate it just doesn't accept it as valid syntax. However if I put the assignment in () the messages are gone. So it seems to me this is a bug in JSLint's grammar.

      Thanks,
      Octav
    • douglascrockford
      ... I recommend that you follow JSLint s advice and fix the code that you would agree is bad.
      Message 2 of 10 , Oct 3, 2012
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "octavpo" <octav@...> wrote:

        > I have a statement in one of my functions:
        >
        > return serverInstanceId = response;
        >
        > JSLint flags it as:
        >
        > Expected ';' and instead saw '='.
        > Unreachable '=' after 'return'.
        > Expected '=' at column 9, not column 33.
        > Expected an identifier and instead saw '='.
        >
        > It seems it doesn't accept assignments inside return expressions. However assignments are expressions in JS, so this should be a valid statement. I would agree this might be considered bad style, and it could be flagged as such, but that's another matter. The messages indicate it just doesn't accept it as valid syntax. However if I put the assignment in () the messages are gone. So it seems to me this is a bug in JSLint's grammar.


        I recommend that you follow JSLint's advice and fix the code that you would agree is bad.
      • octavpo
        That doesn t really address my issue. If the Expected messages could be considered advice, the Unreachable = after return message is clearly wrong, as
        Message 3 of 10 , Oct 3, 2012
        • 0 Attachment
          That doesn't really address my issue. If the 'Expected' messages could be considered advice, the "Unreachable '=' after 'return'" message is clearly wrong, as the assignment is very reachable. Besides, why does the advice go away when I put the assignment in parentheses? I don't think that makes it better style. Moreover JSLint stops checking my code right after that line, while if I add parentheses it checks all the way to the end. So it really looks like a bug.

          --- In jslint_com@yahoogroups.com, "douglascrockford" <douglas@...> wrote:
          >
          > --- In jslint_com@yahoogroups.com, "octavpo" <octav@> wrote:
          >
          > > I have a statement in one of my functions:
          > >
          > > return serverInstanceId = response;
          > >
          > > JSLint flags it as:
          > >
          > > Expected ';' and instead saw '='.
          > > Unreachable '=' after 'return'.
          > > Expected '=' at column 9, not column 33.
          > > Expected an identifier and instead saw '='.
          > >
          > > It seems it doesn't accept assignments inside return expressions. However assignments are expressions in JS, so this should be a valid statement. I would agree this might be considered bad style, and it could be flagged as such, but that's another matter. The messages indicate it just doesn't accept it as valid syntax. However if I put the assignment in () the messages are gone. So it seems to me this is a bug in JSLint's grammar.
          >
          >
          > I recommend that you follow JSLint's advice and fix the code that you would agree is bad.
          >
        • douglascrockford
          ... Fix your code.
          Message 4 of 10 , Oct 3, 2012
          • 0 Attachment
            --- In jslint_com@yahoogroups.com, "octavpo" <octav@...> wrote:

            > That doesn't really address my issue. If the 'Expected' messages could be considered advice, the "Unreachable '=' after 'return'" message is clearly wrong, as the assignment is very reachable. Besides, why does the advice go away when I put the assignment in parentheses? I don't think that makes it better style. Moreover JSLint stops checking my code right after that line, while if I add parentheses it checks all the way to the end. So it really looks like a bug.


            Fix your code.
          • John Hawkinson
            douglascrockford wrote on Thu, 4 Oct 2012 ... It would be so easy to explain why this construct is disfavored. It would be so easy to
            Message 5 of 10 , Oct 3, 2012
            • 0 Attachment
              douglascrockford <douglas@...> wrote on Thu, 4 Oct 2012
              at 02:00:02 -0000 in <k4iqj2+rjit@...>:

              > Fix your code.

              It would be so easy to explain why this construct is disfavored.
              It would be so easy to give a link to a web page.
              It would be so easy to be polite.

              Why is it necessary to be rude?

              --jhawk@...
              John Hawkinson
            • douglascrockford
              ... In his original post he stipulated that the code was bad. So we are past explanation here. He refused my advice. I repeated my advice. He can take it or
              Message 6 of 10 , Oct 3, 2012
              • 0 Attachment
                --- In jslint_com@yahoogroups.com, John Hawkinson <jhawk@...> wrote:
                >
                > douglascrockford <douglas@...> wrote on Thu, 4 Oct 2012
                > at 02:00:02 -0000 in <k4iqj2+rjit@...>:
                >
                > > Fix your code.
                >
                > It would be so easy to explain why this construct is disfavored.
                > It would be so easy to give a link to a web page.
                > It would be so easy to be polite.
                >
                > Why is it necessary to be rude?

                In his original post he stipulated that the code was bad. So we are past explanation here. He refused my advice. I repeated my advice. He can take it or leave it. So can you.
              • Rob Richardson
                douglascrockford wrote ... explanation here. He refused my advice. I repeated my advice. He can take
                Message 7 of 10 , Oct 4, 2012
                • 0 Attachment
                  douglascrockford <douglas@... <mailto:douglas%40crockford.com> >
                  wrote
                  >
                  > douglascrockford <douglas@...> wrote on Thu, 4 Oct 2012 at 02:00:02
                  > -0000 in <k4iqj2+rjit@...>:
                  >
                  > > Fix your code.
                  >
                  > It would be so easy to explain why this construct is disfavored.
                  > It would be so easy to give a link to a web page.
                  > It would be so easy to be polite.
                  >
                  > Why is it necessary to be rude?
                  >
                  >In his original post he stipulated that the code was bad. So we are past
                  explanation here. He refused my advice. I repeated my advice. He can take it
                  or leave it. So can you.

                  http://anton.kovalyov.net/2011/02/20/why-i-forked-jslint-to-jshint/
                  http://www.dotnetrocks.com/default.aspx?showNum=802 (17:16 starts a
                  wonderful discussion, but the whole show is great)
                  http://www.hanselminutes.com/332/coneryminutes-1 (12:30 starts a descent
                  sound-byte, but the whole conversation is excellent)
                  http://blogs.hbr.org/bregman/2012/09/how-to-respond-to-negativity.html

                  Douglas,

                  1. I'm sorry you feel the need to be so negative and terse when people are
                  asking for your advice.
                  2. You've definitely reached a great point of knowledge and experience in
                  your career, and others may not have that vision.
                  3. You release some really great tools, and I'm so glad you're helping to
                  enlighten, educate, and build the JavaScript community.

                  Rob
                • Tom Worster
                  There are always going to be stupid people who don t want to get it right. For them it s really good that JSHint is available. -- http://vimeo.com/25606006
                  Message 8 of 10 , Oct 4, 2012
                  • 0 Attachment
                    "There are always going to be stupid people who don't want to get it
                    right. For them it's really good that JSHint is available." --
                    http://vimeo.com/25606006

                    as i've said before, JSLint isn't for everyone.

                    i accept JSLint's preferences over my own because i doubt my own skills
                    and can't be sure who will work on my code in future. it clearly makes no
                    sense for me to argue with JSLint. there's nothing for me to gain from
                    that.

                    on the other hand, a programmer of superlative skill and confidence, who
                    knows that her code will be maintained only by completely reliable
                    programmers, and who has strong feelings about style that differ from
                    those of JSLint -- that programmer has good reason to set their own
                    standards and write their own tools.

                    so, it appears i don't entirely agree with douglas' opening quote. but i
                    think he was not thinking of these preternaturally talented programmers
                    but of another category of people, those that think JSLint is wrong but
                    still want some version of it to give their code its OK.

                    as for polite/rude... i live in boston where traditionally the locals are
                    terse, direct and forthright. it doesn't bother me.



                    On 10/4/12 2:38 PM, "Rob Richardson" <erobrich@...> wrote:

                    >douglascrockford <douglas@... <mailto:douglas%40crockford.com> >
                    >wrote
                    >>
                    >> douglascrockford <douglas@...> wrote on Thu, 4 Oct 2012 at 02:00:02
                    >> -0000 in <k4iqj2+rjit@...>:
                    >>
                    >> > Fix your code.
                    >>
                    >> It would be so easy to explain why this construct is disfavored.
                    >> It would be so easy to give a link to a web page.
                    >> It would be so easy to be polite.
                    >>
                    >> Why is it necessary to be rude?
                    >>
                    >>In his original post he stipulated that the code was bad. So we are past
                    >explanation here. He refused my advice. I repeated my advice. He can take
                    >it
                    >or leave it. So can you.
                    >
                    >http://anton.kovalyov.net/2011/02/20/why-i-forked-jslint-to-jshint/
                    >http://www.dotnetrocks.com/default.aspx?showNum=802 (17:16 starts a
                    >wonderful discussion, but the whole show is great)
                    >http://www.hanselminutes.com/332/coneryminutes-1 (12:30 starts a descent
                    >sound-byte, but the whole conversation is excellent)
                    >http://blogs.hbr.org/bregman/2012/09/how-to-respond-to-negativity.html
                    >
                    >Douglas,
                    >
                    >1. I'm sorry you feel the need to be so negative and terse when people are
                    >asking for your advice.
                    >2. You've definitely reached a great point of knowledge and experience in
                    >your career, and others may not have that vision.
                    >3. You release some really great tools, and I'm so glad you're helping to
                    >enlighten, educate, and build the JavaScript community.
                    >
                    >Rob
                    >
                    >
                    >
                    >------------------------------------
                    >
                    >Yahoo! Groups Links
                    >
                    >
                    >
                  • Rob Richardson
                    Tom, Thanks for the link. That was an incredibly cool video. Thoughts I particularly enjoyed: - Optimize for perfection, not for cleverness - Programs
                    Message 9 of 10 , Oct 5, 2012
                    • 0 Attachment
                      Tom,

                      Thanks for the link. That was an incredibly cool video. Thoughts I
                      particularly enjoyed:

                      - "Optimize for perfection, not for cleverness"
                      - "Programs need to communicate clearly with people"
                      - "I'm not saying it isn't useful, I'm saying there isn't a case where it
                      isn't confusing"
                      - "Confusion must be avoided because confusion creates the condition which
                      creates bugs"
                      - "Clearly communicate intent"
                      - "Forms that hide defects should be considered defects"

                      By the way, you noted it was his opening quote that referenced JSHint, but
                      it actually was the final comment in the video. (42:00) You might want to
                      fix that bug. :D

                      Rob


                      -----Original Message-----
                      From: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] On
                      Behalf Of Tom Worster
                      Sent: Thursday, October 04, 2012 12:39 PM
                      To: jslint_com@yahoogroups.com
                      Subject: Re: [jslint] Re: return statement flagged as syntax error



                      "There are always going to be stupid people who don't want to get it right.
                      For them it's really good that JSHint is available." --
                      http://vimeo.com/25606006

                      as i've said before, JSLint isn't for everyone.

                      i accept JSLint's preferences over my own because i doubt my own skills and
                      can't be sure who will work on my code in future. it clearly makes no sense
                      for me to argue with JSLint. there's nothing for me to gain from that.

                      on the other hand, a programmer of superlative skill and confidence, who
                      knows that her code will be maintained only by completely reliable
                      programmers, and who has strong feelings about style that differ from those
                      of JSLint -- that programmer has good reason to set their own standards and
                      write their own tools.

                      so, it appears i don't entirely agree with douglas' opening quote. but i
                      think he was not thinking of these preternaturally talented programmers but
                      of another category of people, those that think JSLint is wrong but still
                      want some version of it to give their code its OK.

                      as for polite/rude... i live in boston where traditionally the locals are
                      terse, direct and forthright. it doesn't bother me.

                      On 10/4/12 2:38 PM, "Rob Richardson" <erobrich@...
                      <mailto:erobrich%40robrich.org> > wrote:

                      >douglascrockford <douglas@...
                      ><mailto:douglas%40crockford.com> <mailto:douglas%40crockford.com> >
                      >wrote
                      >>
                      >> douglascrockford <douglas@...> wrote on Thu, 4 Oct 2012 at 02:00:02
                      >> -0000 in <k4iqj2+rjit@...>:
                      >>
                      >> > Fix your code.
                      >>
                      >> It would be so easy to explain why this construct is disfavored.
                      >> It would be so easy to give a link to a web page.
                      >> It would be so easy to be polite.
                      >>
                      >> Why is it necessary to be rude?
                      >>
                      >>In his original post he stipulated that the code was bad. So we are
                      >>past
                      >explanation here. He refused my advice. I repeated my advice. He can
                      >take it or leave it. So can you.
                      >
                      >http://anton.kovalyov.net/2011/02/20/why-i-forked-jslint-to-jshint/
                      >http://www.dotnetrocks.com/default.aspx?showNum=802 (17:16 starts a
                      >wonderful discussion, but the whole show is great)
                      >http://www.hanselminutes.com/332/coneryminutes-1 (12:30 starts a
                      >descent sound-byte, but the whole conversation is excellent)
                      >http://blogs.hbr.org/bregman/2012/09/how-to-respond-to-negativity.html
                      >
                      >Douglas,
                      >
                      >1. I'm sorry you feel the need to be so negative and terse when people
                      >are asking for your advice.
                      >2. You've definitely reached a great point of knowledge and experience
                      >in your career, and others may not have that vision.
                      >3. You release some really great tools, and I'm so glad you're helping
                      >to enlighten, educate, and build the JavaScript community.
                      >
                      >Rob
                      >
                      >
                      >
                      >------------------------------------
                      >
                      >Yahoo! Groups Links
                      >
                      >
                      >
                    • Tom Worster
                      the quotes you mention get to the core of the fundamental difference of opinion between JSLint s supporters and critics. the general considerations reflected
                      Message 10 of 10 , Oct 5, 2012
                      • 0 Attachment
                        the quotes you mention get to the core of the fundamental difference of
                        opinion between JSLint's supporters and critics.

                        the general considerations reflected in the quotes are so important that
                        they sweep all my personal style preferences into irrelevance. now that i
                        really accept this (for many years i did not) it just makes no sense for
                        me to take issue with any given rule in JSLint. to truly prioritize
                        quality and then argue for accommodation of ones own style preferences is
                        incoherent.

                        btw: i don't believe i said anything about where in the video douglas'
                        remark about JSHint arises. yes, it is all the way at the end.

                        another that i particularly like:

                        "The contract we have with the machine is that if the program is in any
                        aspect, at any time, and in any way, imperfect with respect to any of its
                        inputs, the computer has license to do anything it wants. And it can often
                        do the worst possible thing, and at a time of its own choosing, which
                        could be the worst possible time. And when that occurs the fault is not
                        the computer's, it is the programmer's. So our programs have to be
                        perfect."



                        On 10/5/12 2:24 PM, "Rob Richardson" <erobrich@...> wrote:

                        >Tom,
                        >
                        >Thanks for the link. That was an incredibly cool video. Thoughts I
                        >particularly enjoyed:
                        >
                        >- "Optimize for perfection, not for cleverness"
                        >- "Programs need to communicate clearly with people"
                        >- "I'm not saying it isn't useful, I'm saying there isn't a case where it
                        >isn't confusing"
                        >- "Confusion must be avoided because confusion creates the condition which
                        >creates bugs"
                        >- "Clearly communicate intent"
                        >- "Forms that hide defects should be considered defects"
                        >
                        >By the way, you noted it was his opening quote that referenced JSHint, but
                        >it actually was the final comment in the video. (42:00) You might want
                        >to
                        >fix that bug. :D
                        >
                        >Rob
                        >
                        >
                        >-----Original Message-----
                        >From: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] On
                        >Behalf Of Tom Worster
                        >Sent: Thursday, October 04, 2012 12:39 PM
                        >To: jslint_com@yahoogroups.com
                        >Subject: Re: [jslint] Re: return statement flagged as syntax error
                        >
                        >
                        >
                        >"There are always going to be stupid people who don't want to get it
                        >right.
                        >For them it's really good that JSHint is available." --
                        >http://vimeo.com/25606006
                        >
                        >as i've said before, JSLint isn't for everyone.
                        >
                        >i accept JSLint's preferences over my own because i doubt my own skills
                        >and
                        >can't be sure who will work on my code in future. it clearly makes no
                        >sense
                        >for me to argue with JSLint. there's nothing for me to gain from that.
                        >
                        >on the other hand, a programmer of superlative skill and confidence, who
                        >knows that her code will be maintained only by completely reliable
                        >programmers, and who has strong feelings about style that differ from
                        >those
                        >of JSLint -- that programmer has good reason to set their own standards
                        >and
                        >write their own tools.
                        >
                        >so, it appears i don't entirely agree with douglas' opening quote. but i
                        >think he was not thinking of these preternaturally talented programmers
                        >but
                        >of another category of people, those that think JSLint is wrong but still
                        >want some version of it to give their code its OK.
                        >
                        >as for polite/rude... i live in boston where traditionally the locals are
                        >terse, direct and forthright. it doesn't bother me.
                        >
                        >On 10/4/12 2:38 PM, "Rob Richardson" <erobrich@...
                        ><mailto:erobrich%40robrich.org> > wrote:
                        >
                        >>douglascrockford <douglas@...
                        >><mailto:douglas%40crockford.com> <mailto:douglas%40crockford.com> >
                        >>wrote
                        >>>
                        >>> douglascrockford <douglas@...> wrote on Thu, 4 Oct 2012 at 02:00:02
                        >>> -0000 in <k4iqj2+rjit@...>:
                        >>>
                        >>> > Fix your code.
                        >>>
                        >>> It would be so easy to explain why this construct is disfavored.
                        >>> It would be so easy to give a link to a web page.
                        >>> It would be so easy to be polite.
                        >>>
                        >>> Why is it necessary to be rude?
                        >>>
                        >>>In his original post he stipulated that the code was bad. So we are
                        >>>past
                        >>explanation here. He refused my advice. I repeated my advice. He can
                        >>take it or leave it. So can you.
                        >>
                        >>http://anton.kovalyov.net/2011/02/20/why-i-forked-jslint-to-jshint/
                        >>http://www.dotnetrocks.com/default.aspx?showNum=802 (17:16 starts a
                        >>wonderful discussion, but the whole show is great)
                        >>http://www.hanselminutes.com/332/coneryminutes-1 (12:30 starts a
                        >>descent sound-byte, but the whole conversation is excellent)
                        >>http://blogs.hbr.org/bregman/2012/09/how-to-respond-to-negativity.html
                        >>
                        >>Douglas,
                        >>
                        >>1. I'm sorry you feel the need to be so negative and terse when people
                        >>are asking for your advice.
                        >>2. You've definitely reached a great point of knowledge and experience
                        >>in your career, and others may not have that vision.
                        >>3. You release some really great tools, and I'm so glad you're helping
                        >>to enlighten, educate, and build the JavaScript community.
                        >>
                        >>Rob
                        >>
                        >>
                        >>
                        >>------------------------------------
                        >>
                        >>Yahoo! Groups Links
                        >>
                        >>
                        >>
                        >
                        >
                        >
                        >
                        >
                        >
                        >
                        >------------------------------------
                        >
                        >Yahoo! Groups Links
                        >
                        >
                        >
                      Your message has been successfully submitted and would be delivered to recipients shortly.