hyiso / lint_staged

Run linters on git staged files for your Flutter and Dart projects. Inspired by JavaScript lint-staged library
https://pub.dev/packages/lint_staged
Apache License 2.0
6 stars 2 forks source link

Option to exclude files #2

Closed vyshnavsdeepak closed 1 year ago

vyshnavsdeepak commented 1 year ago

I couldn't find documentation or code related to excluding certain directories. Looks like it is missing.

This will be useful in cases where there are generated dart files, eg. In case the project uses google's protocol buffers, there will be dart files generated by the compiler, protoc.

hyiso commented 1 year ago

@vyshnavsdeepak Could you try 0.2.0-dev.0 with glob pattern to exclude the files following the glob syntax

hyiso commented 1 year ago

Closed, if any problem exists with the glob pattern, please create a new issue.

bawahakim commented 5 months ago

@hyiso I also can't exactly find where we should put these globs? Also, these globs only seem to match, not exclude?

hyiso commented 5 months ago

@bawahakim See the glob syntax

If it starts with ^ or !, the construction will instead match all characters not mentioned. For example, test[^a-z].dart will match test1.dart but not testa.dart.

bawahakim commented 5 months ago

How can we apply a set of "include" and "not include"? E.g. I want to include all files in lib/**/*.dart but not in lib/**/__generated__/*.dart? Tried various things like

lint_staged:
  'lib/**/*.dart': dart format --fix && dart fix --apply && dart analyze --fatal-infos
  '!lib/**/__generated__/**/*.dart':

But the generated files still get linted

hyiso commented 5 months ago

Maybe you need to split the configuration into multi glob, as the package glob does not support a simple configuration to apply both include and exclude

just like

lint_staged:
  'lib/{foo, bar,baz}/**.dart': your script
  'lib/xxx/{dirs exclude __generated__}/**/*.dart': your script

You can write test code with package glob to check your configuration