GithubHelp home page GithubHelp logo

Add jest config about lynt HOT 7 CLOSED

saadq avatar saadq commented on September 25, 2024
Add jest config

from lynt.

Comments (7)

sheerun avatar sheerun commented on September 25, 2024 1

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" :)

from lynt.

sheerun avatar sheerun commented on September 25, 2024 1

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).

from lynt.

saadq avatar saadq commented on September 25, 2024

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.

from lynt.

sheerun avatar sheerun commented on September 25, 2024

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

from lynt.

saadq avatar saadq commented on September 25, 2024

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?

from lynt.

sheerun avatar sheerun commented on September 25, 2024

(I used such configuration in my .eslintrc)

from lynt.

saadq avatar saadq commented on September 25, 2024

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.

from lynt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.