Skip to content
gholtzapPublic

About

It should be impossible for AI to make a bad UI.

Resources

Stars

608 stars

Watchers

0 watching

Forks

Repository files navigation

lintapple logo

lintapple

It should be impossible for AI to make a bad UI.

A UI linter for web pages. Run it from your terminal or Playwright tests to check rendered pages against fixed design rules. The optional source command checks design system use in your code through ESLint and @shadcn/lint.

npm · Demo

Page checks include open shadow roots. Finding selectors use Playwright's >> :scope > path to name elements inside them. Native CSS selectors in policies still follow each root's CSS scope. Closed shadow roots are not accessible to the checker.

Install

Requires Node.js 22 or later. Run in your app’s project directory:

npm install -D lintapple && npx lintapple init

This creates ui-policy.json and a lint:ui script. Existing settings are kept. Set the fonts and text sizes in ui-policy.json to match your app. Set the app URL in the lint:ui script; the default is http://localhost:3000.

Use

Start your app, then run:

npm run lint:ui

Text reports group repeated problems and list their states, screen sizes, and themes. The JSON report keeps every finding and adds a summary with counts by rule and groups with all measurements. A group means the same rule, element, expected value, interaction phase, document, and frame path. Measured values can differ between occurrences. Confirmed failures and unresolved checks have separate counts. Unresolved checks require review and still exit with code 1. The CLI writes the active font policy to stderr before the check. A font mismatch means the page differs from that policy. Each finding includes the rule, element, measured value, and suggested fix. Exit codes: 0 passed, 1 findings, 2 check did not finish.

To check another URL or save a JSON report:

npx lintapple http://localhost:3000 --json

For a page that loads asynchronously, add --ready '[data-app-ready]' with a selector that is visible when the page is ready.

Check source code

lintapple <url> checks the rendered page. lintapple source reads source files and runs the project's enabled shadcn/* rules through ESLint. It does not start a browser.

To try the examples from this repository:

npm ci
npm run source:example
npm run source:example:good

The first example reports raw colors and arbitrary spacing, and exits with code 1. The corrected example exits with code 0. Edit examples/source/src/bad.tsx and run the first command again to try a fix.

For your own React and Tailwind v4 project, install the source tools:

npm install -D eslint @shadcn/lint @typescript-eslint/parser

Use ESLint 9.30 or later in major version 9 or 10. Each tool's Node.js requirements also apply. The examples use ESLint 9 to support Node.js 22.0. ESLint 10 requires Node.js 22.13 or later on that release line.

Add the following block to your existing ESLint flat configuration. If you have no configuration, save it as eslint.config.mjs. Keep your existing parser setup if it already supports TSX.

import { plugin as shadcn } from '@shadcn/lint';
import tsParser from '@typescript-eslint/parser';

export default [{
  files: ['**/*.{ts,tsx}'],
  languageOptions: {
    parser: tsParser,
    parserOptions: { ecmaFeatures: { jsx: true } },
  },
  plugins: { shadcn },
  rules: {
    'shadcn/no-raw-colors': 'error',
    'shadcn/no-arbitrary-values': 'error',
    'shadcn/require-static-classes': 'error',
  },
}];

Then run:

npx lintapple source src
npx lintapple source 'src/**/*.tsx' --json

Paths default to the current directory. Quote globs so ESLint can expand them. --config path selects an ESLint configuration for this command. Source rules stay in ESLint configuration; ui-policy.json is only for browser checks. Normal lintapple init still sets up browser checks.

Only rules registered under shadcn/* run. Other ESLint rules still need your normal lint command. The source tools are optional and are not installed by Lintapple. Use shadcn/lint's configuration guide to connect your theme and components, or enable component rules such as no-restyle.

Set tailwind.css in your project's components.json when the app has more than one CSS entry point. Use its existing component alias. For example:

{
  "tailwind": { "css": "src/app/globals.css" },
  "aliases": { "ui": "@/components/ui" }
}

The alias must resolve through the project's TypeScript paths or package exports. For theme packages such as Kumo, add settings: { shadcn: { themeImports: ['^@cloudflare/kumo/'] } } to the ESLint block. Relative theme imports are read by the source engine. Lintapple uses the engine's public project API to report the selected theme; it does not implement theme discovery.

Text and JSON reports list checked files, enabled rules, the ESLint config, selected theme, and engine and plugin versions. They also list files without design checks. JSON keeps native ESLint messages and suggestions and includes diagnostics, errors, and status. Upstream setup warnings produce an incomplete result. Missing themes produce an incomplete result for token rules.

Suggestions are unverified and are never applied. Check the result in the browser before accepting a replacement. For example, replacing text-[14px] with text-product-body can change line height. A rem value also depends on the app's root font size. ESLint ignores and inline suppressions apply.

Exit codes: 0 means the enabled rules passed on the listed files; 1 means findings, including warnings; 2 means the check could not finish. Parser errors, missing setup, and a scan with no files that have design rules are not passes. Files listed as skipped have no design-check coverage. Configuration and startup errors go to stderr, including with --json.

For Vue, use the existing vue-eslint-parser setup and enable the component rule in ESLint:

npm install -D vue-eslint-parser
import vueParser from 'vue-eslint-parser';

// Add this block to the configuration above.
{
  files: ['**/*.vue'],
  languageOptions: { parser: vueParser, parserOptions: { parser: tsParser } },
  plugins: { shadcn },
  settings: { shadcn: { componentImports: ['^@/components/ui/'] } },
  rules: { 'shadcn/no-restyle': ['error', { allow: ['layout'] }] },
}

