css/no-hardcoded-values
Suggest using CSS variables instead of hardcoded values.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
opinionated, nuxt |
No | None |
Applies to: Plain CSS style blocks (scss, sass, less and stylus blocks are skipped).
Bad
The button embeds spacing numbers and a hexadecimal color directly in the declarations.
<style scoped>
.button {
padding: 12px 16px;
color: #174ea6;
}
</style>
Good
The declarations refer to named spacing and color custom properties, so these values can be maintained as tokens.
<style scoped>
.button {
padding: var(--space-3) var(--space-4);
color: var(--color-action-text);
}
</style>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"css/no-hardcoded-values": "warn"
}
},
});
Then run vp run lint.