From 61a50e1073afd0a59910ac28e8de6937cdab7556 Mon Sep 17 00:00:00 2001 From: uy_sun Date: Sat, 2 Sep 2023 11:42:47 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E4=BD=BF=E7=94=A8=20ruff=20=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/codecov.yml | 8 ++++---- .pre-commit-config.yaml | 24 +++++++++++------------- .vscode/launch.json | 7 ++----- nonebot_plugin_treehelp/data_source.py | 7 +------ pyproject.toml | 4 ++++ tests/conftest.py | 1 - tests/plugins/nested/plugins/sub2.py | 2 +- tests/test_help.py | 4 ++-- 8 files changed, 25 insertions(+), 32 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 369ff82..1a018dd 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -46,7 +46,7 @@ jobs: needs: test runs-on: ubuntu-latest steps: - - name: Decide whether the needed jobs succeeded or failed - uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe - with: - jobs: ${{ toJSON(needs) }} + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe + with: + jobs: ${{ toJSON(needs) }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9ed08c0..fc02e90 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,30 +5,28 @@ ci: autoupdate_schedule: weekly autoupdate_commit_msg: "chore: auto update by pre-commit hooks" repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.286 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + stages: [commit] + - repo: https://github.com/pycqa/isort rev: 5.12.0 hooks: - id: isort + stages: [commit] - repo: https://github.com/psf/black rev: 23.7.0 hooks: - id: black + stages: [commit] - repo: https://github.com/pre-commit/mirrors-prettier rev: v3.0.0 hooks: - id: prettier - types_or: [markdown] - - - repo: https://github.com/asottile/pyupgrade - rev: v3.9.0 - hooks: - - id: pyupgrade - args: [--py38-plus] - - - repo: https://github.com/hadialqattan/pycln - rev: v2.1.6 - hooks: - - id: pycln - args: [--config, pyproject.toml] + types_or: [javascript, jsx, ts, tsx, markdown, yaml, json] + stages: [commit] diff --git a/.vscode/launch.json b/.vscode/launch.json index b49d8b7..9571788 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,10 +9,7 @@ "type": "python", "request": "launch", "module": "nb_cli", - "args": [ - "run", - "--reload" - ], + "args": ["run", "--reload"], "justMyCode": false }, { @@ -22,4 +19,4 @@ "module": "pytest" } ] -} \ No newline at end of file +} diff --git a/nonebot_plugin_treehelp/data_source.py b/nonebot_plugin_treehelp/data_source.py index 7868f5f..d22ea35 100644 --- a/nonebot_plugin_treehelp/data_source.py +++ b/nonebot_plugin_treehelp/data_source.py @@ -42,12 +42,7 @@ def map_command_to_plguin(plugin: "Plugin"): def format_description(plugins: List["Plugin"]) -> str: """格式化描述""" return "\n".join( - sorted( - map( - lambda x: f"{x.metadata.name} # {x.metadata.description}", # type: ignore - plugins, - ) - ) + sorted(f"{x.metadata.name} # {x.metadata.description}" for x in plugins) ) diff --git a/pyproject.toml b/pyproject.toml index ca2c3c7..ac20e3d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,6 +41,10 @@ pythonVersion = "3.8" pythonPlatform = "All" typeCheckingMode = "basic" +[tool.ruff] +select = ["E", "W", "F", "UP", "C", "T", "PYI", "Q"] +ignore = ["E402", "E501", "C901", "UP037"] + [tool.nonebot] adapters = [ { name = "OneBot V11", module_name = "nonebot.adapters.onebot.v11" }, diff --git a/tests/conftest.py b/tests/conftest.py index 0c93d5d..aac9f12 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,6 @@ import nonebot import pytest from nonebug import NONEBOT_INIT_KWARGS, App -from nonebug.app import App from .utils import clear_plugins diff --git a/tests/plugins/nested/plugins/sub2.py b/tests/plugins/nested/plugins/sub2.py index b57926e..8d5dd9b 100644 --- a/tests/plugins/nested/plugins/sub2.py +++ b/tests/plugins/nested/plugins/sub2.py @@ -1,6 +1,6 @@ from nonebot.plugin import PluginMetadata -from .sub1 import plugin_id +from .sub1 import plugin_id # noqa: F401 __plugin_meta__ = PluginMetadata( name="功能二", diff --git a/tests/test_help.py b/tests/test_help.py index dfe5e06..09a30a4 100644 --- a/tests/test_help.py +++ b/tests/test_help.py @@ -5,7 +5,7 @@ async def test_help(app: App): """测试帮助""" - from nonebot_plugin_treehelp import __plugin_meta__, help_cmd + from nonebot_plugin_treehelp import help_cmd async with app.test_matcher(help_cmd) as ctx: bot = ctx.create_bot() @@ -13,7 +13,7 @@ async def test_help(app: App): event = make_fake_event(_message=message)() ctx.receive_event(bot, event) - ctx.should_call_send(event, f"插件:\n帮助 # 获取插件帮助信息", True) + ctx.should_call_send(event, "插件:\n帮助 # 获取插件帮助信息", True) ctx.should_finished()