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 jest config #38

Closed
sheerun opened this issue Feb 8, 2019 · 7 comments
Closed

Add jest config #38

sheerun opened this issue Feb 8, 2019 · 7 comments
Labels
feedback wanted This issue needs to hear some feedback from the users of lynt.

Comments

@sheerun
Copy link

sheerun commented Feb 8, 2019

React folks often use Jest. I think it would be good to add it's config by default.

I get lots of errors like:

  3:1  'describe' is not defined.  no-undef
  4:3  'test' is not defined.      no-undef

I guess better defaults would be to allow them in test files

@saadq
Copy link
Owner

saadq commented Feb 8, 2019

You can specify any amount of env flags and pass valid ESLint environments with command line arguments or in your config file:

lynt --react --env jest

Doing the above would add support for both react as well as jest variables.

Or are you suggesting that --env jest is provided by default without the need for passing in a flag? I am kind of 50-50 on this. On one hand, it seems like Jest is really ramping up on popularity so this might be a good idea, but on the other it might be a bad idea to always treat describe, it, etc as valid global variables when one isn't using Jest.

There has also been some discussion from people who actually want to import these variables rather than having them be global: jestjs/jest#4473

Curious to hear your/others thoughts on this.

@saadq saadq added the feedback wanted This issue needs to hear some feedback from the users of lynt. label Feb 8, 2019
@sheerun
Copy link
Author

sheerun commented Feb 12, 2019

I guarantee that 90% of react devs are using Jest for testing. Also I think the discussion about these variables going non-global in Jest is not relevant, as status quo for this moment is that they are global and Lynt is supposed to be "Zero configuration by default" :)

@sheerun
Copy link
Author

sheerun commented Feb 12, 2019

Also, I tried node_modules/.bin/lynt test --react --env jest but it still shows "describe is not defined" etc.

@saadq
Copy link
Owner

saadq commented Feb 12, 2019

Hmm, that's strange. I've been testing it out on a couple of my larger projects as well as a new project I just made with create-react-app, and there didn't seem to be those issues.

Example: https://github.com/saadq/issues/tree/master/lynt-jest

I just ran:

create-react-app lynt-jest

And once that was done, in the project I just ran:

npm install -D lynt

Which installed lynt version v0.5.5. I added a describe function call to the default Jest test.

Running lynt without --env jest would result in errors like you described, but they should go away when the env flag is passed:

screen shot 2019-02-12 at 4 50 43 am

Not that it should matter, but could you give a bit of info on whether you have lynt installed globally or as a local project devDependency? And if possible, would you be able to share some code (or even better, a minimal project) which causes this issue?

@sheerun
Copy link
Author

sheerun commented Feb 12, 2019

Hmm suddenly it's working for me as well, I think it's because I've experimented with .lyntrc and made something like this and forgot about it:

{
  "env": {
    "jest": true
  }
}

It seems such .lyntrc is incorrect overrides CLI flag (usually CLI flags have priority over configuration).

@sheerun
Copy link
Author

sheerun commented Feb 12, 2019

(I used such configuration in my .eslintrc)

@saadq
Copy link
Owner

saadq commented Feb 12, 2019

Ah, I see. I currently didn't have tests for both CLI and config files existing simultaneously, so I should definitely add that. I am currently overriding the CLI args with the config file, but I definitely agree it should be the other way around. Opened #44 for this problem.

I think the reason your issue was happening was that the env in a .lyntrc file should be an array of env strings (for example, ['jest', 'browser'] rather than a mapping of env string => boolean. I think I went this way rather than the .eslintrc config style because the programmatic ESLint API requires env to be passed as an array of strings, and I just thought it was simpler overall.

Going to close this out as I think it is currently working, but automatically adding jest support on detection (like react/ts/flow) might be a good idea. For example, if the user has a jest.config.js file or "jest" key in package.json or even if they just have jest installed as a dependency are some things I could look for.

@saadq saadq closed this as completed Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback wanted This issue needs to hear some feedback from the users of lynt.
Projects
None yet
Development

No branches or pull requests

2 participants