Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address pylint missing-function-docstring #1998

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ disable =
dangerous-default-value,
duplicate-code,
fixme,
missing-function-docstring,
no-member,
not-callable,
protected-access,
Expand Down
3 changes: 2 additions & 1 deletion src/ansiblelint/formatters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def _format_path(self, path: Union[str, Path]) -> str:

# pylint: disable=no-self-use
def format(self, match: "MatchError") -> str:
"""Format a match error."""
return str(match)

@staticmethod
Expand Down Expand Up @@ -154,7 +155,7 @@ class CodeclimateJSONFormatter(BaseFormatter[Any]):
"""

def format_result(self, matches: List["MatchError"]) -> str:

"""Format a list of match errors as a JSON string."""
if not isinstance(matches, list):
raise RuntimeError(
f"The {self.__class__} was expecting a list of MatchError."
Expand Down
7 changes: 7 additions & 0 deletions src/ansiblelint/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class AnsibleLintRule(BaseRule):

@property
def rule_config(self) -> Dict[str, Any]:
"""Retrieve rule specific configuration."""
return get_rule_config(self.id)

@lru_cache()
Expand All @@ -57,6 +58,7 @@ def __repr__(self) -> str:

@staticmethod
def unjinja(text: str) -> str:
"""Remove jinja2 bits from a string."""
text = re.sub(r"{{.+?}}", "JINJA_EXPRESSION", text)
text = re.sub(r"{%.+?%}", "JINJA_STATEMENT", text)
text = re.sub(r"{#.+?#}", "JINJA_COMMENT", text)
Expand All @@ -71,6 +73,7 @@ def create_matcherror(
filename: Optional[Union[str, Lintable]] = None,
tag: str = "",
) -> MatchError:
"""Instantiate a new MatchError."""
match = MatchError(
message=message,
linenumber=linenumber,
Expand Down Expand Up @@ -251,6 +254,7 @@ def __init__(
self.rules = sorted(self.rules)

def register(self, obj: AnsibleLintRule) -> None:
"""Register a rule."""
# We skip opt-in rules which were not manually enabled
if "opt-in" not in obj.tags or obj.id in self.options.enable_list:
self.rules.append(obj)
Expand All @@ -264,11 +268,13 @@ def __len__(self) -> int:
return len(self.rules)

def extend(self, more: List[AnsibleLintRule]) -> None:
"""Combine rules."""
self.rules.extend(more)

def run(
self, file: Lintable, tags: Set[str] = set(), skip_list: List[str] = []
) -> List[MatchError]:
"""Run all the rules against the given lintable."""
matches: List[MatchError] = []

if not file.path.is_dir():
Expand Down Expand Up @@ -309,6 +315,7 @@ def __repr__(self) -> str:
)

def listtags(self) -> str:
"""Return a string with all the tags in the RulesCollection."""
tag_desc = {
"command-shell": "Specific to use of command and shell modules",
"core": "Related to internal implementation of the linter",
Expand Down
15 changes: 8 additions & 7 deletions src/ansiblelint/rules/risky_octal.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ class OctalPermissionsRule(AnsibleLintRule):

@staticmethod
def is_invalid_permission(mode: int) -> bool:
# sensible file permission modes don't
# have write bit set when read bit is
# not set and don't have execute bit set
# when user execute bit is not set.
# also, user permissions are more generous than
# group permissions and user and group permissions
# are more generous than world permissions
"""Check if permissions are valid.

Sensible file permission modes don't have write bit set when read bit
is not set and don't have execute bit set when user execute bit is
not set.

Also, user permissions are more generous than group permissions and
user and group permissions are more generous than world permissions.
"""
other_write_without_read = (
mode % 8 and mode % 8 < 4 and not (mode % 8 == 1 and (mode >> 6) % 2 == 1)
)
Expand Down