Openlibrary: Stylelint: Add no-descending-specificity and fix offenders

Created on 15 Sep 2018  ·  9Comments  ·  Source: internetarchive/openlibrary

From the stylelint docs:
"Source order is important in CSS, and when two selectors have the same specificity, the one that occurs last will take priority. However, the situation is different when one of the selectors has a higher specificity. In that case, source order does not matter: the selector with higher specificity will win out even if it comes first.

The clashes of these two mechanisms for prioritization, source order and specificity, can cause some confusion when reading stylesheets. If a selector with higher specificity comes before the selector it overrides, we have to think harder to understand it, because it violates the source order expectation. "

Stylelint (which can be run by using npm install && npm run lint:fix) can detect these if configured with the following:
"no-descending-specificity": true,

Note: there are currently lots of offenders for this rule, so it may be worth waiting until master.less is more manageable (#1092) before attempting this

Checklist

  • [ ] Update .stylelintrc.json
  • [ ] fix any offenders detected via npm run lint:fix
Linting CSS hacktoberfest

Most helpful comment

I just want a t-shirt

All 9 comments

Better to have sooner rather than later... will work on this if nobody else does.

This ones also going to be a bit tricky. There are lots of offenders :-S

Hey @jdlrobson! I'd like to help out with this if you still need it.

We do! Go for it @thefifthisa !

@jdlrobson Great, thanks! Can I know which ones you've already done so I know where to start?

@thefifthisa I'd recommend to start with adding the rule to the existing stylelint config file and making sure you can see the errors locally when you run

npm install
npm run lint:fix

screen shot 2018-10-15 at 4 46 27 pm

I'm seeing lots of errors when I add this rule.

Let's keep the first pull request small and reasonably safe from merge conflicts! As a general rule, I'd recommend disabling the rule at the top of large files which have more than 6 errors [1]. (e.g. static/css/components/header-bar.less and static/css/legacy.less) and focusing on the files which have less problems.

The goal with this linting is to slowly chip away at the CSS and improve it so don't take too much on at a time - focus on the files with 1-6 issues! Otherwise, it will make it harder for you to write and others to review.

Does this make sense?

Let me know if any more guidance needed!

[1] Adding the following line at the top of the file will stop the rule from applying there!

/* stylelint-disable no-descending-specificity */

@jdlrobson Got it, just submitted a PR!

I just want a t-shirt

this can be closed... no-descending-specificity is in the codebase thanks to @thefifthisa :)

Was this page helpful?
0 / 5 - 0 ratings