With this rule, <Button size="sm" class="px-8">Save</Button> reports a padding override. <Button size="sm">Save</Button> passes. The runnable Vue pair is in examples/source/src/{bad,good}.vue. Run lintapple source src/bad.vue from the example directory. React and Vue use the same command; their ESLint parsers own the syntax. See the upstream Vue guide for auto-imports and wrapper support.

This version is verified with React/TSX and Vue templates, Tailwind v4, @shadcn/lint 0.2.5, and ESLint 9.39.5 and 10.15.0. Other parsers are not yet verified. Standalone CSS, CSS modules, and Vue style blocks are not checked. It does not check component replacement or component count limits. It does not check layout, contrast, or browser behavior. Run the URL command or your Playwright checks for those checks.

Use in Playwright

Add this to an existing test after the page is ready:

import { expectUI } from 'lintapple/playwright';

await expectUI(page, testInfo);

Checks apply to the current document. Child frames are not checked automatically. Each page and state report includes frameCoverage with the checked document and omitted child frames, including nested frames. Frame paths such as main/0/1 identify frames by their child order at the time of the check. To check a frame, call checkPage(frame) separately. This includes cross-origin frames that Playwright can access. A check with no findings does not prove that omitted frames pass.

Findings fail the test and attach a JSON report. If a passing page has omitted frames, the helper attaches a coverage report. The helper reads your ui-policy.json. See the example tests.

Check part of a page

Pass scope to report findings for a component. Each CSS selector must match one visible element in the current document. Add a second selector for a popover or menu rendered in a portal.

await expectUI(page, testInfo, undefined, {
  scope: ['[data-testid="search-trigger"]', '[role="menu"]'],
  identityAttribute: 'data-testid',
});

Checks still use the complete document for clipping, spacing, and accessibility context. A finding is included when its target or related element is within a scope root. Document-level findings are outside a component scope. The attachment includes the selected roots. Coverage totals and the page size limit still apply to the complete document.

Use the same options as the third argument to checkPage(page, policy, options). In this mode, findings include an elementKey when the element has a unique ID or a unique value for the configured data attribute. The data attribute takes priority. Keys in open shadow roots also require a unique key for each host. Use keys to compare findings across states. Findings without a key use the positional selector, which can change when siblings move.

Mark layout elements

Font, contrast, control size, and screen bounds checks work without extra markup. Add these attributes for checks that need layout information:

Attribute Use on
data-ui-stack A group whose child spacing must be checked.
data-ui-actions A button group whose gaps must be checked.
data-ui-container A surface whose button insets must be checked.
data-ui-number A changing number that needs equal digit widths.
data-ui-content A container whose text must stay inside its edges.
data-ui-align="start" A group whose marked elements must align. Use center or end for other alignments.
data-ui-align-item Each element to compare in an alignment group.
data-ui-radius An outer surface with equal corner radii and insets.
data-ui-radius-inner Its direct inner surface. Its radius must equal the outer radius minus the inset.

You can also use controlContainers in the policy to select existing button containers. See example styles.

Check existing layout groups

Use controlGapRules to set a different minimum gap for a group. Each rule selects the group and sets minGap in CSS pixels. For example, a segmented control can use 2 px while other groups keep the default 8 px.

{ "controlGapRules": [{ "selector": ".segmented-control", "minGap": 2 }] }

Each button belongs to its nearest group selected by a rule or marked with data-ui-actions. When more than one rule matches a group, the first rule applies. Other groups use minControlGap. A minimum of 0 allows shared edges. Overlapping buttons still fail.

Use alignmentRules to check alignment in existing groups. Each rule selects a group, the items in it, and the horizontal edge or center to compare.

{ "alignmentRules": [{ "selector": ".project-summary", "itemSelector": ".title, .details", "alignment": "start" }] }

