summaryrefslogtreecommitdiffstats
path: root/gitlint-core/gitlint/options.py
diff options
context:
space:
mode:
Diffstat (limited to 'gitlint-core/gitlint/options.py')
-rw-r--r--gitlint-core/gitlint/options.py34
1 files changed, 16 insertions, 18 deletions
diff --git a/gitlint-core/gitlint/options.py b/gitlint-core/gitlint/options.py
index e5b7335..50565ea 100644
--- a/gitlint-core/gitlint/options.py
+++ b/gitlint-core/gitlint/options.py
@@ -6,7 +6,7 @@ from gitlint.exception import GitlintError
def allow_none(func):
- """ Decorator that sets option value to None if the passed value is None, otherwise calls the regular set method """
+ """Decorator that sets option value to None if the passed value is None, otherwise calls the regular set method"""
def wrapped(obj, value):
if value is None:
@@ -22,10 +22,10 @@ class RuleOptionError(GitlintError):
class RuleOption:
- """ Base class representing a configurable part (i.e. option) of a rule (e.g. the max-length of the title-max-line
- rule).
- This class should not be used directly. Instead, use on the derived classes like StrOption, IntOption to set
- options of a particular type like int, str, etc.
+ """Base class representing a configurable part (i.e. option) of a rule (e.g. the max-length of the title-max-line
+ rule).
+ This class should not be used directly. Instead, use on the derived classes like StrOption, IntOption to set
+ options of a particular type like int, str, etc.
"""
def __init__(self, name, value, description):
@@ -36,7 +36,7 @@ class RuleOption:
@abstractmethod
def set(self, value):
- """ Validates and sets the option's value """
+ """Validates and sets the option's value"""
pass # pragma: no cover
def __str__(self):
@@ -76,18 +76,16 @@ class IntOption(RuleOption):
class BoolOption(RuleOption):
-
# explicit choice to not annotate with @allow_none: Booleans must be False or True, they cannot be unset.
def set(self, value):
value = str(value).strip().lower()
- if value not in ['true', 'false']:
+ if value not in ["true", "false"]:
raise RuleOptionError(f"Option '{self.name}' must be either 'true' or 'false'")
- self.value = value == 'true'
+ self.value = value == "true"
class ListOption(RuleOption):
- """ Option that is either a given list or a comma-separated string that can be split into a list when being set.
- """
+ """Option that is either a given list or a comma-separated string that can be split into a list when being set."""
@allow_none
def set(self, value):
@@ -100,7 +98,7 @@ class ListOption(RuleOption):
class PathOption(RuleOption):
- """ Option that accepts either a directory or both a directory and a file. """
+ """Option that accepts either a directory or both a directory and a file."""
def __init__(self, name, value, description, type="dir"):
self.type = type
@@ -112,16 +110,17 @@ class PathOption(RuleOption):
error_msg = ""
- if self.type == 'dir':
+ if self.type == "dir":
if not os.path.isdir(value):
error_msg = f"Option {self.name} must be an existing directory (current value: '{value}')"
- elif self.type == 'file':
+ elif self.type == "file":
if not os.path.isfile(value):
error_msg = f"Option {self.name} must be an existing file (current value: '{value}')"
- elif self.type == 'both':
+ elif self.type == "both":
if not os.path.isdir(value) and not os.path.isfile(value):
- error_msg = (f"Option {self.name} must be either an existing directory or file "
- f"(current value: '{value}')")
+ error_msg = (
+ f"Option {self.name} must be either an existing directory or file (current value: '{value}')"
+ )
else:
error_msg = f"Option {self.name} type must be one of: 'file', 'dir', 'both' (current: '{self.type}')"
@@ -132,7 +131,6 @@ class PathOption(RuleOption):
class RegexOption(RuleOption):
-
@allow_none
def set(self, value):
try: