Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

jshint error - es6 default params #76

Closed
brancusi opened this issue Sep 5, 2015 · 2 comments
Closed

jshint error - es6 default params #76

brancusi opened this issue Sep 5, 2015 · 2 comments

Comments

@brancusi
Copy link

brancusi commented Sep 5, 2015

Hi,

Is it possible to turn off hinting for specific test files?

I am using a utility to help setup some tests and using es6 default args produces the following:

//
var acceptanceSetupAs = function (app, {role='admin', before=function(){}, after=function(){}} = {role:'admin', before:function(){}, after:function(){}}) {
  return {
    beforeEach: function() {
      Ember.run(()=>{
        app = startApp();
        FactoryGuy.clearStore();
        $.mockjax.clear();
        TestHelper.setup();
        authenticateAs(role);
        before();
      });
    },

    afterEach: function() {
      Ember.run(()=>{
        FactoryGuy.clearStore();
        $.mockjax.clear();
        TestHelper.teardown();
        after();
        app.destroy();
      });
    }
  };
};

This is called in tests as follows:

let app;

module('Acceptance | admin visits customer new', acceptanceSetupAs(app, {
  before(){
    //Doing some setup here.
  }
}));

OR

module('Acceptance | admin visits customer new', acceptanceSetupAs(app));

So all the tests run and pass, except the jshint on the utility itself:

JSHint - helpers: helpers/utility-methods.js should pass jshint
    ✘ helpers/utility-methods.js should pass jshint.
    helpers/utility-methods.js: line 6, col 45, Expected ',' and instead saw '='.
    helpers/utility-methods.js: line 6, col 46, Expected an identifier and instead saw 'admin'.
    helpers/utility-methods.js: line 6, col 61, Expected ',' and instead saw '='.
    helpers/utility-methods.js: line 6, col 62, Expected an identifier and instead saw 'function' (a reserved word).
    helpers/utility-methods.js: line 6, col 70, Expected ',' and instead saw '('.
    helpers/utility-methods.js: line 6, col 71, Expected an identifier and instead saw ')'.
    helpers/utility-methods.js: line 6, col 72, Expected ',' and instead saw '{'.
    helpers/utility-methods.js: line 6, col 94, Expected ')' to match '(' from line 6 and instead saw '}'.
    helpers/utility-methods.js: line 6, col 94, 'function closure expressions' is only available in Mozilla JavaScript extensions (use moz option).
    helpers/utility-methods.js: line 6, col 96, Expected an identifier and instead saw '='.
    helpers/utility-methods.js: line 6, col 97, Missing semicolon.
    helpers/utility-methods.js: line 6, col 104, Label 'role' on admin statement.
    helpers/utility-methods.js: line 6, col 113, Expected an assignment or function call and instead saw an expression.
    helpers/utility-methods.js: line 6, col 119, Missing semicolon.
    helpers/utility-methods.js: line 6, col 119, Expected '}' to match '{' from line 6 and instead saw ':'.
    helpers/utility-methods.js: line 6, col 128, Missing name in function declaration.
    helpers/utility-methods.js: line 6, col 132, Expected an identifier and instead saw ','.
    helpers/utility-methods.js: line 6, col 132, Expected an assignment or function call and instead saw an expression.
    helpers/utility-methods.js: line 6, col 133, Missing semicolon.
    helpers/utility-methods.js: line 6, col 140, Label 'after' on function statement.
    helpers/utility-methods.js: line 6, col 148, Missing name in function declaration.
    helpers/utility-methods.js: line 6, col 152, Unrecoverable syntax error. (8% scanned).

So after using the babel repl, and pasting in its output new function as:

var acceptanceSetupAs = function (app) {
  var _ref = arguments.length <= 1 || arguments[1] === undefined ? { role: 'admin', before: function before() {}, after: function after() {} } : arguments[1];

  var _ref$role = _ref.role;
  var role = _ref$role === undefined ? 'admin' : _ref$role;
  var _ref$before = _ref.before;
  var before = _ref$before === undefined ? function () {} : _ref$before;
  var _ref$after = _ref.after;
  var after = _ref$after === undefined ? function () {} : _ref$after;

  return {
    beforeEach: function() {
      Ember.run(()=>{
        app = startApp();
        FactoryGuy.clearStore();
        $.mockjax.clear();
        TestHelper.setup();
        authenticateAs(role);
        before();
      });
    },

    afterEach: function() {
      Ember.run(()=>{
        FactoryGuy.clearStore();
        $.mockjax.clear();
        TestHelper.teardown();
        after();
        app.destroy();
      });
    }
  };
};

All pass just fine.

Any ideas?

Thanks.

@rwjblue
Copy link
Member

rwjblue commented Sep 6, 2015

Firstly, if you update (rm -rf node_modules && npm cache clear && npm install) you should be able to use default args without an issue.

Secondly, you can disable JSHint for sections of code via comments. There is some documentation at http://jshint.com/docs/, but basically it looks like:

// Code here will be linted with JSHint.
/* jshint ignore:start */
// Code here will be ignored by JSHint.
/* jshint ignore:end */

@rwjblue rwjblue closed this as completed Sep 6, 2015
@brancusi
Copy link
Author

brancusi commented Sep 7, 2015

Thank you

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

No branches or pull requests

2 participants