Skip to content

feat: new rule enforce-consistent-important-position#167

Merged
schoero merged 6 commits intomainfrom
feat/enforce-consistent-important-position
Jul 13, 2025
Merged

feat: new rule enforce-consistent-important-position#167
schoero merged 6 commits intomainfrom
feat/enforce-consistent-important-position

Conversation

@schoero
Copy link
Owner

@schoero schoero commented Jul 12, 2025

Recommended Position

// ❌ BAD: with option { "position": "recommended" }
<div class="!text-red-500 hover:!bg-blue-500"></div>;

New rule enforce-consistent-important-position

// ✅ GOOD: with option { "position": "recommended" }
<div class="text-red-500! hover:bg-blue-500!"></div>;

Legacy Position

// ❌ BAD: with option { "position": "legacy" }
<div class="text-red-500! hover:bg-blue-500!"></div>;
// ✅ GOOD: with option { "position": "legacy" }
<div class="!text-red-500 hover:!bg-blue-500"></div>;

fixes #163

@schoero schoero requested a review from Copilot July 12, 2025 20:58

This comment was marked as outdated.

@schoero schoero requested a review from Copilot July 13, 2025 06:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a new ESLint rule enforce-consistent-important-position that enforces where the Tailwind CSS important modifier (!) appears in class names, supporting both legacy (start) and recommended (end) positions based on the Tailwind CSS version.

  • Introduce shared utilities (important-position.ts + versioned async workers) to compute correct important‐modifier placement.
  • Define the ESLint rule logic and schema in enforce-consistent-important-position.ts.
  • Provide a comprehensive test suite and update documentation/README for the new rule.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/tailwindcss/important-position.ts Core sync function and helpers (getDefaultPosition, getPositionWarning, getWorkerPath)
src/tailwindcss/important-position.async.worker.v4.ts Worker bootstrap for v4 async implementation
src/tailwindcss/important-position.async.worker.v3.ts Worker bootstrap for v3 async implementation
src/tailwindcss/important-position.async.v4.ts Tailwind v4 logic for repositioning important modifiers
src/tailwindcss/important-position.async.v3.ts Tailwind v3 logic for repositioning important modifiers
src/rules/enforce-consistent-important-position.ts ESLint rule definition, option parsing, and integration with util functions
src/rules/enforce-consistent-important-position.test.ts Vitest test suite covering both legacy and recommended positions across variants
docs/rules/enforce-consistent-important-position.md Rule documentation with options, examples, and default behavior
README.md Added the new rule to the rules table
Comments suppressed due to low confidence (2)

src/rules/enforce-consistent-important-position.ts:65

  • [nitpick] The rule description is quite generic. You may want to expand it to briefly mention both legacy and recommended positions for clarity in ESLint docs.
        description: "Enforce consistent important position for classes.",

src/rules/enforce-consistent-important-position.test.ts:300

  • There are no tests validating that a warning is emitted when using recommended position on Tailwind CSS v3 (getPositionWarning). Consider adding a test case to cover that warning behavior.
  it.runIf(getTailwindcssVersion().major <= TailwindcssVersion.V3)(`should use "legacy" as default position when no option is provided in tailwind <= 3`, () => {

@schoero schoero merged commit 20f2ff0 into main Jul 13, 2025
20 checks passed
@schoero schoero deleted the feat/enforce-consistent-important-position branch July 13, 2025 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A rule for preferred position of important modifier

2 participants