Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jshint has problems with .catch #257

Closed
philmerrell opened this issue Jan 31, 2015 · 10 comments
Closed

jshint has problems with .catch #257

philmerrell opened this issue Jan 31, 2015 · 10 comments

Comments

@philmerrell
Copy link

I really appreciate the thought and effort that has gone into this style guide.

I'm running into problems using jshint and some of the examples used in the guide. For instance:

function getCategories() {

      return $http.get(env + 'api/feeds/', {cache: true})
        .then(getCategoriesComplete)
        .catch(getCategoriesFailed);

      function getCategoriesComplete(response) {
        return response;
      }

      function getCategoriesFailed(error) {
        console.log(error.data);
      }

    }

When my grunt process runs jshint I get:
screen shot 2015-01-30 at 9 54 51 pm

A simple workaround is to use bracket notation (ew) for catch, but I personally find this unsavory. I tried providing the recommended .jshintrc settings but had no luck. This could use a little clarification, but it could be user error on my part too.

Thanks!

@johnpapa
Copy link
Owner

im not seeing that ... did you check it against the jshintrc rules I provided in my repos?

@philmerrell
Copy link
Author

I tried using the JSHint settings provided in the JSHint Section, which look to be the same in the ng-demos/modular project, but I still kept getting the same error. If those are the same setting you're using I'm not sure why I'm getting this error and you're not.

After looking a little closer at the JSHint Options, the es5 Setting set to true fixed it for me.

From the Docs:

This option enables syntax first defined in the ECMAScript 5.1 specification. This includes 
allowing reserved keywords as object properties.

If this is something you feel adds value I can submit a PR, but I'm a little hesitant since you're not experiencing the same behavior. There are so many great insights in this style guide. I've benefited from it a ton. So thanks for making this public. Much appreciated.

@johnpapa
Copy link
Owner

johnpapa commented Feb 2, 2015

Yeah, this is odd ... I havent looked deep at it, but I do not get any issues when I copy your exact code into my editor and I do not set the es5 setting at all. Let's keep this open for now and see if others get it

@johnpapa
Copy link
Owner

johnpapa commented Mar 5, 2015

closing due to no other people seeing this

@johnpapa johnpapa closed this as completed Mar 5, 2015
@goliney
Copy link

goliney commented Mar 20, 2015

I have just faced the same issue.


My code:

function (credentials) {
    return DataService.login(credentials)
      .then(loginSuccess)
      .catch(loginError);

    function loginSuccess(response) {}
    function loginError(response) {}
}

My grunt config:

    jshint: {
      src: [ 
        '<%= app_files.js %>'
      ],
      options: {
        curly: true,
        immed: true,
        newcap: true,
        noarg: true,
        sub: true,
        boss: true,
        eqnull: true,
        debug: true
      },
      globals: {}
    },

Version of jshint plugin:

{
  "name": "grunt-contrib-jshint",
  "version": "0.4.3",
...
}

@wardbell
Copy link
Contributor

Were you missing 'use strict;' ?

@goliney
Copy link

goliney commented Mar 23, 2015

@wardbell no, 'use strict;' isn't missing.

@wardbell
Copy link
Contributor

Weird. I dint get this. Old version of jshint?

You might look here: http://jslinterrors.com/expected-an-identifier-and-instead-saw-a-a-reserved-word/

It suggests either the /*jshint es5: true */ or /*jshint -W024 */ directives.

But like John I've never had to do anything special.

@goliney
Copy link

goliney commented Mar 26, 2015

Setting es5: true solved my problem. Thanks a million!
Regarding versions. I use grunt-contrib-jshint 0.4.3, which uses jshint 1.1.0.

@ruionwriting
Copy link

@johnpapa I know this a closed issue but I noticed that ASP.NET MVC bundling also have issues with .catch throwing an error and actually does not menify the code.

How the resulting bundle looks:

/* Minification failed. Returning unminified contents.
(514,18-23): run-time error JS1137: 'catch' is a new reserved word and should not be used as an identifier: catch
...
 */
(all the code here without being minified)

A possible solution would be to change styles Y035 and Y060 to use the regular promises described on the AngularJS official docs:

$http(req).success(function(){...}).error(function(){...});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants