bitter-ability-32190
01/24/2022, 2:09 PMLintResults
and think it's a shame that each linter will have to supply the field, even though they all supply it with the same expression. (There's also the "make linters/formatters easier" camp too)
So I'm wondering if it'd be worthwhile to improve the rule parser to follow call-trees (still doing things "dumb"ly where it makes sense, nothing crazy) to allow for some re-use for this and many other cases.
I don't think it'd be too difficult. 🤔
Thoughts? @witty-crayon-22786curved-television-6568
01/24/2022, 2:20 PMbitter-ability-32190
01/24/2022, 2:22 PM@rule(desc="Format with Black", level=LogLevel.DEBUG)
async def black_fmt(field_sets: BlackRequest, black: Black) -> FmtResult:
return _run_black(field_sets, black, is_lint=False)
joshuacannon@CEPHANDRIUS:~/work/pants$ ./pants help LintResults | grep black
10:08:38.82 [INFO] Initializing scheduler...
10:08:39.20 [INFO] Scheduler initialized.
pants.backend.python.lint.black.rules.black_lint
activated by pants.backend.python.lint.black
curved-television-6568
01/24/2022, 4:10 PM_run_black
a regular function, then?bitter-ability-32190
01/24/2022, 4:10 PMfmt
or lint
template out-of-toolasync def _run_black(
field_sets: BlackRequest,
black: Black,
*,
is_lint: bool,
) -> FmtResult | LintResults:
curved-television-6568
01/24/2022, 4:13 PMhundreds-father-404
01/24/2022, 4:23 PM_run_black
rule doesn't get memoized with the engine. It would be equivalent fwict to copying and pasting (inlining) all that code into both the fmt_black
and lint_black
rules. I'm pretty sure that's okay, only something to be aware of
I like that this allows you to DRY without having to create wrapper types because it's just an async function, not a proper rulebitter-ability-32190
01/24/2022, 4:25 PMI like that this allows you to DRY without having to create wrapper types because it's just an async function, not a proper ruleYeah that's the idea. Add the ability to make helpers, so all your code doesn't have to choose between "inline everything" or "rule overhead"
Do you have a WIP you can post for the parsing change? I'm curious how it works, including whether we follow importsI will once I do a smidge more smoke testing. And yes it follows imports (albeit dumbly)
hundreds-father-404
01/24/2022, 4:26 PMbitter-ability-32190
01/24/2022, 5:53 PM