Skip to content

Instantly share code, notes, and snippets.

@ichim-david
Forked from SoMaCoSF/composer-linting-eli5.md
Created January 2, 2025 21:48
Show Gist options
  • Select an option

  • Save ichim-david/67c0a605f3d04123113833d99d0c3211 to your computer and use it in GitHub Desktop.

Select an option

Save ichim-david/67c0a605f3d04123113833d99d0c3211 to your computer and use it in GitHub Desktop.

Linting for Composer Agents: The Simple Guide ๐ŸŽจ

Imagine you're teaching a robot to paint a picture. You want to give it clear rules about what colors to use, how to hold the brush, and where to paint. That's exactly what linting directives do for composer agents!

The Basics ๐ŸŒŸ

Think of linting directives like a recipe card:

TELL_ROBOT:
  what: "paint a tree"
  how: "carefully"
  rules: "stay inside the lines"

Three Magic Words ๐ŸŽญ

  1. ENFORCE - "You MUST do this!"

    ENFORCE: {
        naming: "clean", # Like saying "always label your toys"
        structure: "neat", # Like "keep your room organized"
      }
  2. CHECK - "Please make sure this is right"

    CHECK: {
        spelling: "correct", # Like "double-check your homework"
        formatting: "readable", # Like "write neatly"
      }
  3. OPTIMIZE - "Try to make this better"

    OPTIMIZE: {
        speed: "fast", # Like "clean your room quickly"
        memory: "efficient", # Like "don't waste space"
      }

Real Examples Made Simple ๐ŸŽˆ

When Writing React Components

// Tell the robot: "Keep things tidy!"
// @lint-directive: ENFORCE neat-code
const Button = ({ text }) => {
  // Put hooks at the top, like putting your shoes on before your coat
  const [isClicked, setClicked] = useState(false);

  // Name things clearly, like labeling your lunchbox
  const handleClick = () => setClicked(true);

  return <button onClick={handleClick}>{text}</button>;
};

When Handling Data

# Tell the robot: "Be careful with the data!"
# @lint-directive: CHECK data-safety
def process_user_info(data):
    # Always check if you have everything you need
    if not data:
        return "Oops, no data!"

    # Keep things clean and safe
    clean_data = remove_bad_stuff(data)
    return clean_data

Simple Rules to Remember ๐ŸŒˆ

  1. Be Clear

    • Use simple names
    • Write what you mean
    • Keep things organized
  2. Be Safe

    • Check for mistakes
    • Handle errors nicely
    • Keep secrets safe
  3. Be Smart

    • Make things fast
    • Don't waste space
    • Keep it simple

Quick Tips ๐Ÿ’ก

  • Start with ENFORCE for important rules
  • Use CHECK for things that might go wrong
  • Add OPTIMIZE when everything works but could be better

Examples by Task ๐ŸŽฏ

Making a Website

ENFORCE: {
    components: "neat", # Keep your toys organized
    naming: "clear", # Label everything clearly
    safety: "important", # Don't run with scissors
  }

Working with Data

CHECK: {
    input: "clean", # Wash your hands before eating
    storage: "safe", # Put things away properly
    output: "correct", # Double-check your work
  }

Making Things Fast

OPTIMIZE: {
    loading: "quick", # Pack your bag the night before
    response: "instant", # Answer quickly when called
    memory: "light", # Don't carry too much stuff
  }

When Things Go Wrong ๐Ÿšจ

  1. If the agent isn't following rules:

    • Check if your instructions are clear
    • Make sure you're using the right magic word
    • Try breaking big rules into smaller ones
  2. If things are too slow:

    • Start with the most important rules
    • Add optimization rules later
    • Keep it simple at first

Remember! ๐ŸŒŸ

  • Start simple
  • Be clear
  • Stay consistent
  • Check your work
  • Make it better over time

Just like teaching a friend to play a game, be patient and clear with your composer agents, and they'll learn to follow your linting rules perfectly! ๐ŸŽฎ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment