kowainik / stan

🕵️ Haskell STatic ANalyser
https://kowainik.github.io/projects/stan
Mozilla Public License 2.0
563 stars 48 forks source link

How to exclude generated files? #399

Open Lysxia opened 3 years ago

Lysxia commented 3 years ago

I'm using Happy to generate .hs files from .y files, and stan reports errors in the .hs file (notably, Happy-generated files use (!!)) that I would like to exclude from reports.

How can I exclude that file?

Is that currently possible? The problem is that apparently you're supposed to report the path to the .hs file relative to the root of the project, but generated files don't have a stable location. The path to the file shown in the report is the absolute path on my filesystem, going into the dist-newstyle/ directory (see picture). One way would be to have a way to ignore any file whose path ends with MyLib/Parser.hs, rather than matching a relative path exactly.

Screenshot_2020-10-30 Stan Report

vrom911 commented 3 years ago

@Lysxia if I understand you correctly, you need to exclude the whole folder of dist-newstyle? This is possible to do with:

[[check]]
type = "Exclude"
directory = "dist-newstyle/"
filter = "all"
Lysxia commented 3 years ago

Thanks! It seems I have to give the whole prefix, "dist-newstyle/" does not suffice:

directory = "/home/..../mylib/dist-newstyle"

Also this seems overly specific to Cabal. Stack users would then want to exclude .stack-work. It is at the same time quite coarse grained. What do you think of a way to match filepaths by their suffixes, so one could write files = "*/Parser.hs" for instance? I can try to work on a PR.

vrom911 commented 3 years ago

Sure, this sounds like a great idea, and there is a use-case for that. I think we can introduce globs to our configs.

Stan itself is working with the relative paths, so it depends on where you call Stan from (but note, that Stan is also looking for the .cabal file). I assume that that full path with a prefix is some work of the HIE as we are taking the pathname from there, and for generated files, it seems to add the whole prefix 🤔

german1608 commented 1 year ago

I was taking a look at this while working on https://github.com/chshersh/iris/issues/64, and as @vrom911 pointed out, HIE is putting the absolute path in the case of generated files:

Screen Shot 2022-10-03 at 9 16 51 PM

After brainstorming a little bit, I come up with the following ideas. Let me know your thoughts so I can tackle this issue :)

  1. Ignore the files that are in a known set of folders. We could ignore anything that has .stack-work, or .dist-newstyle on it.
  2. ScopeDirectory would also check for the directory with the current working dir preppended to it: https://github.com/kowainik/stan/blob/c8560bd13f9e272a1a83773a06f2112df3ff4550/src/Stan/Config.hs#L212-L225
  3. Add globs to the config, as suggested by @Lysxia