Skip to content

The KeywordRule class

boakley edited this page Nov 30, 2014 · 1 revision

The KeywordRule class is an abstract class that should be inherited by all rules that operate on a Keyword. When the rule is applied (ie: the apply method is called), an instance of the Keyword class will be passed as a parameter. The class has an attribute named severity which defines the severity of the rule. The default severity is WARNING but may be overridden in the concrete class.

Every class that inherits from this class must define a method named apply. This method must take exactly one parameter, a Keyword object.

For example, here is a testcase rule that that requires a test to have documentation:

from rflint.common import KeywordRule, ERROR
from rflint.parser import SettingTable

class RequireKeywordDocumentation(KeywordRule):
    '''Verify that a keyword has documentation'''
    severity=ERROR

    def apply(self, keyword):
        for setting in keyword.settings:
            if setting[1].lower() == "[documentation]" and len(setting) > 2:
                return

        # set the line number to the line immediately after the keyword name
        self.report(keyword, "No keyword documentation", keyword.linenumber+1)