Package: robotframework-robocop
RobocopIntroductionDocumentationRequirementsInstallationUsageExample OutputValuesFixing issuesFAQWatch our talks fromRoboCon 2021andRoboCon 2022about Robocop &Robotidyand learn more about these cool tools! :robot:IntroductionRobocop is a tool that performs static code analysis ofRobot Frameworkcode.It uses officialRobot Framework parsing APIto parse files and runs number of checks,
looking for potential errors or violations to code quality standards (commonly referred aslinting issues).Hosted onGitHub. :medal_military:DocumentationFull documentation is availablehere. :open_book:Most common questions with answers can be found at the bottom ⬇ of this README file.RequirementsPython 3.8+ :snake: and Robot Framework 3.2.2+ :robot:.InstallationYou can install the latest version of Robocop simply by running:pip install -U robotframework-robocopUsageRobocop runs by default from the current directory and it discovers supported files recursively.
You can simply run:robocopAll command line options can be displayed in help message by executing:robocop -hExample OutputExecuting command:robocop --report rules_by_error_type test.robotWill 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.ValuesOriginalRoboCop- a fictional cybernetic police officer :policeman: - was following 3 prime directives
which also drive the progress of Robocop linter:First Directive:Serve the public trust:family_man_woman_girl_boy:Which lies behind the creation of the project - toservedevelopers and testers as a tool to build applications they cantrust.Second Directive:Protect the innocent:baby:The innocenttesters and developers have no intention to produce ugly code but sometimes, you know, it just happens,
so Robocop is there toprotectthem.Third Directive:Uphold the law:classical_building: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 touphold the law.Fixing issuesMany issues in your code reported by Robocop can be fixed using auto-formatting tool, Robotidy.
Check out the Robotidydocumentation.FAQCan I integrate Robocop with my code editor (IDE)?Yes, Robocop integrates nicely with popular IDEs like PyCharm or VSCode
thanks toRobot 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 Toolsand click+icon. Then put values based onofficial instructionsor this screenshot:If you're using Python virtual environment in your project,
make sure to provide correct path to robocop.exe located invenv\Scripts\robocop.exe.
Now, you can run Robocop by right-clicking on a file or directory and choosingExternal 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 inSettings→Keymap.Can I load configuration from file?Yes, there are multiple ways to configure Robocop:Argument fileYou 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 / -Aoption, 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.robocopfileIt is a default file that is loaded only when no command line options are provided for Robocop.
When running plainrobocopcommand, it looks for.robocopfile from place where it was run
until it finds.gitfile. Options can be provided like in the example above.pyproject.tomlfileIf there is no.robocopfile andtomlmodule is installed,
Robocop will try to load configuration frompyproject.tomlfile (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 = trueI use different coding standards. Can I configure rules so that they fit my needs?Yes, some rules are configurable. You can list them by runningrobocop --list-configurablesor justrobocop -lc.Configuring is done by using-c / --configurecommand 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 parameterFor example:--configure line-too-long:line_length:140is equivalent to-c 0508:line_length:140Each rule's severity can also be overwritten. Possible values aree/error,w/warningori/infoand are case-insensitive. Example:-c too-long-test-case:severity:eIf 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: disableMore about it inour documentation.Can I define custom rules?Yes, you can define and include custom rules using-rules / --ext-rulescommand 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.pyIf you feel that your rule is very helpful and should be included in Robocop permanently,
you can always share your solution bysubmitting a pull request.
You can also share your idea bycreating an issue.More about external rules with code examples inour 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 readour 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 / --configurecommand 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=-1which 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 codeis integrated with popular IDE toolsis highly configurablehas very good defaults that work out of the boxcan be configured in source codeuses the latestRobot Framework Parsing APIis actively developed & fixedis easy to integrate with external toolscan redirect output to a filedisplays nice reportsis easy to extend it with new rulesis cool :nerd_face:Still not convinced?Watch our talkabout Robocop &Robotidyand see for yourself! :monocle_face:Excuse me, I have to go. Somewhere there is a crime happening. - Robocop