PoC: Stop importing bare stylelint in rule files - #245
Draft
bartveneman wants to merge 1 commit into
Draft
Conversation
Every rule only used the bare `stylelint` default export to reach `createPlugin` and three `utils` functions (report, ruleMessages, validateOptions). That default export resolves to stylelint's main entry point, which statically pulls in standalone.mjs and everything behind it (globby, cosmiconfig, write-file-atomic, ...) - fine for stylelint's own CLI, but it means anything that deep-imports these rule modules for a non-Node target (e.g. bundling stylelint's linting core for the browser) drags all of that in too, even though none of it is ever used. `createPlugin` is a two-line function, and the three `utils` functions used live under stylelint's public `./lib/utils/*` export. src/utils/stylelint.ts now re-implements/re-exports just those directly, and every rule imports from there instead of `stylelint`. Behavior is unchanged - verified against the full test suite and a smoke run of the built package through the real stylelint.lint().
Contributor
|
| 📦 Package | 📏 Base Size | 📏 Source Size | 📈 Size Change |
|---|---|---|---|
| @projectwallace/stylelint-plugin | 28.6 kB | 28.7 kB | +142 B |
Member
Author
|
The Security Audit check is failing on 3 pre-existing high-severity advisories, all transitive through
Checked out (The package-size bot comment above — +142 B — is expected: this trades a one-line Generated by Claude Code |
stylelint in rule filesstylelint in rule files
bartveneman
marked this pull request as draft
August 20, 2026 06:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
stylelintdefault export (import stylelint from 'stylelint') to reachcreatePluginand threeutilsfunctions (report,ruleMessages,validateOptions). That default export resolves to stylelint's main entry point, which statically pulls instandalone.mjsand everything behind it (globby,cosmiconfig,write-file-atomic, ...) — fine for stylelint's own CLI, but dead weight for anyone deep-importing these rule modules.stylelintspecifier to a hand-rolled shim just to work around this package. With this change that shim is no longer necessary — the plugin is browser-safe by construction.createPluginis a two-line function, and the threeutilsfunctions actually used live under stylelint's public./lib/utils/*export.src/utils/stylelint.tsnow re-implements/re-exports just those directly, and every rule imports from there instead ofstylelint.lib/utils/*paths exist in both stylelint 16 and 17 (the peer range).Test plan
npx vitest run— 921 tests pass, unchangednpx tsc --noEmit— clean (addedsrc/utils/stylelint-internals.d.tsfor the deeplib/utils/*imports, same reasoning as stylelint's own.d.tspinning)npx oxlint -D perf/npx oxfmt --check— cleannpx tsdown+publint— clean build; confirmeddist/**/*.mjsno longer contains anyfrom "stylelint"bare importstylelint.lint()against known-bad CSS — same warnings as beforeGenerated by Claude Code