Hey all! I'm looking for a way to have the `LintFi...
# general
h
Hey all! I'm looking for a way to have the
LintFilesRequest
ignore anything that's in a project's.
.gitignore
(and thus pants' ignore).
p
You’re likely looking for a solution in the (plugin?) code but I think you can do this globally with
--pants-ignore
Copy code
pants --pants-ignore="$(tr '\n' ',' < .gitignore)"
h
I’m surprised that is not already the case! Can you create a small repo that reproduces the issue?
h
poc.py
Copy code
from typing import Any

from pants.core.goals.lint import LintFilesRequest, LintResult, Partitions
from pants.engine.rules import collect_rules, rule
from pants.option.subsystem import Subsystem
from pants.source.filespec import FilespecMatcher


class PocLintSubsystem(Subsystem):
    name = "poc"
    options_scope = "poc"
    help = "poc"


class PocLintRequest(LintFilesRequest):
    tool_subsystem = PocLintSubsystem


@rule
async def partition_inputs(
    request: PocLintRequest.PartitionRequest,
    subsystem: PocLintSubsystem,
) -> Partitions[str, Any]:
    matched_filepaths = FilespecMatcher(
        includes=["**"],
        excludes=[],
    ).matches(tuple(request.files))

    return Partitions.single_partition(sorted(matched_filepaths))


@rule(desc="poc")
async def do_poc(
    request: PocLintRequest.Batch[str, Any],
    lint_subsystem: PocLintSubsystem,
) -> LintResult:

    return LintResult(
        exit_code=0,
        stdout=", ".join(request.elements),
        stderr="",
        linter_name=PocLintSubsystem.name,
    )


def rules():
    return [
        *collect_rules(),
        *PocLintRequest.rules(),
    ]
Copy code
pants lint --only=poc ::
The stdout contains files that are in my .gitignore.
Oh, it seems only the root
.gitignore
is considered. Not those in subtrees.
To make this actionable: • Is this expected? ◦ If not, what shall we do? • Is this documented? ◦ If not, where shall we add it?
h
Ah yes, that is expected
The issue is that the rust crate for parsing .gitignore doesn’t handle nested .gitignores (or at least didn’t when this bit was implemented)
Looks like it is documented
“Warning: this does not yet support reading nested gitignore files.”
h
That's great to know. I guess I will add another linter that prevents nested gitignores.
h
I would prefer to get this to work, but I remember it being somehow more complicated than you’d think