How to Use Semgrep in CodeGrade to Improve Student Code Quality
February 10, 2025

How to use Semgrep for Automatic Grading

In 30 seconds...

Want to catch missing function definitions, enforce coding best practices, or ensure students follow assignment guidelines? Semgrep in CodeGrade makes it easy. This powerful, lightweight static analysis tool helps instructors automatically check for code structures without complex setup. Learn how to integrate Semgrep into your grading workflow to provide instant feedback and improve student learning.

What is Semgrep?

Semgrep (Semantic Grep) is an open-source, lightweight static analysis tool that scans source code to identify specific patterns. It helps instructors and developers check for certain structures in code, such as:

  • Statements
  • Loops
  • Declarations
  • Function definitions

Semgrep works similarly to grep, but instead of searching for plain text, it scans for structured code patterns in a variety of programming languages like Python, JavaScript, Go, Java, C, and more.

How Can You Use Semgrep in CodeGrade?

In CodeGrade, Semgrep is integrated as a parent block called Code Structure, with two child blocks for pattern matching:

  • Positive Match: Passes if the pattern is found.
  • Negative Match: Fails if the pattern is found (useful for ensuring students don't use overly advanced or AI-generated code).

These blocks can be added to your setup with just a few simple steps. Here’s how:

Step 1: Set Up the Code Structure Block

  1. Drag the Code Structure block into your setup in CodeGrade.
  2. Inside the Code Structure block, nest a Match block.
    There are two types of Match blocks:
    • Positive Match: This will pass if the pattern is detected in the student’s code.
    • Negative Match: This will fail if the pattern is detected. This can be helpful to ensure students aren't using inappropriate code structures, such as overly advanced techniques or AI-generated code.

‍

Make your coding course more efficient today.

Continue reading

Snowball Miracle: A Terminal, a Smarter AI Assistant, and Tighter Exam Controls

CodeGrade released Snowball Miracle on 21 August 2026. A terminal with tabs, an AI assistant that reads AutoTest results, tighter exam controls, API changes.

Watch Now! CodeGrade Back to School Webinar

Watch the recap of our Back to School webinar. See the new built-in Terminal and redesigned code editor, learn how to set up your first autograded assignment on CodeGrade Free, and get a look at the latest features.

What we recommend for teaching intro to programming in 2026

Planning an intro programming course in 2026? Here is the teaching stack we recommend: editor, autograder, plagiarism, AI policy. Start free up to 50 students.

Sign up to our newsletter