Page MenuHomePhabricator

INVESTIGATION: Add class prefix linting to new-lexeme repository
Closed, DeclinedPublic1 Estimated Story Points

Description

We want to ensure that all the classes in new-lexeme-special-page begin with the prefix snl- (Special:NewLexeme), to avoid collisions with other markup on-wiki. This should be enforced by a linter. Since T301694, we have such linting for selectors in our style sheets (ensuring they start with .snl-), but that doesn’t cover classes that are assigned in the HTML template without being used in a style sheet.

any solution needs to be able to...:

  • check that classes we add to HTML use this prefix

Add to the task created after completion of this investigation:

  • All potential violation to the linting rules are corrected

Event Timeline

It would be nice to ensure not just the snl- prefix, but also other BEM rules (or maybe even ensuring that the class name on the template’s root element matches the element name, i.e. ItemLookup.vue contains class="snl-item-lookup"), but I’m not sure if that’s feasible without too much extra effort, so I didn’t include it in the AC.

Prio Notes:

  • Does not affect end users
  • Can help avoid style rule clashes with other on wiki stylesheets → Affects development efforts
  • Does not affect know process owners
  • Eases onboarding of new / occasional developers to our class naming conventions → Affect external and new developers
karapayneWMDE renamed this task from Add class prefix linting to new-lexeme repository to INVGESTIGATION: Add class prefix linting to new-lexeme repository.May 3 2022, 10:29 AM
karapayneWMDE updated the task description. (Show Details)
karapayneWMDE set the point value for this task to 1.

Note regarding external styles affecting styles within the vue application: This can actually also be circumvented by applying a class to the root node of App.vue and using that class to reset styles in the nested application. We don't have to always inherit all the styles from the wiki environment (especially since the majority of which are actually determined by the wikit components we use)

ItamarWMDE renamed this task from INVGESTIGATION: Add class prefix linting to new-lexeme repository to INVESTIGATION: Add class prefix linting to new-lexeme repository.May 3 2022, 12:08 PM

sprint 9 planning - timeboxed to a half a day

Breakdown Notes:

The goals of this investigation are

  • We have a better idea of how much time and effort this implementation requires
  • We have decided whether to implement this according to the above
  • A task to implement this tool is created if we decided to proceed

Questions to be answered:

  • Is there an existing lint configuration or plugin for this?
  • How much effort is it to write a linter for HTML in a Single File Component in Vue?

How about using an @typescript-eslint/naming-convention prefix rule ?

UPDATE:

This doesn't seem to work since it checks for class names as in javascript classes not html classes. Allowed selectors as reference of what can be targetted using @typescript-eslint/naming-convention.

Tested adding the following code to the .eslintrc.js but this not the correct approach

'@typescript-eslint/naming-convention': ['error', {
			selector: "class",
			format: [ "snake_case" ],
			prefix: [ 'wbl-snl' ]
}],

Moving this task back to To-Do, I believe someone else can offer a better approach.

Declining this; I think we agreed in an informal chat yesterday that this isn’t worth pursuing. (It would very likely have to be implemented as a new eslint plugin, which would need more time than the 4h we assigned to this investigation.)