Giter Site home page Giter Site logo

Comments (9)

mgtitimoli avatar mgtitimoli commented on May 22, 2024 1

For enforce-min-coverage would be something like this:

module.exports = {
    meta: { ... },
    create: context => ({
       Program: node => {
           // 1. get flow coverage
           // 2. do some math to calculate percentage
           // 3. place it in a const like for example actualCovered :)
           const requiredCoverage = context.options[0];
           if (actualCovered < requiredCoverage) {
               context.report({
                   node: node,
                   message:
                       `Expected coverage to be at least ${requiredCoverage}, ` +
                       `but is: ${actualCovered}`
               });
           }
       }
    })
};

One thing that could be hard to know is if a given file has flow annotation, but I guess you are already doing that, if not, it would be a matter of visiting Comment nodes, and look for flow annotation, and change Program by Program:exit.

from eslint-plugin-flowtype-errors.

jzimmek avatar jzimmek commented on May 22, 2024 1

Thanks @mgtitimoli.

Will add a PR for the readme today. Meanwhile you can use it this way:

yarn add eslint-plugin-flowtype-errors@beta

add the following rule (enforce 50% coverage) to your .eslintrc:

flowtype-errors/enforce-min-coverage: [2, 50]

You are somehow right about 2. It is not a bug, because the default case will never be entered. The coverage function is always file based as of now. I copy/pasted this code part from the existing collect function which can also be invoked on a global level without any specific file. Will clean this up.

from eslint-plugin-flowtype-errors.

amilajack avatar amilajack commented on May 22, 2024

I have used nuclide before but I don't remember seeing something like a min flow types coverage check. Can you send me a screenshot of that? That might help me understand this more. I also think that enforce-min-coverage should be a separate tool. eslint is primarily used for reporting errors in specific lines of code. I think a better solution would add the flow-coverage-report checker in your lint script:

{
  "scripts": {
    "lint": "flow-coverage-report --min-coverage=50% && eslint ."
  }
}

Thoughts on this?

from eslint-plugin-flowtype-errors.

mgtitimoli avatar mgtitimoli commented on May 22, 2024

Sure, here is a screenshot so you can see what I'm talking about

image

As you can see, they don't have a min flow types coverage, what they do have is a feature that on hover shows a tooltip where they tell you the percentage covered by flow, and in addition if you click on it, then it toggles a feature that underlines all the code sections that are not covered.

The idea would be to replicate this behavior, and control the error level used with display-not-covered rule, I know in my previous post I wrote that it should be a conf value, but now that I think it better, it could also be a rule and use its level to control how all the parts that are not covered by flow are shown (as errors, warnings, or disable them).

In addition to this and going back to the other idea I mentioned (the one about enforce-min-coverage), one alternative would be to use Program node type, and run the correspondent flow command to get the coverage analysis and then do some math to get the percentage and contrast it with the value specified in the rule config, and in case it's below the specified value use the context parameter received in node visitor function, to rise the proper feedback, error/warning, so at the end you would run this rule once per file (Program node).

I hope I have explained better what I think.

from eslint-plugin-flowtype-errors.

amilajack avatar amilajack commented on May 22, 2024

I see. How about making a PR for this? The code base is very small so its pretty easy to navigate. Also I'm a bit busy at the moment so it may take a while before I get around to looking over and doing this. Thanks!

from eslint-plugin-flowtype-errors.

jzimmek avatar jzimmek commented on May 22, 2024

Hi @amilajack,

I put together a enforce-min-coverage rule:
https://github.com/jzimmek/eslint-plugin-flowtype-errors

Not sure how you want this to be implemented into the existing codebase, so I tried to modify a minimum of existing code. Some code could be further unified.

I am still struggling with the testing infrastructure. Seems like it is tightly focused on the collect functionality - which made total sense till now ;-)

The enforce-min-coverage rule takes the required coverage (as percentage) as an option:

...
  rules:
    strict: 0
    flowtype-errors/show-errors: 2
    flowtype-errors/enforce-min-coverage:
      - 2
      - 50
...

Please let me know what I should change / enhance so you would consider a pull request.

from eslint-plugin-flowtype-errors.

amilajack avatar amilajack commented on May 22, 2024

@jzimmek would be awesome if you could PR this! 🎉

from eslint-plugin-flowtype-errors.

jzimmek avatar jzimmek commented on May 22, 2024

#84

from eslint-plugin-flowtype-errors.

mgtitimoli avatar mgtitimoli commented on May 22, 2024

Nice job @jzimmek!

Correct me if I'm wrong, but I believe there are two little details missed on the PR

  1. Add a section in the README showing how to use the rule
  2. There is a bug here (shouldn't be stdout = childProcess.spawnSync(getFlowBin(), ['coverage', '--json']).stdout;?)

Thanks again for taking the time to do this 🙂

from eslint-plugin-flowtype-errors.

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.