@agencypmg/design-lint
v0.0.9
Published
Flags code that bypasses the Alli design system and scores how much an app is breaking the system
Maintainers
Readme
@agencypmg/design-lint
Flags code that bypasses the Alli design system and scores how much an app is breaking the system.
It statically scans an app's .ts, .tsx, .js, .jsx, .css, .scss and .less files for patterns that couple to design-system internals or sidestep its tokens and scales, then reports an adherence score from 0 to 100 (100 = clean).
Requires Node >= 18.
Usage
# Report adherence score(s) for one or more apps
npx @agencypmg/design-lint report apps/my-app
# Fail on any violation
npx @agencypmg/design-lint check apps/my-app
# List all rules
npx @agencypmg/design-lint --rulesThe command defaults to report if omitted.
Commands
| Command | Behavior |
| -------- | ---------------------------------------------------------------------------------------------------------------- |
| report | Prints adherence score(s). Exits 0 unless --fail-under is set. |
| check | Exits 1 on any violation, on new violations vs --baseline, or on violations in changed lines with --diff. |
Options
| Option | Description |
| ----------------------- | --------------------------------------------------------------------------------------------------------------- |
| --config <file> | JSON config file (default: ./design-lint.config.json). See Configuration. |
| --baseline <file> | Only fail on violations not present in the baseline. |
| --update-baseline | Write the baseline file from the current state (use with --baseline). |
| --diff <base-ref> | Only violations on lines changed vs the merge-base with <base-ref> are blocking. Run inside the app's git repo. |
| --fail-under <score> | Exit 1 if any app scores below this. |
| --format <fmt> | text (default), json, md, or github (inline PR annotations for blocking violations). |
| --path-prefix <p> | Prefix for annotation file paths when the app is checked out in a subfolder. |
| --comment-file <file> | With --diff: write the PR-comment markdown to <file>: the violations table, or a short "resolved" note when the PR adds none. Line 1 is always the hidden COMMENT_MARKER. |
| --head-sha <sha> | Commit that comment links point to (the PR head). Defaults to GITHUB_SHA, which is the merge commit on pull_request. |
| --color / --no-color| Force or disable ANSI colors. Defaults to TTY detection; honors NO_COLOR / FORCE_COLOR. |
| --verbose | Show detail for every app, not just a single one. |
| --rules | List rules and exit. |
Rules
Rules are split into two tiers. Tier 1 is reaching into the system (coupling to internals, overriding specificity). Tier 2 is bypassing the system's tokens and scales. Weights feed the score.
| Rule | Tier | Weight | What it flags |
| ------------------------ | ---- | ------ | ----------------------------------------------------------------------- |
| reaches-into-internals | 1 | 15 | Selectors targeting .alli-* classes, data-testid or data-*. |
| alli-class | 1 | 15 | Using an alli-* class directly. |
| style-element | 1 | 10 | <style> elements. |
| important | 1 | 5 | !important. |
| arbitrary-selector | 1 | 5 | Arbitrary Tailwind selectors/variants, e.g. [&_div]:p-2. |
| raw-css-file | 2 | 8 | Raw CSS files (files with only @tailwind/@import/@config are OK). |
| arbitrary-color | 2 | 4 | Arbitrary Tailwind colors, e.g. text-[#f00]. |
| hardcoded-color | 2 | 3 | Hardcoded colors in inline styles. |
| arbitrary-value | 2 | 2 | Arbitrary Tailwind values, e.g. text-[11px]. |
| inline-style | 2 | 1 | Inline style props. |
| alli-string | 1 | 0 | Warning only. An alli-* string outside a class prop. Never blocks and never affects the score. |
If a component can't do what you need, request a prop or variant from the design system team instead of working around it.
Scoring
score = 100 / (1 + density / 10)
density = weighted violation points per 1k lines of codeLOC is floored at 1k so tiny apps aren't over-penalised. A score of 100 is clean; about 50 means 10 points per 1k LOC.
Configuration
Create design-lint.config.json in the directory you run the CLI from, or pass --config:
{
"ignore": ["**/generated/**"],
"relaxed": ["**/custom/**"],
"disabledRules": ["alli-class"]
}| Key | Description |
| --------------- | --------------------------------------------------------------------------------------------------------- |
| ignore | Globs (relative to the app root) to skip entirely. |
| relaxed | Globs where violations are reported as exceptions rather than counted. |
| disabledRules | Rule ids to turn off. The design-system repo itself should disable alli-class. |
The scanner always skips node_modules, dist, build, coverage, .git, storybook-static and .next, as well as .d.ts, test, spec and stories files.
Adopting in an existing app
There are two ways to avoid a wall of failures on day one.
Baseline. Snapshot the current violations, then fail only on new ones:
alli-design-lint check . --baseline design-lint.baseline.json --update-baseline
alli-design-lint check . --baseline design-lint.baseline.jsonDiff mode. Only violations on lines changed in the PR are blocking. Everything else is reported but never fails:
alli-design-lint check . --diff origin/mainCI
Copy examples/design-lint.yml to <app-repo>/.github/workflows/design-lint.yml and mark design-lint as a required check in branch protection. It runs in diff mode with --format github, so violations appear as inline PR annotations, and a summary is written to GITHUB_STEP_SUMMARY.
To also post a PR comment, add --comment-file comment.md --head-sha ${{ github.event.pull_request.head.sha }} and post the file. Line 1 is a hidden COMMENT_MARKER (<!-- a360-design-lint -->), so read it with head -1 to find and update the same comment on later runs, and only post a new comment when the lint failed.
Programmatic API
import { scanProject, loadConfig, summarize, renderText } from '@agencypmg/design-lint';
const summary = summarize(scanProject('apps/my-app', loadConfig('design-lint.config.json')));
console.log(summary.score, summary.violations);Also exported: RULES, analyzeSource, classifyClass, isClassProp, DEFAULT_CONFIG, renderMarkdown, renderGithub, renderDiffMarkdown, renderComment, renderResolvedComment, COMMENT_MARKER, toBaseline, newViolations, applyDiff, parseDiff, getChangedLines, inDiff.
Development
npm ci
npm testReleasing
Push a tag like v0.2.0 to publish @agencypmg/[email protected] via .github/workflows/release-design-lint.yml. The workflow runs the tests, sets the package version from the tag and publishes to npm.
