Skip to content

Conversation

TKDev7
Copy link
Contributor

@TKDev7 TKDev7 commented Oct 14, 2025

Prerequisites checklist

What is the purpose of this pull request?

This PR introduces a new rule no-unmatchable-selectors to catch CSS selectors that can never match any elements, helping developers identify dead code and potential mistakes in their stylesheets.

What changes did you make? (Give an overview)

  • Implemented no-unmatchable-selectors rule that detects and reports selectors with impossible :nth-*() pseudo-class formulas
  • Added rule documentation
  • Included test cases covering both invalid patterns and valid patterns

Related Issues

#186

This initial implementation focuses on :nth-*() pseudo-classes, but I plan to expand the rule in follow-up PRs to cover additional scenarios.

Is there anything you'd like reviewers to focus on?

@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Oct 14, 2025
@nzakas nzakas moved this from Needs Triage to Implementing in Triage Oct 21, 2025
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

This is looking really good. Just a couple of notes around documentation.


## Background

An unmatchable selector is one that can never match any element in any document. These are effectively dead code and usually indicate mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

Let's give a couple of examples here.

Comment on lines +42 to +43
const a = Number(node.a);
const b = Number(node.b);
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment here describing what's happening? Either node.a or node.b can be null, in which case Number() converts it into 0. I don't think it's obvious from the code that this is an intentional behavior and not an oversight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Implementing

Development

Successfully merging this pull request may close these issues.

2 participants