From 00e716279c499da28c22f22950ec3d3082ced3a2 Mon Sep 17 00:00:00 2001 From: thecalamiity Date: Mon, 27 Oct 2025 16:58:29 +0300 Subject: [PATCH] fix: enforce valid `allow*` values in `prefer-logical-properties` rule --- docs/rules/prefer-logical-properties.md | 24 ++++++++++++++++++++++++ src/rules/prefer-logical-properties.js | 4 ++-- src/rules/relative-font-units.js | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/docs/rules/prefer-logical-properties.md b/docs/rules/prefer-logical-properties.md index b4a28798..465789c2 100644 --- a/docs/rules/prefer-logical-properties.md +++ b/docs/rules/prefer-logical-properties.md @@ -38,6 +38,30 @@ This rule accepts an option object with the following properties: - `allowProperties` (default: `[]`) - Specify an array of physical properties that are allowed to be used. - `allowUnits` (default: `[]`) - Specify an array of physical units that are allowed to be used. +#### `allowProperties` + +Examples of **correct** code with `{ allowProperties: ["margin-left"] }`: + +```css +/* eslint css/prefer-logical-properties: ["error", { allowProperties: ["margin-left"] }] */ + +a { + margin-left: 10px; +} +``` + +#### `allowUnits` + +Examples of **correct** code with `{ allowUnits: ["vw"] }`: + +```css +/* eslint css/prefer-logical-properties: ["error", { allowUnits: ["vw"] }] */ + +a { + margin: 10vw; +} +``` + ## When Not to Use It If you aren't concerned with the use of logical properties, then you can safely disable this rule. diff --git a/src/rules/prefer-logical-properties.js b/src/rules/prefer-logical-properties.js index b5359b97..729a3621 100644 --- a/src/rules/prefer-logical-properties.js +++ b/src/rules/prefer-logical-properties.js @@ -152,14 +152,14 @@ export default { allowProperties: { type: "array", items: { - type: "string", + enum: Array.from(propertiesReplacements.keys()), }, uniqueItems: true, }, allowUnits: { type: "array", items: { - type: "string", + enum: Array.from(unitReplacements.keys()), }, uniqueItems: true, }, diff --git a/src/rules/relative-font-units.js b/src/rules/relative-font-units.js index 7167b223..59d4d585 100644 --- a/src/rules/relative-font-units.js +++ b/src/rules/relative-font-units.js @@ -69,8 +69,8 @@ export default { type: "array", items: { enum: relativeFontUnits, - uniqueItems: true, }, + uniqueItems: true, }, }, additionalProperties: false,