The first rule that matches a group supplies its alignment and item selectors. Nested groups own their items. Groups can still use data-ui-align and data-ui-align-item without a policy rule.

Automatic tooltip checks

CLI and checkUrl scans open declared tooltips on hover and keyboard focus. They check the rendered page in each open state and check Escape dismissal and focus retention. While the hover tooltip is open, they resize to the other configured viewports. A tooltip can close on resize; if it stays open, it must fit. Resize findings retain the actual screen size.

Triggers are discovered through aria-describedby references to existing role="tooltip" elements, or through data-ui-tooltip IDs. A data-ui-tooltip target can be created when the tooltip opens. Scans use hover, Tab, and Escape; they do not click triggers or submit forms. Explicit tooltip plans take priority for their triggers. Automatic discovery runs after the supplied interaction plan, on the resulting page state.

accessibilityCoverage.tooltips lists automatically checked triggers and unmeasured cases. Native title tooltips, disabled or unreachable triggers, duplicate IDs, and tooltip elements without a visible declared trigger are reported as unmeasured. Scans check at most 100 declared tooltip relationships per page. These coverage limits alone do not change the exit code. An already-open tooltip has an unresolved opening check and exits with code 1. Tooltips that fail to open on hover or focus, or fail to close on Escape, produce findings.

If a trigger adds aria-describedby only while its tooltip is open, select the trigger in an explicit interaction plan and omit the tooltip selector.

{ "tooltips": [{ "trigger": "#about-requests" }] }

The scan follows aria-describedby after hover and keyboard focus. Each opening must name exactly one visible role="tooltip" element with text. Its ID can change on each opening. Escape must hide the tooltip and keep focus on the trigger. Other triggers still use the normal checks.

Use this plan with checkInteractions, checkUrl, or the CLI --interactions option. checkPage and expectUI remain passive. Open the tooltip in your test before calling them. Child frames still need separate checks.

While the pointer is over a trigger, an open custom tooltip and an active HTML title produce a native-tooltip-conflict finding. The check reads the title on the hovered element or its nearest ancestor with a title. An explicit empty title stops inheritance. For a custom hover label without role="tooltip", set data-ui-tooltip to the label ID and call checkPage or expectUI while the label is open.

Control content insets

Buttons and custom dropdown controls are checked by default. Their visible text and DOM icons (svg, img, and canvas) need at least 8 px from the inner left and right borders. The check uses rendered text ranges and icon boxes, including transformed and absolute content. It does not require contract attributes. It does not apply to general containers.

Native select arrows and labels, native input content, CSS images, generated content, and clipped content cannot be fully measured by this check. controlContentCoverage.unmeasured lists these limits. CLI text reports show them, and expectUI saves a coverage attachment. An unmeasured item is not a spacing pass; it needs visual review. Coverage limits alone do not change the exit code.

Use a DOM icon to make arrow spacing measurable. A matching contentInsetRules entry replaces the automatic check for that control and can set component-specific edges and minimums. Existing content-inset exceptions also apply to automatic findings.

Custom content insets

Use contentInsetRules in ui-policy.json to check the space between a component's inner edges and selected content. The default list is empty. Controls still receive the automatic check described above.

{
  "contentInsetRules": [
    {
      "selector": ".sidebar-row",
      "contentSelector": ".icon, .label",
      "insets": { "left": 8, "right": 8 }
    }
  ]
}

The first rule whose selector matches a container applies. contentSelector selects descendant element boxes. A nested container that matches the same selector owns its own content. Hidden content and selectors with no visible matches are skipped. Raw text nodes and pseudo-elements are not measured; wrap text in an element if it needs this check.

Choose physical edges from left, top, right, and bottom. Values must be finite, nonnegative CSS pixel minimums. Omitted edges are not checked. The rule measures rendered distances from inside the border, with a 0.1 px tolerance. Borders do not count as padding. Transforms and absolute positions affect the measurement.

A content-inset finding names the content element, its container, the failing edge, the measured distance, and the configured minimum. This rule does not change the existing control-inset check.

Optional icon sizes

Use iconSizeRules in ui-policy.json to require specific sizes for selected icons. The default is an empty list. No icon-size checks run until you add a rule.

{
  "iconSizeRules": [
    { "selector": ".sidebar-row .icon", "sizes": [18] },
    { "selector": ".toolbar .icon", "sizes": [16, 20] }
  ]
}

The first rule whose selector matches a visible element applies. Each size is a positive, finite CSS pixel value for a square icon. Both rendered dimensions must match the same allowed size, with a 0.1 px tolerance. A list of [16, 20] allows 16 by 16 px or 20 by 20 px, not 16 by 20 px.

