Is there a built-in way to skip linting on untrack...
# general
h
Is there a built-in way to skip linting on untracked files?
h
Not that I can think of, if they are in some BUILD target, they will be used by Pants.
h
Is there a way to specify files to skip? Then I can just pipe a git command output into it...
h
Ah yes, but then Pants ignores those files for all purposes, not just linting. It's as if they aren't there.
h
Yes - I never intended to put it inside
pants.toml
, though. This is part of a git hook that runs linting, so I can leverage shell scripting to do this ad-hoc This is the janky solution I came up with:
Copy code
unstaged_files="$(git status --short | grep -E '^[ MARC]|\?\?')"
ignore_files=$(echo ${unstaged_files} | awk '{printf("\"%s\",", $2)}')
ignore_builtin='".*/","/dist/","__pycache__","!.semgrep/","!.github/"'
pants \
    --changed-since=origin/master \
    --pants-ignore="[${ignore_files} ${ignore_builtin}]" \
    lint
h
Ah, yes, that should work
😀 1
h
It'd be nice if it was considered to be added as a builtin option Do you guys accept feature requests on GH?
h
We in fact love those
❤️ 1
Well, sorry, we accept feature requests, we love pull requests
😄 1
h
Haha I can go on and try to implement it
Although random PRs tend to be a burden because it's not part of the roadmap yada yada yada
h
That's why it's good to discuss first, which you have!
🙂 1
I think having
--pants-ignore-unstaged
makes sense
As a sibling to
--pants-ignore
h
Yeah they should be mutually exclusive, I guess
h
Not necessarily, they are additive
ignore this and also this
I think we just ignore the union
Otherwise weird things happen
h
I guess we should also consider changing
--pants-ignore-use-gitignore
then, because that and
--pants-ignore
seem to be mutually exclusive atm
h
Are they? Hmm
h
Oh sorry I mixed it up
h
Copy code
`pants_ignore` can be used in tandem with `pants_ignore_use_gitignore`; any rules
            specified here are applied after rules specified in a .gitignore file.
So, yeah, the union
h
Yes, please ignore what I just said
My issue was with not being able to reuse the (very sensible) default value of
--pants-ignore
Anyways, I'll have a look at implementing
--pants-ignore-unstaged
as you mentioned 🙂 Thanks a bunch!
h
There is already some code that abstracts the git interactions in
src/python/pants/vcs
that should be helpful