Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Add ruff linter #62

Merged
merged 7 commits into from
May 30, 2024
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
7 changes: 4 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ jobs:
id: python
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: '3.11'
- name: Install dependencies
id: install-deps
run: |
python3 -m pip install --upgrade black
python3 -m pip install --upgrade ruff
python3 -m pip install --upgrade requests
python3 -m pip install --upgrade nextcord
- name: Test 1
run: "black --check ."
uses: chartboost/ruff-action@v1
env:
PR_TESTING: 1
- name: Test 2
Expand Down
13 changes: 8 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ ci:
style: auto fixes from pre-commit hooks
autofix_prs: true
repos:
- repo: https://github.com/psf/black
rev: 24.4.2
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.6
hooks:
- id: black
name: Run black in files

# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
Expand Down
4 changes: 1 addition & 3 deletions _orangcbot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from __future__ import annotations

from os import environ, getenv
from os import environ

from dotenv import load_dotenv

load_dotenv()
import os
import traceback

import nextcord
import psycopg2
from nextcord import ApplicationError, Intents
from nextcord.ext import application_checks as ac
from nextcord.ext import commands, help_commands
Expand Down
4 changes: 2 additions & 2 deletions _orangcbot/extensions/archwiki.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Final, Generic, Self, TypeVar
from typing import Final, Generic, Self, TypeVar

import aiohttp
import nextcord
from nextcord import SlashOption, slash_command
from nextcord import SlashOption
from nextcord.ext import commands, menus

T = TypeVar("T")
Expand Down
4 changes: 1 addition & 3 deletions _orangcbot/extensions/delete_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ async def on_raw_reaction_add(self, event: nextcord.RawReactionActionEvent) -> N
if event.event_type == "REACTION_ADD":
# print(event.emoji == "<:delete:1236642973576331328>")
if str(event.emoji) == "<:delete:1236642973576331328>":

# Do not delete suggestions
if event.channel_id == 1236200920317169695:
return
n = await self._bot.get_channel(event.channel_id).fetch_message(
event.message_id
)
if self._bot.get_user(event.user_id).bot == False: # type: ignore[reportOptionalMemberAccess]
if not self._bot.get_user(event.user_id).bot: # type: ignore[reportOptionalMemberAccess]
if n.author.id == self._bot.user.id: # type: ignore[reportOptionalMemberAccess]

await n.delete()
else:
pass
Expand Down
1 change: 0 additions & 1 deletion _orangcbot/extensions/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import TYPE_CHECKING

import nextcord
import whois
from dns import resolver as _dnsresolver
from nextcord.ext import commands

Expand Down
1 change: 0 additions & 1 deletion _orangcbot/extensions/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import datetime

# import os
from os import getenv

_psl = PSL()
import random
Expand Down
2 changes: 1 addition & 1 deletion _orangcbot/extensions/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def on_message(self, message: nextcord.Message):
return
full_matches: List[re.Match] = re.findall(FULL_MATCH_ANY_REPO, message.content)
# print(full_matches)
is_a_dev_matches: List[re.Match] = re.findall(
is_a_dev_matches: List[re.Match] = re.findall( # noqa: F841
MATCH_IS_A_DEV_ONLY, message.content
)
pr_list: List[_PRRawObject] = []
Expand Down
2 changes: 1 addition & 1 deletion _orangcbot/extensions/nixwiki.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Generic, TypeVar
from typing import Generic, TypeVar

import aiohttp
import nextcord
Expand Down
6 changes: 3 additions & 3 deletions _orangcbot/extensions/nonsense.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import re
from typing import TYPE_CHECKING, Literal, Optional
from typing import TYPE_CHECKING, Optional

import aiohttp
import nextcord
Expand Down Expand Up @@ -266,7 +266,7 @@ async def check(
self, ctx: commands.Context, domain: SubdomainNameConverter
) -> None:
try:
data = await request(
await request(
True,
"GET",
f"https://raw.githubusercontent.com/is-a-dev/register/main/domains/{domain}.json",
Expand All @@ -291,7 +291,7 @@ async def check(
),
) -> None:
try:
data = await request(
await request(
True,
"GET",
f"https://raw.githubusercontent.com/is-a-dev/register/main/domains/{domain}.json",
Expand Down
1 change: 1 addition & 0 deletions _orangcbot/extensions/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Final, List, Optional, Tuple

import nextcord
from nextcord import Embed
from nextcord.ext import commands, menus

RULES: Final[List[str]] = [
Expand Down
2 changes: 1 addition & 1 deletion _orangcbot/extensions/suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# from models.basecog import BaseCog

if TYPE_CHECKING:
from nextcord import TextChannel
pass


class Suggestion(commands.Cog):
Expand Down
1 change: 1 addition & 0 deletions _orangcbot/extensions/tags.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa
from nextcord.ext import commands

nohelp = """
Expand Down
8 changes: 4 additions & 4 deletions _orangcbot/extensions/tags_reworked.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async def callback(self, interaction: nextcord.Interaction) -> None:
try:
cursor.execute(
# f"INSERT INTO taginfo VALUES('{id.hex}', '{self.my_name.value}', '{self.my_title.value}', '{self.my_content.value}', '{str(interaction.user.id)}')"
f"INSERT INTO taginfo VALUES(%s, %s, %s, %s, %s)",
"INSERT INTO taginfo VALUES(%s, %s, %s, %s, %s)",
(
id.hex,
self.my_name.value,
Expand Down Expand Up @@ -207,7 +207,7 @@ async def find(
"""Request a tag"""
with self._db.cursor() as cursor:
cursor.execute("SELECT * FROM taginfo\nWHERE name=%s", (tag_name,))
if info := cursor.fetchone():
if info := cursor.fetchone() is not None:
# print(info)
await interaction.send(
embed=nextcord.Embed(
Expand All @@ -228,7 +228,7 @@ async def delete(
"""Delete a tag"""
with self._db.cursor() as cursor:
cursor.execute("SELECT * FROM taginfo WHERE name=%s", (tag_name,))
if info := cursor.fetchone():
if cursor.fetchone() is not None:
cursor.execute("DELETE FROM taginfo WHERE name=%s", (tag_name,))
self._db.commit()
await interaction.send("Done")
Expand Down Expand Up @@ -320,7 +320,7 @@ async def delete(self, ctx: commands.Context, tag_name: str):
"""Delete a tag."""
with self._db.cursor() as cursor:
cursor.execute("SELECT * FROM taginfo WHERE name=%s", (tag_name,))
if info := cursor.fetchone():
if cursor.fetchone():
cursor.execute("DELETE FROM taginfo WHERE name=%s", (tag_name,))
self._db.commit()
await ctx.send("Done")
Expand Down
1 change: 0 additions & 1 deletion _orangcbot/extensions/testing_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import nextcord
from nextcord.ext import commands


Expand Down
5 changes: 5 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

[lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
select = ["E4", "E7", "E9", "F"]
ignore = ["E741", "E402", "E722"]
Loading