Skip to content

Commit

Permalink
Add ruff (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Mar 1, 2023
1 parent 8af5d3b commit 0bcf3b6
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 8 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "Lint"

on:
push:
branches:
- "main"
pull_request:
branches:
- "main"

jobs:
ruff:
name: "Ruff"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout the repository"
uses: "actions/checkout@v3.3.0"

- name: "Set up Python"
uses: actions/setup-python@v4.5.0
with:
python-version: "3.10"
cache: "pip"

- name: "Install requirements"
run: python3 -m pip install -r requirements.txt

- name: "Run"
run: python3 -m ruff check .
48 changes: 48 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# The contents of this file is based on https://github.com/home-assistant/core/blob/dev/pyproject.toml

target-version = "py310"

select = [
"B007", # Loop control variable {name} not used within loop body
"B014", # Exception handler with duplicate exception
"C", # complexity
"D", # docstrings
"E", # pycodestyle
"F", # pyflakes/autoflake
"ICN001", # import concentions; {name} should be imported as {asname}
"PGH004", # Use specific rule codes when using noqa
"PLC0414", # Useless import alias. Import alias does not rename original package.
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
"SIM117", # Merge with-statements that use the same scope
"SIM118", # Use {key} in {dict} instead of {key} in {dict}.keys()
"SIM201", # Use {left} != {right} instead of not {left} == {right}
"SIM212", # Use {a} if {a} else {b} instead of {b} if not {a} else {a}
"SIM300", # Yoda conditions. Use 'age == 42' instead of '42 == age'.
"SIM401", # Use get from dict with default instead of an if block
"T20", # flake8-print
"TRY004", # Prefer TypeError exception for invalid type
"RUF006", # Store a reference to the return value of asyncio.create_task
"UP", # pyupgrade
"W", # pycodestyle
]

ignore = [
"D202", # No blank lines allowed after function docstring
"D203", # 1 blank line required before class docstring
"D213", # Multi-line docstring summary should start at the second line
"D404", # First word of the docstring should not be This
"D406", # Section name should end with a newline
"D407", # Section name underlining
"D411", # Missing blank line before section
"E501", # line too long
"E731", # do not assign a lambda expression, use a def
]

[flake8-pytest-style]
fixture-parentheses = false

[pyupgrade]
keep-runtime-typing = true

[mccabe]
max-complexity = 25
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pull requests are the best way to propose changes to the codebase.

1. Fork the repo and create your branch from `main`.
2. If you've changed something, update the documentation.
3. Make sure your code lints (using black).
3. Make sure your code lints (using `scripts/lint`).
4. Test you contribution.
5. Issue that pull request!

Expand Down
3 changes: 1 addition & 2 deletions custom_components/integration_blueprint/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
Custom integration to integrate integration_blueprint with Home Assistant.
"""Custom integration to integrate integration_blueprint with Home Assistant.
For more details about this integration, please refer to
https://github.com/ludeeus/integration_blueprint
Expand Down
3 changes: 2 additions & 1 deletion custom_components/integration_blueprint/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


async def async_setup_entry(hass, entry, async_add_devices):
"""Setup binary_sensor platform."""
"""Set up the binary_sensor platform."""
coordinator = hass.data[DOMAIN][entry.entry_id]
async_add_devices(
IntegrationBlueprintBinarySensor(
Expand All @@ -40,6 +40,7 @@ def __init__(
coordinator: BlueprintDataUpdateCoordinator,
entity_description: BinarySensorEntityDescription,
) -> None:
"""Initialize the binary_sensor class."""
super().__init__(coordinator)
self.entity_description = entity_description

Expand Down
2 changes: 1 addition & 1 deletion custom_components/integration_blueprint/entity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""BlueprintEntity class"""
"""BlueprintEntity class."""
from __future__ import annotations

from homeassistant.helpers.entity import DeviceInfo
Expand Down
3 changes: 2 additions & 1 deletion custom_components/integration_blueprint/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


async def async_setup_entry(hass, entry, async_add_devices):
"""Setup sensor platform."""
"""Set up the sensor platform."""
coordinator = hass.data[DOMAIN][entry.entry_id]
async_add_devices(
IntegrationBlueprintSensor(
Expand All @@ -36,6 +36,7 @@ def __init__(
coordinator: BlueprintDataUpdateCoordinator,
entity_description: SensorEntityDescription,
) -> None:
"""Initialize the sensor class."""
super().__init__(coordinator)
self.entity_description = entity_description

Expand Down
3 changes: 2 additions & 1 deletion custom_components/integration_blueprint/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


async def async_setup_entry(hass, entry, async_add_devices):
"""Setup sensor platform."""
"""Set up the sensor platform."""
coordinator = hass.data[DOMAIN][entry.entry_id]
async_add_devices(
IntegrationBlueprintSwitch(
Expand All @@ -36,6 +36,7 @@ def __init__(
coordinator: BlueprintDataUpdateCoordinator,
entity_description: SwitchEntityDescription,
) -> None:
"""Initialize the switch class."""
super().__init__(coordinator)
self.entity_description = entity_description

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
colorlog==6.7.0
homeassistant==2022.2.0
pip>=21.0,<23.1
pip>=8.0.3,<20.3
ruff==0.0.253
7 changes: 7 additions & 0 deletions scripts/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "$0")/.."

ruff check . --fix

0 comments on commit 0bcf3b6

Please sign in to comment.