prefer-class-list
Use class:list directive for conditional or dynamic class names.
astro-doctor/prefer-class-list
Why it matters
Template-literal class composition is error-prone (extra spaces, false-y values leaking). class:list is Astro's idiomatic way to build class strings — it handles objects, arrays, and conditionals correctly.
See the difference
Incorrect
String concatenation / template literals
---
const isActive = true
---
<button class={`btn ${isActive ? 'btn-active' : ''}`}>
Click me
</button>Correct
class:list directive
---
const isActive = true
---
<button class:list={['btn', { 'btn-active': isActive }]}>
Click me
</button>Configure this check
Override the default severity in your ESLint config:
import astroDoctorPlugin from '@santi020k/eslint-plugin-astro-doctor'
export default [
astroDoctorPlugin.configs.recommended,
{
rules: {
'astro-doctor/prefer-class-list': 'error',
},
},
]Or set the severity for CLI scans in doctor.config.ts:
export default {
rules: {
'astro-doctor/prefer-class-list': 'error',
},
}Use 'error', 'warn', or 'off'. The configuration guide covers presets and per-file overrides.
Keep exploring best practices
- no-process-envDisallow process.env in Astro files — use import.meta.env instead.
- prefer-content-collectionsPrefer Content Collections over Astro.glob() or import.meta.glob() for Markdown and MDX files.
- no-legacy-astro-7-experimental-flagsMigrate experimental configuration fields removed or stabilized in Astro 7.
- prefer-env-schemaDefine an Astro env schema for variables documented in .env.example.
- prefer-pnpmUse pnpm consistently and remove competing package-manager lockfiles.
- require-client-router-script-lifecycleInitialize scripts on astro:page-load when using ClientRouter.
- require-content-configAdd a content config when src/content contains entries.
- require-fetch-default-exportRequire a default export from Astro 7 advanced-routing entrypoints.