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

Add "env" config to package.json #371

Closed
gsklee opened this issue Jan 6, 2016 · 16 comments · Fixed by standard/standard-engine#58
Closed

Add "env" config to package.json #371

gsklee opened this issue Jan 6, 2016 · 16 comments · Fixed by standard/standard-engine#58

Comments

@gsklee
Copy link
Contributor

gsklee commented Jan 6, 2016

As a continuation of #18, can we add this?

{
  "standard": {
    "env": "mocha"
  }
}

IMHO it's better than either adding /* eslint-env mocha */ to all test files, or adding:

{
  "standard": {
    "globals": ["beforeEach", "describe", "it", ...]
  }
}
@gsklee gsklee changed the title Add Add "env" confit to package.json Jan 6, 2016
@gsklee gsklee changed the title Add "env" confit to package.json Add "env" config to package.json Jan 6, 2016
@dcousens
Copy link
Member

dcousens commented Jan 6, 2016

IMHO, if /* eslint-env mocha */ is a thing, than this is exactly what should be added to all test files.
I don't think blanket application of a mocha env to an entire project is acceptable, though this could be different for other environments.

@rstacruz
Copy link
Member

rstacruz commented Jan 7, 2016

bad, mocha. one of the reasons I don't use mocha anymore. :p

@dmitriz
Copy link

dmitriz commented Jan 15, 2016

@rstacruz What is better than mocha?

@rstacruz
Copy link
Member

I personally prefer tape, but that's just me.

Anyway, IMHO this is most certainly doable. Eslint itself has support for environments defined here: http://eslint.org/docs/user-guide/configuring#specifying-environments. These look particularly useful:

  • browser
  • worker
  • mocha
  • ...

@rstacruz
Copy link
Member

Also, @feross, this might be worth documenting:

/* eslint-env mocha */

...will consider describe/it/beforeEach/etc as predefined globals.

@dcousens
Copy link
Member

I guess if it is basically just a direct pass-through for a common eslint feature, then I'm not against it.

@dcousens
Copy link
Member

Though, IMHO /* eslint-env mocha */ (aka, per-file configuration) is a better pattern than package.json defined configuration.

Make the lame things hard, and the bad things impossible

@rstacruz
Copy link
Member

yes, i agree. there's also the possibility of this:

{
  "scripts": {
    "lint": "standard 'lib/*.js'; standard 'test/**/*.js' --env mocha"
  }
}

@dcousens
Copy link
Member

@rstacruz that I would agree with a lot more than the blanket suggestion.

@dmitriz
Copy link

dmitriz commented Jan 15, 2016

@rstacruz Seems like they require to write this in every single test file:

You always need to require('tape') in test files.

Grows old very fast, imo.

@rstacruz
Copy link
Member

@dmitriz: i know this is off tangent in the conversation now, but that's precisely why I like it. It means you have write your test files in idiomatic JavaScript—no fancy test runners. In practice, it means your tests are runnable on their own (node test/foo.js), and perfectly browserifyable (browserify test/index.js). This opens up the opportunity to do a lot of interesting things:

node test.js     # run in node.js
hihat test.js    # run in electron (hihat is browserify-aware)
budo test.js     # run in browser (budo is, too)
browserify test.js | smokestack -b firefox  # run in headless browser

@dmitriz
Copy link

dmitriz commented Jan 15, 2016

@rstacruz I see, interesting, have you seen ava - that looks similar!

@gsklee
Copy link
Contributor Author

gsklee commented Jan 18, 2016

@rstacruz Interesting info ;-)

@feross
Copy link
Member

feross commented Feb 4, 2016

@rstacruz +1 to tape and being unfancy and explicit.

It's not worth saving one line if you break compatibility with everything. All tooling has to add custom support for mocha and know about the exact list of globals that mocha assumes. Not a good tradeoff.

@feross
Copy link
Member

feross commented Feb 4, 2016

That said, we'll support passing through this option to eslint, like we've done for the other options.

feross added a commit to standard/standard-engine that referenced this issue Feb 4, 2016
So users can specify custom rules.

Works in `package.json`:

```json
{
"standard": {
"env": {
"mocha": true
}
}
}
```

And the command line:

```
standard --env mocha test/*.js
```

For users that need to change the environment across their entire
project, or just for their tests (e.g. with mocha).

Fixes standard/standard#371
@feross
Copy link
Member

feross commented Feb 4, 2016

PR to standard-engine to add support for the --env option: standard/standard-engine#58

Works in package.json:

{
  "standard": {
    "env": {
      "mocha": true
    }
  }
}

And the command line:

standard --env mocha test/*.js

This will be released in standard v6.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants