summaryrefslogtreecommitdiffstats
path: root/gitlint-core/gitlint/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'gitlint-core/gitlint/config.py')
-rw-r--r--gitlint-core/gitlint/config.py35
1 files changed, 19 insertions, 16 deletions
diff --git a/gitlint-core/gitlint/config.py b/gitlint-core/gitlint/config.py
index f038d4a..4b38d90 100644
--- a/gitlint-core/gitlint/config.py
+++ b/gitlint-core/gitlint/config.py
@@ -1,17 +1,19 @@
-from configparser import ConfigParser, Error as ConfigParserError
-
import copy
-import re
import os
+import re
import shutil
-
from collections import OrderedDict
-from gitlint.utils import DEFAULT_ENCODING
-from gitlint import rules # For some weird reason pylint complains about this, pylint: disable=unused-import
-from gitlint import options
-from gitlint import rule_finder
+from configparser import ConfigParser
+from configparser import Error as ConfigParserError
+
+from gitlint import (
+ options,
+ rule_finder,
+ rules,
+)
from gitlint.contrib import rules as contrib_rules
from gitlint.exception import GitlintError
+from gitlint.utils import FILE_ENCODING
def handle_option_error(func):
@@ -31,7 +33,7 @@ class LintConfigError(GitlintError):
pass
-class LintConfig: # pylint: disable=too-many-instance-attributes
+class LintConfig:
"""Class representing gitlint configuration.
Contains active config as well as number of methods to easily get/set the config.
"""
@@ -105,7 +107,7 @@ class LintConfig: # pylint: disable=too-many-instance-attributes
@handle_option_error
def verbosity(self, value):
self._verbosity.set(value)
- if self.verbosity < 0 or self.verbosity > 3:
+ if self.verbosity < 0 or self.verbosity > 3: # noqa: PLR2004 (Magic value used in comparison)
raise LintConfigError("Option 'verbosity' must be set between 0 and 3")
@property
@@ -294,7 +296,7 @@ class LintConfig: # pylint: disable=too-many-instance-attributes
if not hasattr(self, attr_name) or attr_name[0] == "_":
raise LintConfigError(f"'{option_name}' is not a valid gitlint option")
- # else:
+ # else
setattr(self, attr_name, option_value)
def __eq__(self, other):
@@ -384,7 +386,7 @@ class RuleCollection:
"""Deletes all rules from the collection that match a given attribute name and value"""
# Create a new list based on _rules.values() because in python 3, values() is a ValuesView as opposed to a list
# This means you can't modify the ValueView while iterating over it.
- for rule in [r for r in self._rules.values()]: # pylint: disable=unnecessary-comprehension
+ for rule in list(self._rules.values()):
if hasattr(rule, attr_name) and (getattr(rule, attr_name) == attr_val):
del self._rules[rule.id]
@@ -466,7 +468,7 @@ class LintConfigBuilder:
try:
parser = ConfigParser()
- with open(filename, encoding=DEFAULT_ENCODING) as config_file:
+ with open(filename, encoding=FILE_ENCODING) as config_file:
parser.read_file(config_file, filename)
for section_name in parser.sections():
@@ -528,14 +530,15 @@ class LintConfigBuilder:
for section_name, section_dict in self._config_blueprint.items():
for option_name, option_value in section_dict.items():
+ qualified_section_name = section_name
# Skip over the general section, as we've already done that above
- if section_name != "general":
+ if qualified_section_name != "general":
# If the section name contains a colon (:), then this section is defining a Named Rule
# Which means we need to instantiate that Named Rule in the config.
if self.RULE_QUALIFIER_SYMBOL in section_name:
- section_name = self._add_named_rule(config, section_name)
+ qualified_section_name = self._add_named_rule(config, qualified_section_name)
- config.set_rule_option(section_name, option_name, option_value)
+ config.set_rule_option(qualified_section_name, option_name, option_value)
return config