summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoris Roovers <joris.roovers@gmail.com>2023-07-05 09:50:38 +0200
committerGitHub <noreply@github.com>2023-07-05 09:50:38 +0200
commitf6640f4115db966e1453f2af6bb9cc7cfa34f774 (patch)
tree6a6cdfe578c42a9e6fefc518f9d597b8bc179196
parent3810472b75e316b069459455ff5131accea2edee (diff)
Default to general.regex-style-search=True (#517)
This will make all rules use re.search() by default. It's still possible to manually reverse this behavior by setting: general.regex-style-search=False Relates to #254
-rw-r--r--docs/configuration/general_options.md6
-rw-r--r--gitlint-core/gitlint/config.py2
-rw-r--r--gitlint-core/gitlint/tests/config/test_config.py4
-rw-r--r--gitlint-core/gitlint/tests/expected/cli/test_cli/test_debug_12
-rw-r--r--gitlint-core/gitlint/tests/expected/cli/test_cli/test_input_stream_debug_22
-rw-r--r--gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_msg_filename_22
-rw-r--r--gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_stdin_22
-rw-r--r--gitlint-core/gitlint/tests/expected/cli/test_cli/test_named_rules_22
-rw-r--r--gitlint-core/gitlint/tests/rules/test_configuration_rules.py5
-rw-r--r--gitlint-core/gitlint/tests/rules/test_meta_rules.py4
-rw-r--r--gitlint-core/gitlint/tests/test_deprecation.py46
-rw-r--r--qa/expected/test_commits/test_ignore_commits_12
-rw-r--r--qa/expected/test_commits/test_lint_staged_msg_filename_12
-rw-r--r--qa/expected/test_commits/test_lint_staged_stdin_12
-rw-r--r--qa/expected/test_config/test_config_from_env_12
-rw-r--r--qa/expected/test_config/test_config_from_env_22
-rw-r--r--qa/expected/test_config/test_config_from_file_debug_12
-rw-r--r--qa/expected/test_gitlint/test_commit_binary_file_12
18 files changed, 51 insertions, 40 deletions
diff --git a/docs/configuration/general_options.md b/docs/configuration/general_options.md
index e046499..b029cf5 100644
--- a/docs/configuration/general_options.md
+++ b/docs/configuration/general_options.md
@@ -460,13 +460,13 @@ Whether to use Python `re.search()` instead of `re.match()` semantics in all bui
| Default value | Type | CLI flag | Env var |
| ---------------- | --------------- | --------------------------------------- | ------------- |
-| `#!python false` | `#!python bool` | `-c general.regex-style-search=<value>` | Not Available |
+| `#!python true` | `#!python bool` | `-c general.regex-style-search=<value>` | Not Available |
!!! important
- At this time, `regex-style-search` is **disabled** by default, but it will be **enabled** by default in the future.
+ At this time, `regex-style-search` is **enabled** by default, but you can still manually **disable** it.
+ Future versions of gitlint will no longer allow this, please follow the steps below to migrate.
-
Gitlint will log a warning when you're using a rule that uses a custom regex and this option is not enabled:
```plain
diff --git a/gitlint-core/gitlint/config.py b/gitlint-core/gitlint/config.py
index ed20a98..e23b2c7 100644
--- a/gitlint-core/gitlint/config.py
+++ b/gitlint-core/gitlint/config.py
@@ -90,7 +90,7 @@ class LintConfig:
"fail-without-commits", False, "Hard fail when the target commit range is empty"
)
self._regex_style_search = options.BoolOption(
- "regex-style-search", False, "Use `search` instead of `match` semantics for regex rules"
+ "regex-style-search", True, "Use `search` instead of `match` semantics for regex rules"
)
@property
diff --git a/gitlint-core/gitlint/tests/config/test_config.py b/gitlint-core/gitlint/tests/config/test_config.py
index baea4e9..422bb33 100644
--- a/gitlint-core/gitlint/tests/config/test_config.py
+++ b/gitlint-core/gitlint/tests/config/test_config.py
@@ -55,7 +55,7 @@ class LintConfigTests(BaseTestCase):
self.assertFalse(config.ignore_stdin)
self.assertFalse(config.staged)
self.assertFalse(config.fail_without_commits)
- self.assertFalse(config.regex_style_search)
+ self.assertTrue(config.regex_style_search)
self.assertFalse(config.debug)
self.assertEqual(config.verbosity, 3)
active_rule_classes = tuple(type(rule) for rule in config.rules)
@@ -291,7 +291,7 @@ class LintConfigTests(BaseTestCase):
("ignore_fixup_amend_commits", False),
("ignore_squash_commits", False),
("ignore_revert_commits", False),
- ("regex_style_search", True),
+ ("regex_style_search", False),
("rules", []),
("staged", True),
("target", self.get_sample_path()),
diff --git a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_debug_1 b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_debug_1
index 4b47566..7d69818 100644
--- a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_debug_1
+++ b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_debug_1
@@ -19,7 +19,7 @@ ignore-revert-commits: True
ignore-stdin: False
staged: False
fail-without-commits: False
-regex-style-search: False
+regex-style-search: True
verbosity: 1
debug: True
target: {target}
diff --git a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_input_stream_debug_2 b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_input_stream_debug_2
index 0d8070c..9278a92 100644
--- a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_input_stream_debug_2
+++ b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_input_stream_debug_2
@@ -19,7 +19,7 @@ ignore-revert-commits: True
ignore-stdin: False
staged: False
fail-without-commits: False
-regex-style-search: False
+regex-style-search: True
verbosity: 3
debug: True
target: {target}
diff --git a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_msg_filename_2 b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_msg_filename_2
index 751708f..eaa329b 100644
--- a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_msg_filename_2
+++ b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_msg_filename_2
@@ -19,7 +19,7 @@ ignore-revert-commits: True
ignore-stdin: False
staged: True
fail-without-commits: False
-regex-style-search: False
+regex-style-search: True
verbosity: 3
debug: True
target: {target}
diff --git a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_stdin_2 b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_stdin_2
index ff3f41e..0b09339 100644
--- a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_stdin_2
+++ b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_stdin_2
@@ -19,7 +19,7 @@ ignore-revert-commits: True
ignore-stdin: False
staged: True
fail-without-commits: False
-regex-style-search: False
+regex-style-search: True
verbosity: 3
debug: True
target: {target}
diff --git a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_named_rules_2 b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_named_rules_2
index 4d4b711..7773a0b 100644
--- a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_named_rules_2
+++ b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_named_rules_2
@@ -19,7 +19,7 @@ ignore-revert-commits: True
ignore-stdin: False
staged: False
fail-without-commits: False
-regex-style-search: False
+regex-style-search: True
verbosity: 3
debug: True
target: {target}
diff --git a/gitlint-core/gitlint/tests/rules/test_configuration_rules.py b/gitlint-core/gitlint/tests/rules/test_configuration_rules.py
index 9148f11..8589153 100644
--- a/gitlint-core/gitlint/tests/rules/test_configuration_rules.py
+++ b/gitlint-core/gitlint/tests/rules/test_configuration_rules.py
@@ -1,7 +1,6 @@
from gitlint import rules
from gitlint.config import LintConfig
from gitlint.tests.base import (
- EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING,
BaseTestCase,
)
@@ -25,7 +24,6 @@ class ConfigurationRuleTests(BaseTestCase):
self.assertEqual(config, expected_config)
expected_log_messages = [
- EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING.format("I1", "ignore-by-title"),
"DEBUG: gitlint.rules Ignoring commit because of rule 'I1': "
"Commit title 'Releäse' matches the regex '^Releäse(.*)', ignoring rules: all",
]
@@ -62,7 +60,6 @@ class ConfigurationRuleTests(BaseTestCase):
self.assertEqual(config, expected_config)
expected_log_messages = [
- EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING.format("I2", "ignore-by-body"),
"DEBUG: gitlint.rules Ignoring commit because of rule 'I2': "
"Commit message line ' a relëase body' matches the regex '(.*)relëase(.*)',"
" ignoring rules: all",
@@ -119,7 +116,6 @@ class ConfigurationRuleTests(BaseTestCase):
self.assertEqual(config, expected_config)
expected_log_messages += [
- EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING.format("I4", "ignore-by-author-name"),
"DEBUG: gitlint.rules Ignoring commit because of rule 'I4': "
"Commit Author Name 'Tëst nåme' matches the regex '(.*)ëst(.*)',"
" ignoring rules: all",
@@ -164,7 +160,6 @@ class ConfigurationRuleTests(BaseTestCase):
self.assertEqual(commit1, expected_commit)
self.assertEqual(config, LintConfig()) # config shouldn't have been modified
expected_log_messages = [
- EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING.format("I3", "ignore-body-lines"),
"DEBUG: gitlint.rules Ignoring line ' a relëase body' because it " + "matches '(.*)relëase(.*)'",
]
self.assert_logged(expected_log_messages)
diff --git a/gitlint-core/gitlint/tests/rules/test_meta_rules.py b/gitlint-core/gitlint/tests/rules/test_meta_rules.py
index a574aa3..137ea25 100644
--- a/gitlint-core/gitlint/tests/rules/test_meta_rules.py
+++ b/gitlint-core/gitlint/tests/rules/test_meta_rules.py
@@ -1,6 +1,5 @@
from gitlint.rules import AuthorValidEmail, RuleViolation
from gitlint.tests.base import (
- EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING,
BaseTestCase,
)
@@ -75,6 +74,3 @@ class MetaRuleTests(BaseTestCase):
commit = self.gitcommit("", author_email=email)
violations = rule.validate(commit)
self.assertListEqual(violations, [RuleViolation("M1", "Author email for commit is invalid", email)])
-
- # When a custom regex is used, a warning should be logged by default
- self.assert_logged([EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING.format("M1", "author-valid-email")])
diff --git a/gitlint-core/gitlint/tests/test_deprecation.py b/gitlint-core/gitlint/tests/test_deprecation.py
index bfe5934..9f796b4 100644
--- a/gitlint-core/gitlint/tests/test_deprecation.py
+++ b/gitlint-core/gitlint/tests/test_deprecation.py
@@ -1,6 +1,12 @@
from gitlint.config import LintConfig
from gitlint.deprecation import Deprecation
-from gitlint.rules import IgnoreByTitle
+from gitlint.rules import (
+ AuthorValidEmail,
+ IgnoreBodyLines,
+ IgnoreByAuthorName,
+ IgnoreByBody,
+ IgnoreByTitle,
+)
from gitlint.tests.base import (
EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING,
BaseTestCase,
@@ -11,16 +17,32 @@ class DeprecationTests(BaseTestCase):
def test_get_regex_method(self):
config = LintConfig()
Deprecation.config = config
- rule = IgnoreByTitle({"regex": "^Releäse(.*)"})
- # When general.regex-style-search=True, we expect regex.search to be returned and no warning to be logged
- config.regex_style_search = True
- regex_method = Deprecation.get_regex_method(rule, rule.options["regex"])
- self.assertEqual(regex_method, rule.options["regex"].value.search)
- self.assert_logged([])
+ # These rules have a regex option and are affected by the deprecation behavior
+ rules = [
+ AuthorValidEmail({"regex": "Föo(.*)"}),
+ IgnoreByTitle({"regex": "Föo(.*)"}),
+ IgnoreByBody({"regex": "Föo(.*)"}),
+ IgnoreByAuthorName({"regex": "Föo(.*)"}),
+ IgnoreBodyLines({"regex": "Föo(.*)"}),
+ ]
+
+ for rule in rules:
+ Deprecation.warning_msgs = set()
+ self.logcapture.clear()
+
+ # When general.regex-style-search=True, we expect regex.search to be returned and no warning to be logged
+ config.regex_style_search = True
+ regex_method = Deprecation.get_regex_method(rule, rule.options["regex"])
+ self.assertEqual(regex_method, rule.options["regex"].value.search)
+ self.assert_logged([])
+
+ # When general.regex-style-search=False, we expect regex.match to be returned and a warning to be logged
+ config.regex_style_search = False
+ regex_method = Deprecation.get_regex_method(rule, rule.options["regex"])
+ self.assertEqual(regex_method, rule.options["regex"].value.match)
+ self.assert_logged([EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING.format(rule.id, rule.name)])
- # When general.regex-style-search=False, we expect regex.match to be returned and a warning to be logged
- config.regex_style_search = False
- regex_method = Deprecation.get_regex_method(rule, rule.options["regex"])
- self.assertEqual(regex_method, rule.options["regex"].value.match)
- self.assert_logged([EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING.format("I1", "ignore-by-title")])
+ # Ensure we only log once per rule
+ Deprecation.get_regex_method(rule, rule.options["regex"])
+ self.assert_logged([EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING.format(rule.id, rule.name)])
diff --git a/qa/expected/test_commits/test_ignore_commits_1 b/qa/expected/test_commits/test_ignore_commits_1
index df04b7e..f9062c1 100644
--- a/qa/expected/test_commits/test_ignore_commits_1
+++ b/qa/expected/test_commits/test_ignore_commits_1
@@ -1,5 +1,3 @@
-WARNING: I1 - ignore-by-title: gitlint will be switching from using Python regex 'match' (match beginning) to 'search' (match anywhere) semantics. Please review your ignore-by-title.regex option accordingly. To remove this warning, set general.regex-style-search=True. More details: https://jorisroovers.github.io/gitlint/configuration/general_options/#regex-style-search
-WARNING: I2 - ignore-by-body: gitlint will be switching from using Python regex 'match' (match beginning) to 'search' (match anywhere) semantics. Please review your ignore-by-body.regex option accordingly. To remove this warning, set general.regex-style-search=True. More details: https://jorisroovers.github.io/gitlint/configuration/general_options/#regex-style-search
Commit {commit_sha0}:
1: T3 Title has trailing punctuation (.): "Sïmple title4."
diff --git a/qa/expected/test_commits/test_lint_staged_msg_filename_1 b/qa/expected/test_commits/test_lint_staged_msg_filename_1
index fe633ca..022c484 100644
--- a/qa/expected/test_commits/test_lint_staged_msg_filename_1
+++ b/qa/expected/test_commits/test_lint_staged_msg_filename_1
@@ -20,7 +20,7 @@ ignore-revert-commits: True
ignore-stdin: False
staged: True
fail-without-commits: False
-regex-style-search: False
+regex-style-search: True
verbosity: 3
debug: True
target: {target}
diff --git a/qa/expected/test_commits/test_lint_staged_stdin_1 b/qa/expected/test_commits/test_lint_staged_stdin_1
index 47c7900..f541bc7 100644
--- a/qa/expected/test_commits/test_lint_staged_stdin_1
+++ b/qa/expected/test_commits/test_lint_staged_stdin_1
@@ -20,7 +20,7 @@ ignore-revert-commits: True
ignore-stdin: False
staged: True
fail-without-commits: False
-regex-style-search: False
+regex-style-search: True
verbosity: 3
debug: True
target: {target}
diff --git a/qa/expected/test_config/test_config_from_env_1 b/qa/expected/test_config/test_config_from_env_1
index 9b0d17c..6e01f6e 100644
--- a/qa/expected/test_config/test_config_from_env_1
+++ b/qa/expected/test_config/test_config_from_env_1
@@ -20,7 +20,7 @@ ignore-revert-commits: True
ignore-stdin: True
staged: False
fail-without-commits: True
-regex-style-search: False
+regex-style-search: True
verbosity: 2
debug: True
target: {target}
diff --git a/qa/expected/test_config/test_config_from_env_2 b/qa/expected/test_config/test_config_from_env_2
index 75dba83..652dbf3 100644
--- a/qa/expected/test_config/test_config_from_env_2
+++ b/qa/expected/test_config/test_config_from_env_2
@@ -20,7 +20,7 @@ ignore-revert-commits: True
ignore-stdin: False
staged: True
fail-without-commits: False
-regex-style-search: False
+regex-style-search: True
verbosity: 0
debug: True
target: {target}
diff --git a/qa/expected/test_config/test_config_from_file_debug_1 b/qa/expected/test_config/test_config_from_file_debug_1
index 17fa3aa..eb37971 100644
--- a/qa/expected/test_config/test_config_from_file_debug_1
+++ b/qa/expected/test_config/test_config_from_file_debug_1
@@ -20,7 +20,7 @@ ignore-revert-commits: True
ignore-stdin: False
staged: False
fail-without-commits: False
-regex-style-search: False
+regex-style-search: True
verbosity: 2
debug: True
target: {target}
diff --git a/qa/expected/test_gitlint/test_commit_binary_file_1 b/qa/expected/test_gitlint/test_commit_binary_file_1
index efede85..7038b74 100644
--- a/qa/expected/test_gitlint/test_commit_binary_file_1
+++ b/qa/expected/test_gitlint/test_commit_binary_file_1
@@ -20,7 +20,7 @@ ignore-revert-commits: True
ignore-stdin: False
staged: False
fail-without-commits: False
-regex-style-search: False
+regex-style-search: True
verbosity: 3
debug: True
target: {target}