Giter VIP home page Giter VIP logo

eslint-plugin-rtl-friendly's Introduction

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:

  • 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

eslint-plugin-rtl-friendly's People

Contributors

ahmedbaset avatar dependabot[bot] avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

eslint-plugin-rtl-friendly's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency eslint to v8.57.0
  • chore(deps): update dependency tailwindcss to ~3.4.0
  • chore(deps): update dependency typescript to v5.4.5
  • chore(deps): update typescript-eslint monorepo to v6.21.0 (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update dependency @semantic-release/github to v10
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency husky to v9
  • chore(deps): update dependency lint-staged to v15
  • chore(deps): update dependency tsup to v8
  • chore(deps): update typescript-eslint monorepo to v7 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/release.yml
  • actions/checkout v3
  • actions/setup-node v2
.github/workflows/test.yml
  • actions/checkout v3
  • pnpm/action-setup v2
  • actions/setup-node v3
npm
package.json
  • @semantic-release/git ^10.0.1
  • @semantic-release/github ^9.0.4
  • @types/eslint ^8.44.2
  • @types/estree-jsx ^1.0.0
  • @types/jest ^29.5.4
  • @types/node ^20.5.4
  • @typescript-eslint/eslint-plugin ^6.4.1
  • @typescript-eslint/parser ^6.4.1
  • eslint ^8.47.0
  • husky ^8.0.3
  • jest ^29.6.4
  • lint-staged ^14.0.1
  • npm-run-all ^4.1.5
  • prettier ^3.0.2
  • rimraf ^5.0.1
  • tailwindcss ~3.3.3
  • ts-jest ^29.1.1
  • ts-node ^10.9.1
  • tsup ^7.2.0
  • typescript ^5.1.6
  • eslint >=5.16.0
  • tailwindcss >=3.3.0
  • node >=8.10.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.