Skip to content

robocop

GitHub stars autofix sarif GitHub release (latest SemVer) GitHub last commit GitHub commit activity GitHub contributors

RoboCop is a linter and code formatter for the Robot Framework. It helps maintain clean, consistent, and high-quality automation test code.

Key Features:

  • Static code analysis detecting common issues, code smells, and potential errors in Robot Framework test suites.
  • Customizable rules (checks) with a large set of built-in rules (e.g., naming conventions, spacing, structure) that can be enabled, disabled, or configured to fit team standards.
  • Code formatting can automatically format Robot Framework files to follow consistent style guidelines.
  • Error, warning, and info levels each message is categorized, making it easy to distinguish between critical issues and style suggestions.
  • Extensibility supports custom rules, so teams can enforce project-specific conventions.
  • Configuration flexibility rules can be configured via pyproject.toml, robocop.toml, or CLI options, making integration smooth in different environments.
  • Integration with CI/CD easy to run in pipelines to ensure code quality before merging changes.
  • Pre-commit hook support can be added to Git pre-commit hooks to lint and format files automatically before committing.
  • Output options supports multiple output formats (text, JSON, SARIF), useful for different reporting tools.
  • Performance optimized for speed and can handle large Robot Framework projects.

robocop documentation

robotframework-robocop - GitHub

Configuration in MegaLinter

Variable Description Default value
ROBOTFRAMEWORK_ROBOCOP_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
ROBOTFRAMEWORK_ROBOCOP_COMMAND_REMOVE_ARGUMENTS User custom arguments to remove from command line before calling the linter
Ex: -s --foo "bar"
ROBOTFRAMEWORK_ROBOCOP_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
ROBOTFRAMEWORK_ROBOCOP_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
ROBOTFRAMEWORK_ROBOCOP_CLI_LINT_MODE Override default CLI lint mode
- file: Calls the linter for each file
- list_of_files: Call the linter with the list of files as argument
- project: Call the linter from the root of the project
list_of_files
ROBOTFRAMEWORK_ROBOCOP_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".robot", ".resource"]
ROBOTFRAMEWORK_ROBOCOP_FILE_NAMES_REGEX File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files
Ex: ["Dockerfile(-.+)?", "Jenkinsfile"]
Include every file
ROBOTFRAMEWORK_ROBOCOP_PRE_COMMANDS List of bash commands to run before the linter None
ROBOTFRAMEWORK_ROBOCOP_POST_COMMANDS List of bash commands to run after the linter None
ROBOTFRAMEWORK_ROBOCOP_UNSECURED_ENV_VARIABLES List of env variables explicitly not filtered before calling ROBOTFRAMEWORK_ROBOCOP and its pre/post commands None
ROBOTFRAMEWORK_ROBOCOP_CONFIG_FILE robocop configuration file name
Use LINTER_DEFAULT to let the linter find it
robocop.toml
ROBOTFRAMEWORK_ROBOCOP_RULES_PATH Path where to find linter configuration file Workspace folder, then MegaLinter default rules
ROBOTFRAMEWORK_ROBOCOP_DISABLE_ERRORS Run linter but consider errors as warnings false
ROBOTFRAMEWORK_ROBOCOP_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0
ROBOTFRAMEWORK_ROBOCOP_CLI_EXECUTABLE Override CLI executable ['robocop']

IDE Integration

Use robocop in your favorite IDE to catch errors before MegaLinter !

IDE Extension Name Install
Visual Studio Code RobotCode Install in VSCode

MegaLinter Flavors

This linter is available in the following flavors

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 127 Docker Image Size (tag) Docker Pulls
cupcake MegaLinter for the most commonly used languages 87 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .robot, .resource

How the linting is performed

  • robocop is called once with the list of files as arguments (list_of_files CLI lint mode)

Example calls

robocop check myfile.robot

Help content


 Usage: robocop [OPTIONS] COMMAND [ARGS]...                                     

 Static code analysis tool (linter) and code formatter for Robot Framework.
 Full documentation available at https://robocop.readthedocs.io .

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --version                                            Show the version and    │
│                                                      exit.                   │
│ --install-completion          [bash|zsh|fish|powers  Install completion for  │
│                               hell|pwsh]             the specified shell.    │
│ --show-completion             [bash|zsh|fish|powers  Show completion for the │
│                               hell|pwsh]             specified shell, to     │
│                                                      copy it or customize    │
│                                                      the installation.       │
│ --help                -h                             Show this message and   │
│                                                      exit.                   │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ check     Lint Robot Framework files.                                        │
│ format    Format Robot Framework files.                                      │
│ list      List available rules, reports or formatters.                       │
│ docs      Print formatter, rule or report documentation.                     │
│ migrate   Migrate Robocop and Robotidy old configuration files to the new    │
│           format supported by the Robocop 6.0.                               │
╰──────────────────────────────────────────────────────────────────────────────╯

Installation on mega-linter Docker image

  • Dockerfile commands :
# renovate: datasource=pypi depName=robotframework-robocop
ARG PIP_ROBOT_FRAMEWORK_ROBOCOP_VERSION=6.7.0