def test_gitcontext_ignore_specific(self): # ignore specific rules config = LintConfig() context = GitContext() context.set_commit_msg("test\ngitlint-ignore: T1, body-hard-tab") config.apply_config_from_gitcontext(context) expected_rules = [rule for rule in config.rules if rule.id not in ["T1", "body-hard-tab"]] self.assertEqual(config.rules, expected_rules)
def test_lint_sample4(self): gitcontext = GitContext() gitcontext.set_commit_msg(self.get_sample("commit_message/sample4")) lintconfig = LintConfig() lintconfig.apply_config_from_gitcontext(gitcontext) linter = GitLinter(lintconfig) violations = linter.lint(gitcontext) # expect no violations because sample4 has a 'gitlint: disable line' expected = [] self.assertListEqual(violations, expected)
def test_gitcontext_ignore_all(self): config = LintConfig() original_rules = config.rules # nothing gitlint context = GitContext() context.set_commit_msg("test\ngitlint\nfoo") config.apply_config_from_gitcontext(context) self.assertListEqual(config.rules, original_rules) # ignore all rules context = GitContext() context.set_commit_msg("test\ngitlint-ignore: all\nfoo") config.apply_config_from_gitcontext(context) self.assertEqual(config.rules, []) # ignore all rules, no space config = LintConfig() context.set_commit_msg("test\ngitlint-ignore:all\nfoo") config.apply_config_from_gitcontext(context) self.assertEqual(config.rules, []) # ignore all rules, more spacing config = LintConfig() context.set_commit_msg("test\ngitlint-ignore: \t all\nfoo") config.apply_config_from_gitcontext(context) self.assertEqual(config.rules, [])
def test_lint_sample5(self): gitcontext = GitContext() gitcontext.set_commit_msg(self.get_sample("commit_message/sample5")) lintconfig = LintConfig() lintconfig.apply_config_from_gitcontext(gitcontext) linter = GitLinter(lintconfig) violations = linter.lint(gitcontext) title = " Commit title containing 'WIP', \tleading and trailing whitespace and longer than 72 characters." # expect only certain violations because sample5 has a 'gitlint: T3,' expected = [RuleViolation("T1", "Title exceeds max length (95>72)", title, 1), RuleViolation("T4", "Title contains hard tab characters (\\t)", title, 1), RuleViolation("T5", "Title contains the word 'WIP' (case-insensitive)", title, 1), RuleViolation("B4", "Second line is not empty", "This line should be empty", 2), RuleViolation("B2", "Line has trailing whitespace", "This line has a trailing space. ", 4), RuleViolation("B2", "Line has trailing whitespace", "This line has a trailing tab.\t", 5), RuleViolation("B3", "Line contains hard tab characters (\\t)", "This line has a trailing tab.\t", 5), ] self.assertListEqual(violations, expected)