The check measures element boxes, including borders and transforms. It works with selected SVG, image, and HTML elements. It does not measure the artwork inside an SVG view box or a pseudo-element. Hidden elements and selectors with no visible matches are skipped. Do not select rectangular icons unless they must use a square box.

An icon-size finding includes the measured width and height and the configured sizes. Icon sizes do not change the minimum control hit area. An 18 px icon can sit inside a larger button.

Check full-image previews

Use fullImageSelectors to select visible img elements that must show the full image. For example, set "fullImageSelectors": [".asset-preview img"] in ui-policy.json. The default list is empty. Leave intentionally cropped thumbnails out of the list.

The check uses the loaded image dimensions, the content box, object-fit, and object-position. It checks for image content outside a rectangular overflow or paint clip on the image or an ancestor. A finding identifies the edge, the cut in CSS pixels, and the clipping ancestor when applicable. A cut of 1 px or less is within tolerance.

Check the preview after the image loads. Unavailable image dimensions, masks, clip paths, mixed overflow modes on an image, and transforms that prevent rectangular measurement produce unresolved findings. The check does not measure rounded corners, obstruction by other elements, or cropping inside the source artwork. It skips hidden and unmatched images. Use a browser assertion if the state must include a particular image.

Check the gap between two elements

Use layoutSeparationRules to check the order and gap between two parts of a component. For example, require the caption to sit below the artwork and within 8 px of it:

{
  "layoutSeparationRules": [
    {
      "selector": ".card",
      "before": ".artwork",
      "after": ".caption",
      "axis": "vertical",
      "minGap": 0,
      "maxGap": 8
    }
  ]
}

The default list is empty. Each rule applies to each matching group with visible content. Both endpoint selectors must match one distinct visible element in the group. Elements in nested matching groups belong to those groups. Missing or ambiguous endpoints produce an unresolved finding. Select the parent state where both parts are required if a part is intentionally absent in other states.

The check measures the gap between rendered boxes in CSS pixels, from top to bottom for vertical and in the group's text direction for horizontal. Overlap or reversed order gives a negative gap. Set minGap to zero to allow edges to touch. Leave out maxGap to check only the minimum. The tolerance is 0.1 px. Other spacing and alignment checks still apply.

Stable bounds after an action

Add stableBounds to a named interaction state to check if a change moves or resizes an element. For example, check a revision count when it changes from 9 to 10.

{
  "states": [{
    "name": "Increase revision count",
    "action": "click",
    "selector": "#increase",
    "ready": { "selector": "#revision-count", "expectedText": "10" },
    "stableBounds": [
      { "selector": "#revision-count", "properties": ["width"] },
      { "selector": "#increase", "properties": ["x"], "tolerance": 0.5 }
    ]
  }]
}

Each selector must match one visible element before the action. Lintapple compares its rendered bounds before the action and after the ready condition. Use a ready condition that indicates the end of any transition you want to exclude. The default properties are width and height. The default tolerance is 1 CSS pixel. The x and y properties are relative to the viewport, so scrolling can change them.

Development

All source, tests, examples, and build scripts use strict TypeScript. Run npm ci, then:

npm run typecheck
npm test
npm run test:playwright
npm run demo

npm run build writes JavaScript, source maps, type declarations, and demo assets to dist/. The package exports built JavaScript and generated types for lintapple and lintapple/playwright. Node.js users do not need a TypeScript loader. Run npm run release:build to prepare the demo and package for release.

npm run demo:check saves the local demo matrix in test-results/demo-matrix.json. Page and specimen diagnostics stay in test-results/demo-ui.json and test-results/demo-specimens.json. Tests with LINTAPPLE_ORIGIN save external evidence in test-results/production-matrix.json.

Run npm run demo:record to update the saved demo/reports.json snapshot. This command runs all demo tests and replaces the snapshot only after every test passes. It requires local checks without LINTAPPLE_ORIGIN. Failed checks leave the saved snapshot unchanged.

Functions sent to the browser must define their values inside the function or receive them as arguments. They cannot use imported values, values from an outer scope, or captured context such as module this and import.meta. npm test checks concrete functions at .toString() calls in the compiled JavaScript. It also checks direct Playwright evaluate, evaluateHandle, waitForFunction, and evaluateAll calls in the TypeScript source, before type imports are erased. Browser APIs remain available.

The guard uses Playwright method declarations to distinguish browser calls from unrelated methods. It cannot trace callback parameters through wrappers. Keep a direct checked call for each browser function so the guard can inspect its definition.

License

MIT. See LICENSE.

About

It should be impossible for AI to make a bad UI.

Resources

Stars

608 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages