Skip to content

Refactor CSSTree lexer creation#9067

Merged
ybiquitous merged 3 commits into
mainfrom
refactor-get-lexer
Feb 12, 2026
Merged

Refactor CSSTree lexer creation#9067
ybiquitous merged 3 commits into
mainfrom
refactor-get-lexer

Conversation

@ybiquitous

Copy link
Copy Markdown
Member

Which issue, if any, is this issue related to?

Follow-up to #9062

Is there anything in the PR that needs further explanation?

This PR simplifies how to create the CSSTree Lexer instance.

  • Unify getLexer() in lib/utils/getLexer.mjs and getCachedLexer() in lib/lintPostcssResult.mjs
    • Now, getLexer() returns a cached Lexer instance based on config.languageOptions.syntax
  • Add the result.stylelint.lexer property for each rule implementation
  • Remove the internal context.lexer property that is no longer needed

Thus, each rule implementation can access the Lexer instance more easily.

Note that this refactoring idea was inspired by this discussion: #9062 (comment)

This simplifies how to create the CSSTree `Lexer` instance.

- Unify `getLexer()` in `lib/utils/getLexer.mjs` and `getCachedLexer()` in `lib/lintPostcssResult.mjs`
  - Now, `getLexer()` returns a cached `Lexer` instance based on `config.languageOptions.syntax`
- Add the `result.stylelint.lexer` property for each rule implementation
- Remove the internal `context.lexer` property that is no longer needed

Thus, each rule implementation can access the `Lexer` instance more easily.

Note that this refactoring idea was inspired by this discussion:
#9062 (comment)
@changeset-bot

changeset-bot Bot commented Feb 12, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 95cdf35

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

This PR is packaged and the instant preview is available (95cdf35). View the demo website.

Install it locally:

npm i -D https://pkg.pr.new/stylelint@95cdf35

@jeddy3 jeddy3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thank you!

@ybiquitous ybiquitous enabled auto-merge (squash) February 12, 2026 15:01
@ybiquitous ybiquitous merged commit fcd18a5 into main Feb 12, 2026
19 checks passed
@ybiquitous ybiquitous deleted the refactor-get-lexer branch February 12, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants