• Stars
    star
    185
  • Rank 208,228 (Top 5 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated 14 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tool for static code analysis of Robot Framework language

Unit tests Codecov PyPI Python versions License Downloads


Robocop

Watch our talks from RoboCon 2021 and RoboCon 2022 about Robocop & Robotidy and learn more about these cool tools! ๐Ÿค–

Robocop & Robotidy presentation at RoboCon 2021 Robocop presentation at RoboCon 2022


Introduction

Robocop is a tool that performs static code analysis of Robot Framework code.

It uses official Robot Framework parsing API to parse files and runs number of checks, looking for potential errors or violations to code quality standards (commonly referred as linting issues).

Hosted on GitHub. ๐ŸŽ–๏ธ

Documentation

Full documentation is available here. ๐Ÿ“–

Most common questions with answers can be found at the bottom โฌ‡ of this README file.

Requirements

Python 3.7+ ๐Ÿ and Robot Framework 3.2.2+ ๐Ÿค–.

Installation

You can install the latest version of Robocop simply by running:

pip install -U robotframework-robocop

Usage

Robocop runs by default from the current directory and it discovers supported files recursively. You can simply run:

robocop

All command line options can be displayed in help message by executing:

robocop -h

Example Output

Executing command:

robocop --report rules_by_error_type test.robot

Will result in following output:

\Users\OCP\test.robot:7:1 [W] 0509 Section '*** Variables ***' is empty (empty-section)
\Users\OCP\test.robot:22:1 [E] 0801 Multiple test cases with name "Simple Test" (first occurrence in line 17) (duplicated-test-case)
\Users\OCP\test.robot:42:1 [E] 0810 Both Task(s) and Test Case(s) section headers defined in file (both-tests-and-tasks)
\Users\OCP\test.robot:48:1 [W] 0302 Keyword 'my keyword' does not follow case convention (wrong-case-in-keyword-name)
\Users\OCP\test.robot:51:13 [I] 0606 Tag 'mytag' is already set by Test Tags in suite settings (tag-already-set-in-test-tags)

Found 5 issues: 2 ERRORs, 2 WARNINGs, 1 INFO.

Values

Original RoboCop - a fictional cybernetic police officer ๐Ÿ‘ฎโ€โ™‚๏ธ - was following 3 prime directives which also drive the progress of Robocop linter:

First Directive: Serve the public trust ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ

Which lies behind the creation of the project - to serve developers and testers as a tool to build applications they can trust.

Second Directive: Protect the innocent ๐Ÿ‘ถ

The innocent testers and developers have no intention to produce ugly code but sometimes, you know, it just happens, so Robocop is there to protect them.

Third Directive: Uphold the law ๐Ÿ›๏ธ

Following the coding guidelines established in the project are something very important to keep the code clean, readable and understandable by others and Robocop can help to uphold the law.

Fixing issues

Many issues in your code reported by Robocop can be fixed using auto-formatting tool, Robotidy. Check out the Robotidy documentation.

FAQ

Can I integrate Robocop with my code editor (IDE)?

Yes, Robocop integrates nicely with popular IDEs like PyCharm or VSCode thanks to Robot Framework Language Server. Read simple manual (README) in that project to figure out how to install & use it.

You can also use Robocop in PyCharm easily as an external tool. To configure it, go to: File โ†’ Settings โ†’ Tools โ†’ External Tools and click + icon. Then put values based on official instructions or this screenshot:

Robocop

If you're using Python virtual environment in your project, make sure to provide correct path to robocop.exe located in venv\Scripts\robocop.exe. Now, you can run Robocop by right-clicking on a file or directory and choosing External tools โ†’ Robocop.

We suggest also to add a keyboard shortcut (e.g. Ctrl + , (comma)) to quickly run Robocop on selected files. You can map the shortcut in Settings โ†’ Keymap.

Can I load configuration from file?

Yes, there are multiple ways to configure Robocop:

Argument file

You can add command line options to an argument file, preferably one option with value for a line. Such file can be used as an input for Robocop with --argumentfile / -A option, e.g. robocop -A robocop.cfg. You can mix arguments from a file with ones provided in run command.

Example argument file:

--exclude *doc*
--exclude 0510
--threshold W
--configure inconsistent-assignment:assignment_sign_type:equal_sign
--configure line-too-long:line_length:140
--reports all
--output robocop.log

.robocop file

It is a default file that is loaded only when no command line options are provided for Robocop. When running plain robocop command, it looks for .robocop file from place where it was run until it finds .git file. Options can be provided like in the example above.


pyproject.toml file

If there is no .robocop file and toml module is installed, Robocop will try to load configuration from pyproject.toml file (if it exists). Options have the same names as command line arguments and need to be placed under [tool.robocop] section.

Example configuration file:

[tool.robocop]
paths = [
    "tests\\atest\\rules\\bad-indent",
    "tests\\atest\\rules\\duplicated-library"
]
include = ['W0504', '*doc*']
exclude = ["0203"]
reports = [
    "rules_by_id",
    "scan_timer"
]
ignore = ["ignore_me.robot"]
ext-rules = ["path_to_external\\dir"]
filetypes = [".txt", ".tsv"]
threshold = "E"
format = "{source}:{line}:{col} [{severity}] {rule_id} {desc} (name)"
output = "robocop.log"
configure = [
    "line-too-long:line_length:150",
    "0201:severity:E"
]
no_recursive = true
I use different coding standards. Can I configure rules so that they fit my needs?

Yes, some rules are configurable. You can list them by running robocop --list-configurables or just robocop -lc.

Configuring is done by using -c / --configure command line option followed by pattern <rule>:<param_name>:<value> where:

  • <rule> can either be rule name or its id
  • <param_name> is a public name of the parameter
  • <value> is a desired value of the parameter

For example:

--configure line-too-long:line_length:140

is equivalent to

-c 0508:line_length:140

Each rule's severity can also be overwritten. Possible values are e/error, w/warning or i/info and are case-insensitive. Example:

-c too-long-test-case:severity:e

If there are special cases in your code that violate the rules, you can also exclude them in the source code.

Example:

Keyword with lowercased name  # robocop: disable

More about it in our documentation.

Can I define custom rules?

Yes, you can define and include custom rules using -rules / --ext-rules command line option by providing a path to a file containing your rule(s). The option accepts comma-separated list of paths to files or directories, e.g.

robocop -rules my/own/rule.py --ext-rules rules.py,external_rules.py

If you feel that your rule is very helpful and should be included in Robocop permanently, you can always share your solution by submitting a pull request. You can also share your idea by creating an issue.

More about external rules with code examples in our documentation.

Can I use Robocop in continuous integration (CI) tools?

Yes, it is easy to integrate Robocop with CI and other tools. For more details read our documentation.

Can I configure return status / code?

Yes, by default Robocop returns code 0 if number of found issues does not exceed quality gates.

Quality gates are the number specified for each severity (error, warning, info) that cannot be exceeded. Every violation of quality gates increases the return code by 1 up to maximum of 255. Default values for quality gates are:

quality_gate = {
          'E': 0,
          'W': 0,
          'I': -1
      }

which shows the accepted number of issues by severity. In that case each error and warning increases the return code. Rules with INFO severity do not affect the return code.

To configure quality gates, you simply use -c / --configure command line option with following pattern --configure return_status:quality_gates:<severity>=limit. You can change all limits at once. Example:

--configure return_status:quality_gates:E=0:W=100:I=-1

which means that no errors are accepted, up to 100 warnings are tolerated and issues with INFO severity do not affect the return code.

What is the difference between Robocop and rflint?

Robocop is better in every case because it:

  • has maaaaany rules that check the quality of your Robot Framework code
  • is integrated with popular IDE tools
  • is highly configurable
  • has very good defaults that work out of the box
  • can be configured in source code
  • uses the latest Robot Framework Parsing API
  • is actively developed & fixed
  • is easy to integrate with external tools
  • can redirect output to a file
  • displays nice reports
  • is easy to extend it with new rules
  • is cool ๐Ÿค“

Still not convinced? Watch our talk about Robocop & Robotidy and see for yourself! ๐Ÿง


Excuse me, I have to go. Somewhere there is a crime happening. - Robocop

More Repositories

1

robotframework-browser

Robot Framework Browser library powered by Playwright.
Python
505
star
2

robotframework-requests

Robot Framework keyword library wrapper for requests
Python
485
star
3

awesome-robotframework

A curated list of awesome Robot Framework resources and libraries
Python
437
star
4

Robotframework-Database-Library

The Database Library for Robot Framework allows you to query a database and verify the results using different Python DB modules (installed separately).
RobotFramework
154
star
5

SwingLibrary

Swing UI testing library for Robot Framework
Java
113
star
6

robotframework-tidy

Robot Framework code formatter
RobotFramework
102
star
7

webdrivermanager

Python module to facilitate downloading and deploying WebDriver binaries for Chrome, Firefox, Opera & Edge
Python
100
star
8

robotframework-faker

Robot Framework keyword library wrapper for faker
HTML
64
star
9

Robot-Framework-Mainframe-3270-Library

Test library for Robot Framework to allow interaction with IBM Mainframe 3270.
Python
38
star
10

robotframework-seleniumtestability

Extension for SeleniumLibrary that provides manual and automatic waiting for asyncronous events like fetch, xhr, etc.
Python
38
star
11

robotframework-angularjs

An AngularJS and Angular extension to Robotframework's SeleniumLibrary
Python
34
star
12

robotframework-openapidriver

Python
30
star
13

robotframework-style-guide

Robot Framework Style Guide
RobotFramework
27
star
14

roboswag

Python
26
star
15

robotframework-aws

Custom Library for Robot Framework to interact with Amazon Cloud Services
Python
25
star
16

robotframeworkguides

A project to share guides and best practices for robot framework and its ecosystem
MDX
25
star
17

robotframework-react

A Robot Framework library for React
JavaScript
24
star
18

robotframework-difflibrary

Robot Framework keyword library that will provide Diff capabilities
Python
23
star
19

robotframework-seleniumlibrary-java

Java port of the Python based SeleniumLibrary for Robot Framework
Java
23
star
20

robotframework-archivelibrary

HTML
22
star
21

robotframework-httprequestlibrary

Robot Framework's library to test REST interfaces utilizing Apache HttpClient
Java
21
star
22

robotframework-webservice

Webservice for running Robot Framework test cases.
Python
21
star
23

Robot-Framework-SOAP-Library

SOAP Library for Robot Framework
Python
20
star
24

robotframework-camunda

Library for testing Camunda 7 instances and workflows
Python
19
star
25

robotframework-stacktrace

A listener for RF >= 4.0 that prints a Stack Trace to console to faster find the code section where the failure appears.
Python
18
star
26

robotframework-sherlock

Robot Framework code inspector
Python
13
star
27

robotframework-reportmodifier

Python
13
star
28

robotframework-retryfailed

A listener to automatically retry tests or tasks based on tags.
Python
12
star
29

robotframework-dblibrary

A database testing library for the Robot Framework
Java
12
star
30

robotframework-openapi-libcore

Python
12
star
31

robotframework-browser-extensions

Collection of working extensions for Robot Frameworkยฎ Browser
HTML
12
star
32

ci-cd-examples

Collection of CI/CD pipelines executing Robto Framework test suites.
RobotFramework
12
star
33

robotframework-seleniumscreenshots

Robot Framework keyword library for capturing annotated screenshots with SeleniumLibrary
Nix
11
star
34

AssertionEngine

Easy way to perform assertions on Robot Framework assertions in libraries
Python
10
star
35

MarketSquare

Robot Framework Community's MarketSquare - Requests, Questions, Maintenance
10
star
36

robotframework-yamllibrary

Read or compare Yaml / Json strings by sub tree or single value
Python
10
star
37

robotframework-cluster

possible successor of Pabot
7
star
38

jupyterlab_robotmode

Robot mode for Jupyterlab
TypeScript
6
star
39

robotframework-openapitools

Python
5
star
40

robotframework-ai

Python
5
star
41

robotframework-browser.org

Vue
3
star
42

RoboConContest

This code draws the winners of RoboCon Contest 2021
RobotFramework
2
star
43

actions-robocop

Shell
2
star
44

robotframework-primefaces

An extension to Robot Framework's SeleniumLibrary for queue-based waiting on PrimeFaces pages.
Python
2
star
45

rfw-lightning

Proof of Concept to make Robot Framework more human understandable
Python
1
star
46

robotframework-browser-project-template

Robot Framework Browser library Project Template
RobotFramework
1
star
47

robot-workshop

JavaScript
1
star
48

robot-upgrade

Documentation and tooling to help upgrading Robot Framework
Python
1
star
49

robotframework-telnet-library

Robot framework keyword library for Telnet connections
1
star
50

compact_testprogram_distribution

Zipapps
1
star
51

HowToContribute

Guide on how to contribute to the open source Robot Framework project.
1
star
52

robotframework-browser-translation-fi

Browser library translation to Finnish
Python
1
star