Ruff v0.0.281 released, a high-performance Python code analysis tool written in Rust

Ruff is a high-performance Python code analysis tool (i.e. Linter) written based on Rust, which is used to check syntax errors, coding specification issues, potential logic problems and code quality problems in the code, and can provide real-time feedback and automatic repair suggestions. Its main feature is high performance, claiming to be 10 to 100 times faster than existing similar tools.

Ruff Core Features

  • install via pip
  • supportpyproject.toml
  • Compatible with Python 3.11
  • More than 500 built-in rules, almost equivalent to Flake8's built-in rule set
  • Reimplemented dozens of Flake8 plugins, such as flake8-bugbear, flake8-comprehensions, etc.
  • Supports autofix, which automatically corrects errors (e.g. removing unused imports)
  • Built-in caching to avoid repeated analysis of unchanged files
  • Support VS Code, Pycharm, Neovim, Sublime Text, Emacs and other editors
  • Monorepo friendly, with layered and cascaded configurations

Ruff just released v0.0.281.

The main change is to increase the speed of the lexer. It is claimed that Ruff's lexer is now 2-3 times faster than the old version:

group                       v0.0.280                               v0.0.281
-----                       --------                               --------
lexer/large/dataset.py      2.18    665.9±5.64µs    61.1 MB/sec    1.00    304.9±3.79µs   133.4 MB/sec
lexer/numpy/ctypeslib.py    2.39    154.4±0.84µs   107.8 MB/sec    1.00     64.5±0.61µs   258.1 MB/sec
lexer/numpy/globals.py      2.89     18.1±0.14µs   163.3 MB/sec    1.00      6.3±0.06µs   471.8 MB/sec
lexer/pydantic/types.py     2.57    326.4±2.23µs    78.1 MB/sec    1.00    127.2±0.71µs   200.5 MB/sec

The lexical analyzer is responsible for tokenizing the Python source code into a stream of tokens, which are then used by the parser to build an Abstract Syntax Tree (AST). The lexer is the first step in Ruff's analysis pipeline and runs on every file that Ruff analyzes.

Optimizing lexer performance can therefore not only improve linter performance, but also improve the performance of future tools that utilize Ruff lexers, such as the Ruff formatter.

The new lexer utilizes more cache-friendly data structures, performs fewer allocations, and includes optimizations for pure ASCII source code. details .

Other changes include ignoring end-of-line # ruff: noqacomments, and adding more rules, see the specific changes here .

Guess you like

Origin www.oschina.net/news/251902/ruff-0-0-281-released