Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stylelint-use-logical-spec

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stylelint-use-logical-spec

Enforce usage of logical properties and values in CSS

  • 5.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Property Use Logical stylelint

NPM Version

Property Use Logical is a stylelint rule to 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.


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;
}

Similarly, physical horizontal and vertical dimensions are described more succinctly using their logical counterparts.

h1, h2, h3 {
  margin-top: 1em;
  margin-bottom: 1em;
}

blockquote {
  margin-left: 1em;
  margin-right: 1em;
}

/* becomes */

h1, h2, h3 {
  margin-block: 1em;
}

blockquote {
  margin-inline: 1em;
}

Usage

Add stylelint and Property Use Logical to your project.

npm install stylelint stylelint-use-logical-spec --save-dev

Add Property Use Logical to your stylelint configuration.

{
  "plugins": [
    "stylelint-use-logical-spec"
  ],
  "rules": {
    "liberty/use-logical-spec": ("always" || true) || ("ignore" || false || null)
  }
}

Options

always

The "always" option (alternatively true) requires logical properties and values to be used, and the following patterns are not considered violations:

.inset {
  inset: 0;
}

.margin {
  margin-inline-start: 0;
}

.padding {
  padding-inline: 0;
}

.float {
  float: inline-start;
}

.text-align {
  text-align: start;
}

.text-align-ignored:dir(ltr) {
  text-align: left;
}

While the following patterns are considered violations:

.inset {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

.margin {
  margin-left: 0;
}

.padding {
  padding-left: 0;
  padding-right: 0;
}

.float {
  float: left;
}

.text-align {
  text-align: left;
}

ignore

The "ignore" option (alternatively false or null) disables the rule.

Secondary Options

except

The except option ignores reporting or autofixing properties and values matching a case-insensitive string or regular expression.

{
  "rules": {
    "liberty/use-logical-spec": ["always", { "except": ['float', /^margin/i] }]
  }
}

direction

The direction option controls whether left to right or right to left properties and values should be reported or autofixed.

{
  "rules": {
    "liberty/use-logical-spec": ["always", { "direction": "ltr" || "rtl" }]
  }
}

Property and Value Mapping

Assuming left to right directionality:

Positioning

Physical PropertyLogical Property
topinset-block-start
rightinset-inline-end
bottominset-block-end
leftinset-inline-start

margin

Physical PropertyLogical Property
margin-topmargin-block-start
margin-rightmargin-inline-end
margin-bottommargin-block-end
margin-leftmargin-inline-start

Padding

Physical PropertyLogical Property
padding-toppadding-block-start
padding-rightpadding-inline-end
padding-bottompadding-block-end
padding-leftpadding-inline-start

Logical Height and Logical Width

Physical PropertyLogical Property
heightblock-size
min-heightmin-block-size
max-heightmax-block-size
widthinline-size
min-widthmin-inline-size
max-widthmax-inline-size

Border

Physical PropertyLogical Property
border-topborder-block-start
border-top-colorborder-block-start-color
border-top-styleborder-block-start-style
border-top-widthborder-block-start-width
border-bottomborder-block-end
border-bottom-colorborder-block-end-color
border-bottom-styleborder-block-end-style
border-bottom-widthborder-block-end-width
border-leftborder-inline-start
border-left-colorborder-inline-start-color
border-left-styleborder-inline-start-style
border-left-widthborder-inline-start-width
border-rightborder-inline-end
border-right-colorborder-inline-end-color
border-right-styleborder-inline-end-style
border-right-widthborder-inline-end-width
border-top-left-radiusborder-start-start-radius
border-bottom-left-radiusborder-start-end-radius
border-top-right-radiusborder-end-start-radius
border-bottom-right-radiusborder-end-end-radius

border-start-start-radius border-top-left-radius border-start-end-radius border-bottom-left-radius border-end-start-radius border-top-right-radius border-end-end-radius border-bottom-right-radius

Special thanks

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

Keywords

FAQs

Package last updated on 15 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc