New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Remember language when using FileCollector.addFile #3971
Conversation
Generated by 🚫 Danger |
Looking back at the original use case:
The problem here is we want rules from several languages to apply to the same file. Whether you set the language to HTML via I think a better fix would be to fix This makes the change more local to compatibility APIs, so it's easier to tear down in PMD 7. It also fixes This still doesn't help with the original use case. I think solving this requires a concept of "language dialects". VF would be a dialect of HTML, which means all HTML rules also apply to VF files. The change would apply here:
Instead of checking for equality we would check |
Ok, there are more use cases - I didn't notice the "the same file should be analyzed as two distinct languages". To be honest - this sounds very weird. I can understand, that one file can contain two languages (embedded), but the whole thing is only one (primary?) language at all times. Do I miss something? This PR is only really trying to fix #3970 and nothing else.
Maybe - I tried to be minimally invasive and just make the existing API work without adding more APIs (e.g. changing DataSource). I might have a look at this, but can't promise when - probably not for 6.46.0, time is not on my side.
True, this suffers from the same problem, that the language is ignored when converted into DataSource. Just to reiterate, why forced-language is something different than I implemented here: Anyway: What we IMHO should try to concentrate here on is these two API calls, which don't work as promised:
|
The language might be a kind of another language (a dialect). Eg a This could also be useful for Visualforce as it's a dialect of HTML, but the parsers are different, so this is not an easy fix for #3952 (as I initially suggested here).
Fair enough. Let me know if I can help, but I think postponing it isn't a problem
Thanks for the explanation, it makes sense now |
in order to support FileCollector.addFile with language Fixes pmd#3970
I've reworked this now to use DataSource to transport the languageVersion of the files added via FileCollector.addFile. The new interfaces classes are all internal API, so it should be transparent to any public API. Note: on PMD 6, there is currently no public way to create a TextFile - other than implementing the interface. Since LanguageAwareDataSource is also internal API, it's probably not possible to use |
...core/src/main/java/net/sourceforge/pmd/util/datasource/internal/LanguageAwareDataSource.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Clément Fournier <clement.fournier76@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
Describe the PR
Related issues
html
#3952Ready?
./mvnw clean verify
passes (checked automatically by github actions)