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

Filter files using a command line flag #510

Closed
liamappelbe opened this issue Nov 9, 2022 · 9 comments
Closed

Filter files using a command line flag #510

liamappelbe opened this issue Nov 9, 2022 · 9 comments
Labels
good first issue A good starting issue for contributors (issues with this label will appear in /contribute) package:coverage type-enhancement A request for a change that isn't a bug

Comments

@liamappelbe
Copy link
Contributor

Add a command line flag that works like // coverage:ignore-file. It should also be able to handle globs, so that users can ignore all generated files like *.g.dart.

@liamappelbe liamappelbe added the type-enhancement A request for a change that isn't a bug label Nov 9, 2022
@devoncarew
Copy link
Member

I wonder if we should glob *.g.dart by default? Is there value in getting coverage info for generated code? Would excluding it by default be unexpected / surprising for users?

They would have the cli flag to disable the behavior if it was undesired.

@liamappelbe
Copy link
Contributor Author

I think I would find that surprising, if I was a user. In package:wasm I'd want to disable that behavior. I think the distinction is between users who have generated code that was generated by a 3rd party tool (eg protos), or generated by a tool that is part of the package (which is the case in package:wasm). The former case is probably more common, but in the latter case changing this default behavior would be a confusing breaking change.

As for whether we just add a flag to exclude *.g.dart, or add a flag that excludes arbitrary globs, I think it's probably going to be the same amount of work either way, so I'm inclined to just do the more general arbitrary glob approach.

@natebosch
Copy link
Member

I'm in favor of a flag which allows arbitrary globs.

@osa1
Copy link
Member

osa1 commented Nov 10, 2022

How widely use used is *.g.dart format for generated files? We don't use it in protoc_plugin, we use *.pb.dart.

I agree with @liamappelbe that whether I want to skip generated files or not depends on the use case.

  1. If I'm using a code generator (e.g. protoc_plugin) then I want to skip generated files. Testing of generated code should be done by the code generator.
  2. If I'm developing a code generator then I want coverage for generated files as well as I'm testing correctness of those in my package.

In general there will be more of (1) than (2) so ignoring generated files might make sense, but we should make sure code generators use a common suffix like .g.dart for generated files. Currently protoc_plugin does not do that (uses .pb.dart). If not then the default will be useless for some of (2) as well.

Either way we should have a flag for arbitrary globs.

If we ignore some files by default then the design of flags gets a bit more complicated as we will probably also need a flag to not ignore anything by default, or have a flag that is opposite of ignore-file (maybe allow-file).

If we don't ignore by default then one flag for ignoring files will do.

I say we don't ignore by default to keep things simple for now. If we want to ignore some files by default in the future it will be the same breaking change when we add it now.

@iapicca
Copy link

iapicca commented Nov 10, 2022

it would be nice to have a yaml file coverage_options.yaml
(like lints uses analysis_options.yaml)
or even better interact through pubspec.yaml
e.g.:

dev_dependencies:
  coverage: ^100.0.0

coverage:
  ignore:
    - '*.g.dart'
    - '*.pb.dart'

@devoncarew
Copy link
Member

How widely use used is *.g.dart format for generated files? We don't use it in protoc_plugin, we use *.pb.dart.

It's the main convention I believe. IIRC the analysis server relies on that file pattern to know to only report one issue for a missing import, instead of hundreds for the rest of the file (for type not found, ...).

If we had a default pattern here, I would default to that one.

Either way we should have a flag for arbitrary globs. I say we don't ignore by default to keep things simple for now. If we want to ignore some files by default in the future it will be the same breaking change when we add it now.

+1

@stact
Copy link

stact commented Jun 12, 2024

Is this enhancement will be planned? It's an awesome idea to have a yml config as @iapicca shared 💯

@liamappelbe
Copy link
Contributor Author

Is this enhancement will be planned? It's an awesome idea to have a yml config as @iapicca shared 💯

It's not prioritized atm. It's a good first issue though, so contributions are welcome.

@liamappelbe liamappelbe added the good first issue A good starting issue for contributors (issues with this label will appear in /contribute) label Jun 12, 2024
@liamappelbe
Copy link
Contributor Author

dart-archive/coverage#496 added the command line flag. I'll file a separate issue for the yaml config idea.

@mosuem mosuem transferred this issue from dart-archive/coverage Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue A good starting issue for contributors (issues with this label will appear in /contribute) package:coverage type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

7 participants