Skip to content

The same CSS declarations under another selector; the same long utility-class string again and again ​

Code that already exists: one of the ways AI coding agents bloat software, from lessloc's pattern catalog. lessloc catches it as style-copy.

What makes the same CSS declarations under another selector a bad practice? ​

The standards that call it a bad practice: DRY; Tailwind docs: Reusing Styles.

What does lessloc do about the same CSS declarations under another selector? ​

lessloc catches it as style-copy.

  • style-copy (tier 2): The same CSS declarations under another selector, or the same long utility-class string written again and again.

Examples ​

Caught as style-copy:

css
.card { padding: 8px; border: 1px solid #ccc; border-radius: 4px; }
.panel { border: 1px solid #ccc; padding: 8px; border-radius: 4px; }

Written well:

css
.surface, .notice { padding: 6px; border: 1px solid #ddd; border-radius: 6px; }

Caught as style-copy:

jsx
export const List = () => (
  <>
    <div className="flex items-center gap-2 rounded-md border px-3 py-2">a</div>
    <div className="flex items-center gap-2 rounded-md border px-3 py-2">b</div>
    <div className="flex items-center gap-2 rounded-md border px-3 py-2">c</div>
  </>
);

Written well:

jsx
const Row = ({ children }) => <div className="grid place-items-center gap-1 rounded-lg border px-2 py-1">{children}</div>;
export const List = () => (
  <>
    <Row>a</Row>
    <Row>b</Row>
    <Row>c</Row>
  </>
);

The other patterns in Code that already exists:

Released under the Apache-2.0 license. · llms.txt