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

eslint-plugin-rtl-friendly

v0.2.2

Published

Encourage the use of RTL-friendly styles

Downloads

57

Readme

eslint-plugin-rtl-friendly

npm version Downloads/month Tests

With a global audience that includes over 800 million people speaking right-to-left (RTL) languages, catering to RTL readability is crucial for international web apps. The eslint-plugin-rtl-friendly is a linter that helps you write RTL-friendly code.

Why does RTL matter?

You read this text from left to right.

However, texts in RTL languages are read from right to left.

Notice how GitHub's markdown aligns the text to the right. It's not a bug; that's how RTL languages are read.

Let's imagine you're writing code using the old way, and you're, for example, creating a button with text and an icon:

return (
  <button>
    <CheckIcon className="mr-2" />
    <span>{getTranslation('buttons.done')}</span>
  </button>
);

The previous code will work fine for LTR languages, but for RTL languages, the icon will be on the right side of the text, just like the margin (mr-2), which means there won't be any space between the icon and the text and extra space at the beggining of the button.

LTR: [{icon} {text}]
RTL: [{text}{icon} ]

The trick here is to use me-2 instead of mr-2. me-2 stands for margin-inline-end, which means right in LTR languages and left in RTL languages. So, the code should be:

return (
  <button>
    <CheckIcon className="me-2" />
    <span>{getTranslation('buttons.done')}</span>
  </button>
);

Up to this point, this plugin only reports a warning (with auto-fix) when using tailwindcss physical properties like pl-*, mr-*, text-left, left-*, border-l-*, rounded-r-*, etc. Instead, you should use their logical properties like ps-*, ms-*, text-start, start-*, border-start-*, rounded-start-*, etc. You can read more about logical properties or tailwindcss logical properties support or our documentation.

demo

RTL languages:

  • (ar) Arabic - العربية
  • (arc) Aramaic - ܐܪܡܝܐ
  • (ckb) Sorani Kurdish - کوردی
  • (dv) Divehi - ދިވެހިބަސް
  • (fa) Persian - فارسی
  • (ha) Hausa - هَوُسَ
  • (he) Hebrew - עברית
  • (khw) Khowar - کھوار
  • (ks) Kashmiri - कॉशुर
  • (ps) Pashto - پښتو
  • (sd) Sindhi - سنڌي
  • (ur) Urdu - اردو
  • (uz-Af) Uzbeki Afghanistan - ازبیک
  • (yi) Yiddish - ייִדיש

The orange areas on the map below show where RTL languages are spoken. map

Installation

# using pnpm
$ pnpm add -D eslint eslint-plugin-rtl-friendly
# using yarn
$ yarn add -D eslint eslint-plugin-rtl-friendly
# using npm
$ npm install --save-dev eslint eslint-plugin-rtl-friendly

Requirements

  • ESLint
  • Tailwindcss V3.3.0 or higher

Usage

Write your config file such as .eslintrc.js.

module.exports = {
  // ...
  plugins: ['rtl-friendly'],
  // extend our recommended config
  extends: ['plugin:rtl-friendly/recommended'],
  // or add the rules you want to use
  rules: {
    'rtl-friendly/no-physical-properties': 'warn',
  },
  // ...
};

See next.js example

See also Configuring ESLint.

Configs

  • rtl-friendly/recommended ... enables the recommended rules.

Rules

suggestion

| Rule ID | Description | | | :---------------------------------------------------------------------------- | :--------------------------------------- | :---: | | rtl-friendly/no-physical-properties | Encourage the use of RTL-friendly styles | ⭐️✒️ |

Contributing

Welcome your contribution!

TODO:

  • [x] Tailwindcss physical properties to logical properties
  • [ ] Add support for advanced className like cn('pl-2', {...}).
  • [ ] Strict <html> to have dir attribute depending on a codition or whatever detecting the language
  • [ ] Strict <code> to have dir="ltr" to override the parent's direction
  • [ ] in the future maybe throw a warning that letter-spacing doesn't work well with RTL languages to disable it in rtl rtl:*** (NOT SURE)
  • [ ] text-opacity like the previous one
  • Some resources