def test_gitcontext_ignore_specific(self): # ignore specific rules config = LintConfig() context = self.gitcontext("test\ngitlint-ignore: T1, body-hard-tab") config.apply_config_from_commit(context.commits[-1]) 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_sample5(self): gitcontext = self.gitcontext(self.get_sample("commit_message/sample5")) lintconfig = LintConfig() lintconfig.apply_config_from_commit(gitcontext.commits[-1]) linter = GitLinter(lintconfig) violations = linter.lint(gitcontext.commits[-1], 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)
def test_lint_sample4(self): gitcontext = self.gitcontext(self.get_sample("commit_message/sample4")) lintconfig = LintConfig() lintconfig.apply_config_from_commit(gitcontext.commits[-1]) linter = GitLinter(lintconfig) violations = linter.lint(gitcontext.commits[-1], 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 = self.gitcontext("test\ngitlint\nfoo") config.apply_config_from_commit(context.commits[-1]) self.assertListEqual(config.rules, original_rules) # ignore all rules context = self.gitcontext("test\ngitlint-ignore: all\nfoo") config.apply_config_from_commit(context.commits[-1]) self.assertEqual(config.rules, []) # ignore all rules, no space config = LintConfig() context = self.gitcontext("test\ngitlint-ignore:all\nfoo") config.apply_config_from_commit(context.commits[-1]) self.assertEqual(config.rules, []) # ignore all rules, more spacing config = LintConfig() context = self.gitcontext("test\ngitlint-ignore: \t all\nfoo") config.apply_config_from_commit(context.commits[-1]) self.assertEqual(config.rules, [])
def test_lint_sample5(self): gitcontext = self.gitcontext(self.get_sample("commit_message/sample5")) lintconfig = LintConfig() lintconfig.apply_config_from_commit(gitcontext.commits[-1]) linter = GitLinter(lintconfig) violations = linter.lint(gitcontext.commits[-1], 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)