Skip to content

New Rule: use-logical #13

Open
Enhancement
@NateRadebaugh

Description

Rule details

Enforce the usage of Logical Properties and Values in CSS. Physical dimensions and directions are described left to right and top to bottom, while their logical counterparts are described start to end and inline or block.

What type of rule is this?

Warns about a potential problem

Example code

https://github.com/csstools/stylelint-use-logical

For example, to add spacing before the start of a paragraph, we might use the physical padding-left property.

p {
  padding-left: 2em;
}

Were the content Hebrew or Arabic — flowing right to left — then we might use alternating padding-left and padding-right properties.

p:dir(ltr) {
  padding-left: 2em;
}

p:dir(rtl) {
  padding-right: 2em;
}

Selector weight aside, we can instead use the logical padding-inline-start property.

p {
  padding-inline-start: 2em;
}

Participation

  • I am willing to submit a pull request to implement this rule.

Additional comments

I'm not sure the quirks of the new css parser and context, but my current stylelint configuration for angular projects includes:

{
  "extends": "stylelint-config-standard-scss",
  "plugins": ["stylelint-use-logical"],
  "overrides": [
    {
      "files": ["*.html", "**/*.html"],
      "customSyntax": "postcss-html"
    },
    {
      "files": ["**/*.component.ts"],
      "customSyntax": "postcss-angular"
    }
  ],
  "rules": {
    "csstools/use-logical": [
      "always",
      {
        "except": [
          "min-width",
          "max-width",
          "width",
          "min-height",
          "height",
          "max-height",
          "top",
          "bottom",
          "margin-top",
          "margin-bottom",
          "padding-top",
          "padding-bottom",
          "border-top",
          "border-bottom",
          "border-top-color",
          "border-bottom-color"
        ]
      }
    ]
  }
}

Metadata

Assignees

No one assigned

    Labels

    Projects

    • Status

      Evaluating

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions