In furthering the development of the prettier plug...
# plugins
i
In furthering the development of the prettier plugin, how can I get the root path of the targets? I ran
./pants -l=debug lint pants-plugins::
and it passes all the python files to prettier but not the markdown file. I want the prettier plugin to operate on all files in a project (BUILD context).
h
What do you mean by "root path"? I want to double check if you mean something different than "source roots": https://www.pantsbuild.org/docs/source-roots
h
Can you show your work-in-progress in a repo? presumably something is filtering to just Python source files
h
Ken and I discussed over VC - the question is ~how to operate on files that aren't "owned" by any target, like a readme.md file. In the short term, the answer is unfortunately that you need to have a target. I suggested adding a new target type like
prettier_sources
or
prettier_files
and doing something like
sources=['**/*'.md]
with it. (The new target type is meant to make it easier for them to differentiate between conventional uses of `files`/`resources` targets vs. their plugin, so if they ever need to evolve this target it's clear what is what.)
h
Hmm, that's a bit unorthodox, why not just use all target types and filter on the suffixes prettier can handle?
prettier
is unusual in that it operates on many languages and file types
So it probably makes sense to just feed it all files (or all files filtered by suffix)
And then can use regular
files/resources
targets
prettier_files
seems wrong to me - "the user wants to feed me to prettier" is not a property of the files themselves
h
why not just use all target types
Actually, that reminds me that currently @incalculable-yacht-75851 is using
SourceFiles
for the
FieldSet
meaning that every target with sources will match I realize now that can eventually cause issues specifically with
fmt
. We run formatters within each language sequentially so they don't overwrite each other, i.e. Python vs Go vs Shell etc. But we run each language in parallel, i.e. Python at the same time as Go. This is why we have that
LanguageFmtTargets
thing For Prettier running on multiple different languages, it's important that it still properly respect this expectation. When you eventually add other JavaScript linters, you'll need to have Prettier use your
JavaScriptLanguageFmtTargets
stuff, otherwise your Prettier implementation will have merge conflicts with the Javascript linters and Pants will error. (If you also wanted Prettier to run on things like markdown files, you could have in addition
MarkdownLanguageFmtTargets
or
FilesLanguageFmtTargets
, for example) Concretely, this will only be a problem once you start having Prettier run on targets that are already being formatted in another "language" - so, you can get away with the current implementation until you add other JavaScript or Markdown linters etc I think Benjy might be right to use `files`/`resources` for now and not add
prettier_files
. Although both approaches seem fine.
i
thanks for this Eric and Benjy. I don't know where we'll land immediately but do know we will evaluate every pants version bump and make sure our plugins don't break other languages. As it sits now, the languages supported by pants don't collide with the languages supported by prettier.
h
We had another pair programming session today and ended up with a good solution!
prettier_sources
generates
file
targets. It allows them to have the default
sources
they want, while still using the core Pants target We also discussed the difference between files vs resources: https://www.pantsbuild.org/docs/resources. For now, they're generating
file
targets, but can change that to be
resource
targets when necessary. And they could model it in a few ways, like adding a field to
prettier_sources
to decide which target type to generate FYI @incalculable-yacht-75851 and @icy-account-9671, when doing that you'll have to update Prettier to say it works with both
FileSource
and
ResourceSource
. Right now, that's not possible to do - we can possibly tweak Pants itself to allow that, or there's a workaround we can help you with
h
Glad there's a solution, but I'm still not convinced
prettier_sources
makes sense as a name of a target type.
These aren't sources that exist for the purpose of having prettier run on them
It seems conceptually wrong to model a source as "belonging" to a formatter
Why are these not just regular files/resources targets?