Skip to lesson
Exit
Rule Scoping and Anti-Patterns1 / 1

2 min lesson

Rule frontmatter and file globs

Complete "Rule frontmatter and file globs". Check the final state against the lesson before you move on.

Check your understanding

Run this practice: Rule scoping — narrow an always-on rule to the files it belongs in.

Outcome: The rules attached to that run don't include this one; it loads only when a file under src/components is in context, so the fixture and story are untouched by it.

Rule scoping — narrow an always-on rule to the files it belongs in
Rule frontmatter and file globs
SayThis icon-import rule is right for our component files, but it's set to Always, so Agent also enforces it in test fixtures and Storybook stories, where importing an icon straight from lucide-react is intentional.
DoOpen the rule under Cursor Settings, Rules to see its current scope.
TypealwaysApply: false globs: src/components/**/*.tsx
SeeThe rule flips from Always to Auto Attached in the Rules list, so it only loads when a file under src/components is in context.
TypeImport icons from @/components/icon; never import from lucide-react directly.
SeeThe body is one line you can confirm by eye in any diff, so the rule is small enough to reason about and cheap to remove later.
DoBefore saving, scan the other rules for anything else whose globs touch src/components and says the opposite.
SeeNothing nearby re-allows the raw import, so there's no older instruction left to quietly override the new intent.
DoStart Agent on an edit to a test fixture and a Storybook story, both outside src/components.
SeeThe rules attached to that run don't include this one; it loads only when a file under src/components is in context, so the fixture and story are untouched by it.
Learn more

Optional practice

Practice: Rule frontmatter and file globs

QYou've applied it. What actually proves the work is done, not just a plausible answer?

Finish the check to continue.