npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

postcss-ltr-rtl-detect

v1.5.1

Published

Detects properties in your css that influence LTR and RTL layouts

Downloads

125

Readme

postcss-ltr-rtl-detect

PostCSS plugin that detects properties in your CSS that influence LTR and RTL layouts and are not being generated by @mixins or another dynamic way.

item.css

    .item {
        text-align: right;
    }

Console warning:

text-align: right; found on line 2. Use a @mixin to support LTR vs RTL.

item.css - fixing the warnings

    .item {
        /*
        supposing you have a @mixin that handles the alignment "right" or "left"
        following the current layout direction (LTR or RTL)
        */
        @mixin textAlign end;
    }

Done!

Properties detected:
padding, padding-right, padding-left
margin, margin-right, margin-left
border, border-right, border-left left, right
text-align
float

Aggressive Properties detected:
padding-top, padding-bottom, margin-top, margin-bottom, border-top, border-bottom, top, bottom, border,

Usage

All warnings are written to postCSS result.messages.
You'll need a tool to handle them, for example, postcss-reporter.


    postcss() {
        return [
            require('postcss-ltr-rtl-detect'),
            require('postcss-reporter'),
        ];
    }

Options (all optional)

aggressive

Detects properties that don't influence layout LTR RTL like "margin-top".
Type: Boolean
Default: true

aggressiveMsg

Warning shown when an Aggressive Property is found.
Type: string
Default: Use a @mixin to keep consistence on code.

Example

item.css

    .item {
        @mixin margin end, 1rem;
        margin-top: 10%;
    }

Console warning:

margin-top: 10%; found on line 3. Use a @mixin to keep consistence on code.


importantDetect

Detects properties that have !important.
Type: Boolean
Default: false

importantMsg

Warning shown when a unit value is found (unitsDetect: true required).
Type: string
Default: Consider reviewing your code and remove !important rule.

Example

item.css

    .item {
        margin-top: 10%!important;
    }

Console warning:

margin-top: 10%!important; found on line 2. Consider reviewing your code and remove !important rule...


propsDetect

Detects properties that influence ltr | rtl layout.
Type: Boolean
Default: true

propsMsg

Warning shown when a propriety that affects the layout RTL vs LTR is found.
Type: string
Default: Use a @mixin to support LTR vs RTL.

unitsPxDetect

Detects properties that have px value instead of variable.
Type: Boolean
Default: false

unitsRemDetect

Detects properties that have rem value instead of variable.
Type: Boolean
Default: false

unitsEmDetect

Detects properties that have em value instead of variable.
Type: Boolean
Default: false

unitsMsg

Warning shown when a unit value is found (unitsDetect: true required).
Type: string
Default: Consider using a variable.

Example item.css

    .item {
    	border: 1px solid red;
        padding: 15px;
        font-size: 1rem;
    }

Console warning:

border: 1px solid red; found on line 2. Consider using a variable. padding: 15px; found on line 3. Consider using a variable. font-size: 1rem; found on line 4. Consider using a variable.

ignoreNodeModules

Don't show warnings if css file is at node_modules/.
Type: bool
Default: true.


Ignore a specific rule

If for some reason you don't want to ignore the css smell, you can add /* smell-ignore */ as comment on CSS rule.

  • Notice to write /* smell-ignore */ after the rule but before the semicolon ;, otherwise it won't work.

Example item.css

    .item {
    	border: 1px solid red /* smell-ignore */;
        padding: 15px;
    }

Console warning:

padding: 15px; found on line 3. Consider using a variable.


Usage example with some options


    /* activate units detection */
    postcss() {
        return [
            require('postcss-ltr-rtl-detect')({
                importantDetect: true,
                importantMsg: "don't you dare using it",
                unitsPxDetect: true
            }),
            require('postcss-reporter'),
        ];
    }

Contribute

Any doubts or suggestions you may have feel free to create an issue on github repo.

License

MIT Licence