1
0
mirror of https://github.com/home-assistant/core synced 2024-07-08 20:17:01 +00:00

Add pylint directory to black pre-commit (#78011)

Add pylint to black CI
This commit is contained in:
epenet 2022-09-08 09:14:58 +02:00 committed by GitHub
parent 37631d2017
commit 23168434d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -11,7 +11,7 @@ repos:
args:
- --safe
- --quiet
files: ^((homeassistant|script|tests)/.+)?[^/]+\.py$
files: ^((homeassistant|pylint|script|tests)/.+)?[^/]+\.py$
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:

View File

@ -303,9 +303,13 @@ class HassImportsFormatChecker(BaseChecker): # type: ignore[misc]
if module.startswith(f"{self.current_package}."):
self.add_message("hass-relative-import", node=node)
def _visit_importfrom_relative(self, current_package: str, node: nodes.ImportFrom) -> None:
def _visit_importfrom_relative(
self, current_package: str, node: nodes.ImportFrom
) -> None:
"""Called when a ImportFrom node is visited."""
if node.level <= 1 or not current_package.startswith("homeassistant.components"):
if node.level <= 1 or not current_package.startswith(
"homeassistant.components"
):
return
split_package = current_package.split(".")
if not node.modname and len(split_package) == node.level + 1:
@ -330,7 +334,10 @@ class HassImportsFormatChecker(BaseChecker): # type: ignore[misc]
):
self.add_message("hass-relative-import", node=node)
return
if self.current_package.startswith("homeassistant.components") and node.modname == "homeassistant.components":
if (
self.current_package.startswith("homeassistant.components")
and node.modname == "homeassistant.components"
):
for name in node.names:
if name[0] == self.current_package.split(".")[2]:
self.add_message("hass-relative-import", node=node)