wardbell / bardjs

Spec helpers for testing angular v.1.x apps with Mocha, Jasmine and QUnit
MIT License
178 stars 34 forks source link

Missing plugin for ESLint #39

Open santiph opened 8 years ago

santiph commented 8 years ago

Is there any way to integrate bardjs to ESLint?

mikeerickson commented 8 years ago

@santiph At what capacity are you thinking Bard should contain ESLint support? Seeing as you can lint just about anything you want (and also exclude) not sure what you are looking for?

rglepper commented 8 years ago

@mikeerickson For example, If no-undef: "error" and you inject an application component using Bard, when you use it on your tests, ESLint throws a linting error. This can be avoided by declaring the vars on a global comment at the top of the file, so is no big deal, but it would be great if ESLint recognised the components injected by Bard.

mikeerickson commented 8 years ago

Ah, this is because it is a global variable. You can also fix as

/*global error*/

Or, in your package.json

  "eslintConfig": {
...
    "globals": {
      "error": true
    }
  },
rglepper commented 8 years ago

@mikeerickson I have tried what you suggest, and it doesn't seem to change anything. Maybe I did't get my message across, let me show you an example:

/* eslint-env mocha */
/* eslint no-undef:2 */
/* global error */

describe('example', function() {
    beforeEach(function() {
        bard.appModule('app.module');
        bard.inject('exampleService');
    });

    it('should do something', function() {
        exampleService.someMethod();
    });

});

'exampleService' is not defined (no-undef)

That's what I mean, does it make sense?

I think it would be very nice if there was a Bard plugin for ESLint so that injected components are recognised as defined. As I said before, the way around it is to declare the injected component as a global /* global exampleService */ but it sort of misses the whole point for using Bard.

mikeerickson commented 8 years ago

@rglepper So in your case, if you apply

/* eslint no-undef: 0 */

Then it would take care of your issue (no?) I hear what you are saying, but creating a specific bard-eslint-plugin to workaround these types of eslint warnings / errors is sort of out of the scope when specific rules outside of bards control (ie your own choosing) the no-undef switch would do the trick

If I am still missing your point and you feel a bard-eslint-plugin would make additional sense, please let me know.

santiph commented 8 years ago

I was expecting a better solution than copy/pasting this on every test file: /*global bard $controller $httpBackend $q $rootScope */

mikeerickson commented 8 years ago

You can again apply this in your package.json as follows

  "eslintConfig": {
...
    "globals": {
      "error": true,
      "$controller": true,
      "$httpBackend": true,
      "$rootScope": true
    }
  },

This way, you don't have to apply to each of your test files.

mikeerickson commented 8 years ago

@santiph See previous message...