invertase / dart_custom_lint

💡 Easily write powerful Dart & Flutter lint rules for your projects or for users of your packages.
https://pub.dev/packages/custom_lint
Apache License 2.0
288 stars 65 forks source link

Get project path or environment #295

Closed Goddchen closed 1 week ago

Goddchen commented 1 week ago

Is your feature request related to a problem? Please describe. I want to implement a custom lint that does some validation for the ticket you are currently working on. To get the ticket, I'd love to simply use something like git branch --show-current. Unfortunately, the custom_lint process is executed in a temp directory, so I do not have access to the Git repo / working directory of the project. Another alternative for me would be to read the Git branch name from an environment variable. But it seems like the custom_lint child process does not inherit its parent environment.

Describe the solution you'd like I'd love to have some way of knowing the project working directory. Or to be able to pass environment variables to the custom_lint process.

Any idea how this could be achieved?

rrousselGit commented 1 week ago

The path of the analyzed file is readily available. You should be able to find the enclosing .git directory from it.

Goddchen commented 1 week ago

Ah, that was totally my bad. I was focusing on somehow grabbing the Git branch name on the plugin level and not on the rule level 🤦‍♂️