-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[css] Add new CPD language #5733
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
Conversation
- Introduced a new PMD module for CSS, including the necessary POM configuration. - Added ANTLR grammar for CSS to support syntax parsing. - Implemented the `CssLanguageModule` and `CssCpdLexer` for code duplication detection. - Created unit tests for the CSS lexer functionality. - Updated the binary distribution to include CSS as a supported language.
Compared to main: (comment created at 2025-07-10 14:42:45+00:00 for 82fec8f) |
Hi @adangel, |
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.
Thanks for the PR!
This looks mostly good. Please fix the small suggestions I've made.
However, I'm unsure how to deal with case sensitivity, as this is not as simple as "CSS is case insensitive". Whether a token is case sensitive or not can probably only be decided after parsing. At the time of lexing, we don't know, whether the identifier is a attribute/property name or a class name/selector.
Maybe we should just remove the method "getImage" from CssCpdLexer and use the default behavior.
The grammar matches some keyword in a case insensitive way (e.g. @import
or @ImPoRt
will result in the same token). Maybe we should just normalize these special tokens?
pmd-css/src/main/antlr4/net/sourceforge/pmd/lang/css/ast/CssLexer.g4
Outdated
Show resolved
Hide resolved
pmd-css/src/main/java/net/sourceforge/pmd/lang/css/cpd/CssCpdLexer.java
Outdated
Show resolved
Hide resolved
pmd-css/src/test/resources/net/sourceforge/pmd/lang/css/cpd/testdata/literals.txt
Outdated
Show resolved
Hide resolved
pmd-css/src/test/resources/net/sourceforge/pmd/lang/css/cpd/testdata/literals.txt
Outdated
Show resolved
Hide resolved
pmd-css/src/test/resources/net/sourceforge/pmd/lang/css/cpd/testdata/literals.txt
Outdated
Show resolved
Hide resolved
Co-authored-by: Andreas Dangel <andreas.dangel@adangel.org>
Co-authored-by: Andreas Dangel <andreas.dangel@adangel.org>
@tprouvot There is currently a build failure:
Could you pleas fix this by adding css to the list here: pmd/docs/_plugins/jdoc_namespace_tag.rb Lines 102 to 109 in a329149
Also, how should we handle now the case sensitivity or insensitivity? Ignoring case in general looks wrong to me. |
Hi @adangel |
Hi @adangel, |
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.
Thanks, looks good!
Merge pull request #5733 from tprouvot:feat/addCSStoCPD
Thanks for the guidance @adangel 🙏 |
Hi @adangel Did the documentation was updated ? https://pmd.github.io/pmd/pmd_userdocs_cpd.html#supported-languages |
The release has not been published yet. It will be part of PMD 7.16.0, to appear at the end of this month. (I'm not sure there is a snapshot documentation website, @adangel?) |
Thanks for your response @oowekyala 👍 |
So, https://pmd.github.io/pmd/pmd_userdocs_cpd.html#supported-languages is actually the snapshot version (like https://docs.pmd-code.org/snapshot/pmd_userdocs_cpd.html#supported-languages or from this PR https://pull-requests.pmd-code.org/pr-5733/82fec8fb51f498d86d05f3ba600a445bd4a6df6f/docs/pmd_userdocs_cpd.html#supported-languages ) So, you found a problem: CSS is not listed there, because it was not added there: https://github.com/pmd/pmd/blob/main/docs/pages/pmd/userdocs/cpd/cpd.md CSS appears in the left menu however: https://docs.pmd-code.org/snapshot/pmd_languages_css.html and on this (generated) site: https://docs.pmd-code.org/snapshot/tag_CpdCapableLanguage.html Probably we should just point to the latter page instead of maintaining the list manually in cpd.md. |
instead of maintaining another list of languages Refs pmd#5733 (comment)
will be fixed via #5911 |
Describe the PR
As discussed here, this PR adds CSS as a new language for CPD.
Ready?
./mvnw clean verify
passes (checked automatically by github actions)