Skip to content

🐛 CSS @import inside a comment is parsed as a real import (false cycles positive) #1880

Description

@dorshinar

Prerequisites

Reproduction url

https://github.com/dorshinar/knip-css-comment-repro

Reproduction access

  • I've made sure the reproduction is publicly accessible

Description of the issue

knip's CSS import scanner extracts @import '…'; statements textually without stripping /* … */ comments, so an @import that appears only inside a comment is treated as a real dependency edge. When the specifier resolves back to the same file (e.g. via the package's exports map), the new cycles issue type reports a false self-cycle.

Reproduction
theme.css:

/**
* Usage:
* @import '@your-scope/theme/tailwind-theme.css';
*/
@import 'tailwindcss/theme';

package.json:

{ "exports": { "./tailwind-theme.css": "./src/theme.css" } }

Run: knip --include cycles (with rules: { cycles: 'error' }).

Expected: the commented-out @import is ignored; no cycle.
Actual: Circular dependencies (1): src/theme.css → src/theme.css.
Removing the @import line from the comment eliminates the report.

Environment: knip 6.25.0. The same comment-unaware regex scanning is present in the scss/less compilers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions