Skip to content

Support Salesforce LWC Markup #3849

Open

Description

@rsoesemann

Salesforce has 3 UI / Markup dialects from which only 2 can be parsed by PMD.

1) Visualforce: SUPPORTED using own Visualforce language module

Sample code: https://github.com/rsoesemann/salesforce-recipes/blob/master/force-app/main/default/pages/activateAccountButton.page parses using Visualforce language module
Screenshot_2022-03-16_at_11_03_09

2) Aura Component Markup: SUPPORTED

Sample code: https://github.com/rsoesemann/salesforce-recipes/blob/master/force-app/main/default/aura/resultToast/resultToast.cmp parses using Visualforce language module
Cursor_and_PMD_Rule_Designer__v_6_37_0_

3) LWC Component Markup: NOT SUPPORTED

Sample code: https://raw.githubusercontent.com/trailheadapps/lwc-recipes-oss/main/src/modules/ui/app/app.html
doesn't parse. Neighter as XML nor anything else.
Cursor_and_PMD_Rule_Designer__v_6_37_0_-2

Activity

  1. added
    an:enhancement
    on Mar 16, 2022
  2. changed the title [-]PMD to parse and analyse Salesforce LWC markup[/-] [+]Support Salesforce LWC Markup[/+] on Mar 16, 2022
  3. adangel commented on Mar 17, 2022

    @adangel
    Member

    The error message is:

     org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 23; Open quote is expected for attribute "nav-items" associated with an  element type  "ui-navbar".
    

    It's not a valid XML format, e.g.

    <ui-navbar nav-items={navigationItems} ...

    should be

    <ui-navbar nav-items="{navigationItems}" ...

    These curly braces look like this is actually a template (also the "if:true" pseudo attributes later on) and the "XML" is probably not used as-is.
    We would need to preprocess it if we want to use the standard XML parser or would need to write an own parser.
    Preprocessing has the downside, that the analysis happens not on the original source, and it could introduce other errors.

    In the documentation they use "HTML" for the description of this format: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.create_components_html

    "A template is valid HTML with a root tag."

    But HTML is not supported by PMD today (#3521).

  4. rsoesemann commented on Mar 17, 2022

    @rsoesemann
    MemberAuthor

    @adangel thanks for looking into this. So there is still something in this world like not well-formed HTML.
    I know Salesforce LWC is following industry Web Components standards and had hoped this mean well-formed XML. But no...

    Can you elaborate a bit on why PMD never supported HTML? Because there exist no compatible parsers or because nobody contributed it or what else?

    I asked in salesforce/lwc#2749 which format they use and if there is a public parser?

  5. adangel commented on Mar 18, 2022

    @adangel
    Member

    nobody contributed

    Yes, nobody contributed.

    I had a look a https://jsoup.org/ - this is a lot more relaxed for parsing. I could successfully parse the snippet you mentioned via Parser.xmlParser().parseInput(...). Like the DOM from plain java xml, this DOM also doesn't support positional info. But we had created a solution back then already (which involves going through the file once more): DOMLineNumbers

  6. oowekyala commented on Mar 18, 2022

    @oowekyala
    Member

    For PMD 7 I wrote a javadoc parser, which as you know includes HTML. This supports position information correctly, maybe we could extract it. I like Jsoup, but its API also allows mutating everything, which PMD rules shouldn't be doing.

  7. niteshCopado commented on Mar 6, 2024

    @niteshCopado

    Hi @rsoesemann @adangel Will there be a plan for PMD to support LWC?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    an:enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions