Skip to content

Feature Request: relative-font-units does not report absolute units inside math functions (clamp(), calc(), min(), max()) #560

Description

@minseonkkim

Environment

ESLint version: v10.10.0
@eslint/css version: v2.0.0
Node version: v22.15.0
npm version: v11.12.1
Operating System: Windows 11

Which language are you using?

stylesheet

What did you do?

eslint.config.js

import css from "@eslint/css";
import { defineConfig } from "eslint/config";

export default defineConfig([
	{
		files: ["**/*.css"],
		plugins: { css },
		language: "css/css",
		rules: { "css/relative-font-units": "error" },
	},
]);

test.css

/* reported (expected) */
.a {
  font-size: 12px;
}
.b {
  font: 12px Arial;
}

/* not reported (unexpected) */
.c {
  font-size: clamp(12px, 2vw, 20px);
}
.d {
  font-size: calc(12px + 1rem);
}
.e {
  font-size: min(12px, 1rem);
}
.f {
  font: clamp(12px, 2vw, 20px) Arial;
}
npx eslint test.css

What did you expect to happen?

The 12px inside clamp(), calc(), and min() in .c.f should be reported. The rule exists to disallow absolute font-size units, and font-size: clamp(12px, 2vw, 20px) still uses px. Fluid typography with clamp() is a very common pattern, so this is a significant gap.

What actually happened?

Only .a and .b are reported. Every declaration whose value is a math function (.c.f) passes silently, even though each one contains 12px.

test.css
  3:14  error  Use only allowed relative units for 'font-size' - rem  css/relative-font-units
  6:9   error  Use only allowed relative units for 'font-size' - rem  css/relative-font-units

✖ 2 problems (2 errors, 0 warnings)

Link to Minimal Reproducible Example

https://stackblitz.com/edit/stackblitz-starters-8rrnybj4?file=eslint.config.js

Participation

  • I am willing to submit a pull request for this issue.

AI acknowledgment

  • I did not use AI to generate this issue report.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

Additional comments

No response

Disclosure: I'm a participant of open source contribution program OSSCA

Activity

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

  • Status
    Feedback Needed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions