diff options
Diffstat (limited to '')
-rw-r--r-- | qa/samples/config/gitlintconfig | 13 | ||||
-rw-r--r-- | qa/samples/config/ignore-release-commits | 7 | ||||
-rw-r--r-- | qa/samples/config/named-rules | 8 | ||||
-rw-r--r-- | qa/samples/config/named-user-rules | 15 | ||||
-rw-r--r-- | qa/samples/user_rules/extra/extra_rules.py | 72 | ||||
-rw-r--r-- | qa/samples/user_rules/incorrect_linerule/my_line_rule.py | 8 |
6 files changed, 123 insertions, 0 deletions
diff --git a/qa/samples/config/gitlintconfig b/qa/samples/config/gitlintconfig new file mode 100644 index 0000000..a5ecb84 --- /dev/null +++ b/qa/samples/config/gitlintconfig @@ -0,0 +1,13 @@ +[general] +ignore=title-trailing-punctuation,B2 +verbosity = 2 + +[title-max-length] +line-length=20 + +[B1] +# B1 = body-max-line-length +line-length=30 + +[title-must-not-contain-word] +words=WIP,thåt
\ No newline at end of file diff --git a/qa/samples/config/ignore-release-commits b/qa/samples/config/ignore-release-commits new file mode 100644 index 0000000..5807c96 --- /dev/null +++ b/qa/samples/config/ignore-release-commits @@ -0,0 +1,7 @@ +[ignore-by-title] +regex=^Release(.*) +ignore=T5,T3 + +[ignore-by-body] +regex=(.*)relëase(.*) +ignore=T3,B3
\ No newline at end of file diff --git a/qa/samples/config/named-rules b/qa/samples/config/named-rules new file mode 100644 index 0000000..f9bbdf5 --- /dev/null +++ b/qa/samples/config/named-rules @@ -0,0 +1,8 @@ +[title-must-not-contain-word] +words=WIP,thåt + +[title-must-not-contain-word:extra-wôrds] +words=hûr,dûr + +[title-must-not-contain-word: even$more%wôrds ] +words=fôo,bår
\ No newline at end of file diff --git a/qa/samples/config/named-user-rules b/qa/samples/config/named-user-rules new file mode 100644 index 0000000..ed811fb --- /dev/null +++ b/qa/samples/config/named-user-rules @@ -0,0 +1,15 @@ +# Ignore other user-defined rules +[general] +ignore=UC1,UC2,UC3,configürable:ignöred + +[UC4:föo] +int-öption=3 +str-öption=föo + +[configürable:bår] +str-öption=bår +list-öption=bar,list + +# The following rule will be ignored +[configürable:ignöred] +str-öption=foöbar
\ No newline at end of file diff --git a/qa/samples/user_rules/extra/extra_rules.py b/qa/samples/user_rules/extra/extra_rules.py new file mode 100644 index 0000000..7996590 --- /dev/null +++ b/qa/samples/user_rules/extra/extra_rules.py @@ -0,0 +1,72 @@ +from gitlint.options import IntOption, ListOption, StrOption +from gitlint.rules import CommitRule, ConfigurationRule, RuleViolation + + +class GitContextRule(CommitRule): + """Rule that tests whether we can correctly access certain gitcontext properties""" + + name = "gïtcontext" + id = "UC1" + + def validate(self, commit): + violations = [ + RuleViolation(self.id, f"GitContext.current_branch: {commit.context.current_branch}", line_nr=1), + RuleViolation(self.id, f"GitContext.commentchar: {commit.context.commentchar}", line_nr=1), + ] + + return violations + + +class GitCommitRule(CommitRule): + """Rule that tests whether we can correctly access certain commit properties""" + + name = "gïtcommit" + id = "UC2" + + def validate(self, commit): + violations = [ + RuleViolation(self.id, f"GitCommit.branches: {commit.branches}", line_nr=1), + RuleViolation(self.id, f"GitCommit.custom_prop: {commit.custom_prop}", line_nr=1), + ] + + return violations + + +class GitlintConfigurationRule(ConfigurationRule): + """Rule that tests whether we can correctly access the config as well as modify the commit message""" + + name = "cönfigrule" + id = "UC3" + + def apply(self, config, commit): + # We add a line to the commit message body that pulls a value from config, this proves we can modify the body + # and read the config contents + commit.message.body.append(f"{config.target} ") # trailing whitespace deliberate to trigger violation + + # We set a custom property that we access in CommitRule, to prove we can add extra properties to the commit + commit.custom_prop = "foöbar" + + # We also ignore some extra rules, proving that we can modify the config + config.ignore.append("B4") + + +class ConfigurableCommitRule(CommitRule): + """Rule that tests that we can add configuration to user-defined rules""" + + name = "configürable" + id = "UC4" + + options_spec = [ + IntOption("int-öption", 2, "int-öption description"), + StrOption("str-öption", "föo", "int-öption description"), + ListOption("list-öption", ["foo", "bar"], "list-öption description"), + ] + + def validate(self, _): + violations = [ + RuleViolation(self.id, f"int-öption: {self.options['int-öption'].value}", line_nr=1), + RuleViolation(self.id, f"str-öption: {self.options['str-öption'].value}", line_nr=1), + RuleViolation(self.id, f"list-öption: {self.options['list-öption'].value}", line_nr=1), + ] + + return violations diff --git a/qa/samples/user_rules/incorrect_linerule/my_line_rule.py b/qa/samples/user_rules/incorrect_linerule/my_line_rule.py new file mode 100644 index 0000000..33e511f --- /dev/null +++ b/qa/samples/user_rules/incorrect_linerule/my_line_rule.py @@ -0,0 +1,8 @@ +from gitlint.rules import LineRule + + +class MyUserLineRule(LineRule): + id = "UC2" + name = "my-line-rule" + + # missing validate method, missing target attribute |