Open Editor →

Linting & Formatting

Maintain a professional, error-free codebase. Learn how Python Online uses the Ruff engine to analyze and format your code in real-time.

The Ruff Engine

To ensure your code remains clean and free of syntax errors before it even hits the execution server, Python Online integrates Ruff—an extremely fast Python linter built in Rust.

We compile Ruff into WebAssembly, allowing it to run entirely in the background of your browser as a Web Worker. This means as you type, your code is being analyzed continuously without requiring any network requests or consuming server resources, resulting in instantaneous feedback.

Real-Time Quality Control

As the linter scans your active files, it identifies two primary categories of issues, providing immediate visual feedback within the Monaco editor:

  • Errors (Red Squiggles): These indicate fatal problems that will likely cause your script to crash upon execution. Examples include syntax errors (e.g., missing a colon), undefined variables, or importing a module that does not exist.
  • Warnings (Yellow Squiggles): These indicate style violations or bad practices based on the official PEP 8 standards. Examples include lines that are too long, unused imports, or trailing whitespace.

When you hover your mouse over any squiggled text, a tooltip will appear explaining the exact nature of the problem, along with the specific Ruff rule code (e.g., E501 or F401).

The Problems Panel

When working on a large project with multiple files, scanning through every tab to find red squiggles is inefficient. Python Online aggregates all active diagnostics into a centralized Problems Panel.

You can monitor the health of your entire workspace by looking at the bottom right corner of the Status Bar. If errors or warnings are detected, a counter will appear. Clicking this counter automatically opens the Problems Panel as a tab in your layout.

The Problems Panel groups issues by file. If you click on any specific error message within the panel, the editor will instantly jump to the file and highlight the exact line where the problem occurred, allowing for rapid debugging.

Customizing Linter Rules

Every developer has different preferences regarding code style. If you find the linter too strict (or not strict enough), you can configure its behavior globally in the IDE Settings under the Language tab.

Select vs. Ignore

You control the linter using a comma-separated list of rule codes:

  • Select Rules: This defines which categories of checks Ruff should perform. By default, we enable F (Pyflakes for logic errors), E (pycodestyle for formatting errors), W (pycodestyle warnings), and I (Isort for import sorting).
  • Ignore Rules: This allows you to selectively silence specific checks. For example, if you prefer writing long strings without wrapping them, you can add E501 (Line too long) to the Ignore list. The linter will continue checking for other style issues but will stop squiggling your long lines.

Automated Formatting (Format on Save)

Beyond pointing out style violations, Ruff includes an ultra-fast code formatter capable of fixing them automatically. You can enable Format on Save in the General Settings.

When enabled, every time you save a file (e.g., by pressing Ctrl + S), the editor will intercept the save event, pass your code through the Ruff formatter, and cleanly rewrite the document. This ensures your indentation, line spacing, and import organization are perfectly standardized to PEP 8 guidelines before the file is committed to disk.

The formatter respects your specific workspace settings. If you prefer 2 spaces instead of the standard 4, adjust the Tab Size setting. The Ruff formatter will automatically adopt this preference when reorganizing your code blocks.