Socket
Socket
Sign inDemoInstall

stylelint-plugin-logical-css

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stylelint-plugin-logical-css

A Stylelint plugin to enforce the use of logical CSS properties, values and units.


Version published
Weekly downloads
9.1K
decreased by-24.38%
Maintainers
1
Weekly downloads
 
Created
Source

🛸 Stylelint Plugin Logical CSS

License NPM Version Main Workflow Status

Stylelint Plugin Logical CSS aims to enforce the use of logical CSS properties, values and units. The plugin provides two rules. But first, let's get set up.

Read more about Logical CSS on MDN

Getting Started

Before getting started with the plugin, you must first have Stylelint version 14.0.0 or greater installed

To get started using the plugin, it must first be installed.

npm i stylelint-plugin-logical-css --save-dev
yarn add stylelint-plugin-logical-css --dev

With the plugin installed, the rule(s) can be added to the project's Stylelint configuration.

{
  "plugins": ["stylelint-plugin-logical-css"],
  "rules": {
    "plugin/use-logical-properties-and-values": [
      true,
      { "severity": "warning" }
    ],
    "plugin/use-logical-units": [true, { "severity": "warning" }]
  }
}

Rules


plugin/use-logical-properties-and-values

This rule is responsible for checking both CSS properties and values. When a physical property or value is found, it will be flagged.

{
  "rules": {
    "plugin/use-logical-properties-and-values": [
      true,
      { "severity": "warning" }
    ]
  }
}
Options

Note: As of v0.13.0, the original disable-auto-fix option has been removed. Please use Stylelint's disableFix option instead.

OptionDescription
ignorePass an array of physical properties to ignore while linting.
{
  "rules": {
    "plugin/use-logical-properties-and-values": [
      true,
      {
        "severity": "warning",
        "ignore": ["overflow-y", "overflow-x"]
      }
    ]
  }
}
Usage
Not Allowed
.heading {
  max-width: 90ch; /* Will flag the use of "width" */
  text-align: left; /* Will flag the use of "left" */
  opacity: 1;
  transition:
    opacity 1s ease,
    max-width 1s ease; /* Will flag the use of 'max-width' */
}
Allowed
.heading {
  max-inline-size: 90ch;
  text-align: start;
  opacity: 1;
  transition: opacity 1s ease, max-inline-size: 1s ease;
}
Supported Properties and Values
Properties for sizing
Physical Property Logical Property
heightblock-size
widthinline-size
max-heightmax-block-size
max-widthmax-inline-size
min-heightmin-block-size
min-widthmin-inline-size
Properties for margins, borders, and padding
Physical Property Logical Property
border-top & border-bottomborder-block
border-top-color & border-bottom-colorborder-block-color
border-top-style & border-bottom-styleborder-block-style
border-top-width & border-bottom-widthborder-block-width
border-left & border-rightborder-inline
border-left-color & border-right-colorborder-inline-color
border-left-style & border-right-styleborder-inline-style
border-left-width & border-right-widthborder-inline-width
border-bottomborder-block-end
border-bottom-colorborder-block-end-color
border-bottom-styleborder-block-end-style
border-bottom-widthborder-block-end-width
border-topborder-block-start
border-top-colorborder-block-start-color
border-top-styleborder-block-start-style
border-top-widthborder-block-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-leftborder-inline-start
border-left-colorborder-inline-start-color
border-left-styleborder-inline-start-style
border-left-widthborder-inline-start-width
border-bottom-left-radiusborder-end-start-radius
border-bottom-right-radiusborder-end-end-radius
border-top-left-radiusborder-start-start-radius
border-top-right-radiusborder-start-end-radius
margin-top & margin-bottommargin-block
margin-topmargin-block-start
margin-bottommargin-block-end
margin-left & margin-rightmargin-inline
margin-leftmargin-inline-start
margin-rightmargin-inline-end
padding-top & padding-bottompadding-block
padding-toppadding-block-start
padding-bottompadding-block-end
padding-left & padding-rightpadding-inline
padding-leftpadding-inline-start
padding-rightpadding-inline-end
Properties for floating and positioning
Physical Property Logical Property
clear: leftclear: inline-start
clear: rightclear: inline-end
float: leftfloat: inline-start
float: rightfloat: inline-end
top & bottominset-block
topinset-block-start
bottominset-block-end
left & rightinset-inline
leftinset-inline-start
rightinset-inline-end
Properties for size containment
Physical Property Logical Property
contain-intrinsic-heightcontain-intrinsic-block-size
contain-intrinsic-widthcontain-intrinsic-inline-size
Other properties
Physical Property Logical Property
(-webkit-)box-orient: vertical(-webkit-)box-orient: block-axis
(-webkit-)box-orient: horizontal(-webkit-)box-orient: inline-axis
caption-side: rightcaption-side: inline-end
caption-side: leftcaption-side: inline-start
overflow-yoverflow-block
overflow-xoverflow-inline
overscroll-behavior-xoverscroll-behavior-inline
overscroll-behavior-yoverscroll-behavior-block
resize: horizontalresize: inline
resize: verticalresize: block
scroll-margin-bottomscroll-margin-block-end
scroll-margin-bottom & scroll-margin-topscroll-margin-block
scroll-margin-leftscroll-margin-inline-start
scroll-margin-left & scroll-margin-rightscroll-margin-inline
scroll-margin-rightscroll-margin-inline-end
scroll-margin-topscroll-margin-block-start
scroll-padding-bottomscroll-padding-block-end
scroll-padding-bottom & scroll-padding-topscroll-padding-block
scroll-padding-leftscroll-padding-inline-start
scroll-padding-left & scroll-padding-rightscroll-padding-inline
scroll-padding-rightscroll-padding-inline-end
scroll-padding-topscroll-padding-block-start
text-align: lefttext-align: start
text-align: righttext-align: end

plugin/use-logical-units

This rule is responsible for checking that logical CSS units are used. Specifically, viewport units like vw and vh which stand for viewport width and viewport height respectively will not reflect different writing modes and directions. Instead, this rule will enforce the logical equivalents, vi and vb.

{
  "rules": {
    "plugin/use-logical-units": [true, { "severity": "warning" }]
  }
}
Options

Note: As of v0.13.0, the original disable-auto-fix option has been removed. Please use Stylelint's disableFix option instead.

OptionDescription
ignorePass an array of physical units to ignore while linting.
{
  "rules": {
    "plugin/use-logical-properties-and-values": [
      true,
      {
        "severity": "warning",
        "ignore": ["dvh", "dvw"]
      }
    ]
  }
}
Usage
Not Allowed
body {
  max-block-size: 100vh; /* Will flag the physical use of viewport "height" */
}

.container {
  inline-size: clamp(
    10vw,
    100%,
    50vw
  ); /* Will flag the physical use of viewport "width" */
}
Allowed
body {
  max-block-size: 100vb;
}
Supported Units

Read about current browser support for logical viewport units.

Physical Unit Logical Unit
cqhcqb
cqwcqi
dvhdvb
dvwdvi
lvhlvb
lvwlvi
svhsvb
svwsvi
vhvb
vwvi

Keywords

FAQs

Package last updated on 23 May 2024

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