浏览代码

Add flake8-quotes information to pyproject.toml for ruff fixable (#4783)

### Motivation

I kept having "problems" with using " instead of ' for strings when
commiting changes. As we're currently using ruff for some fixing

```toml
fixable = [
    "I",  # isort
    "RUF022", # `__all__` is not sorted
]
```
and
```json
  "[python]": {
    "editor.defaultFormatter": "ms-python.autopep8",
    "editor.codeActionsOnSave": {
      "source.fixAll.ruff": "always"
    }
  }
```

Adding quote fixing to the fixable list would automatically fix this and
we'll have less build-errors when commiting.

In an earlier PR I made
(https://github.com/zauberzeug/nicegui/pull/4368) we come to the
conclusion to not use ruff for the formating but some time after fixable
got added so I don't see any problems adding ruff's quote fixing there
as it only will fix the quotes.

### Progress

- [x] I chose a meaningful title that completes the sentence: "If
applied, this PR will..."
- [x] The implementation is complete.
- [x] Pytests have been added (or are not necessary).
- [x] Documentation has been added (or is not necessary).

---------

Co-authored-by: Falko Schindler <falko@zauberzeug.com>
Ember Light 2 天之前
父节点
当前提交
9531bb5382
共有 2 个文件被更改,包括 13 次插入0 次删除
  1. 1 0
      .vscode/settings.json
  2. 12 0
      pyproject.toml

+ 1 - 0
.vscode/settings.json

@@ -5,6 +5,7 @@
   "python.testing.pytestArgs": ["."],
   "python.testing.pytestEnabled": true,
   "python.testing.unittestEnabled": false,
+  "files.insertFinalNewline": true,
   "[python]": {
     "editor.defaultFormatter": "ms-python.autopep8",
     "editor.codeActionsOnSave": {

+ 12 - 0
pyproject.toml

@@ -137,6 +137,12 @@ target-version = "py38"
 indent-width = 4
 line-length = 120
 
+[tool.ruff.lint.flake8-quotes]
+inline-quotes = "single"
+multiline-quotes = "single"
+docstring-quotes = "double"
+avoid-escape = true
+
 [tool.ruff.lint]
 # See complete list: https://docs.astral.sh/ruff/rules/
 select = [
@@ -148,10 +154,16 @@ select = [
     "UP", # pyupgrade
     "RUF", # ruff
     "PL", # pylint
+    "Q", # flake8-quotes
 ]
 fixable = [
     "I",  # isort
     "RUF022", # `__all__` is not sorted
+    "Q000",  # bad quotes inline string
+    "Q001",  # bad quotes multiline string
+    "Q002",  # bad quotes docstring
+    "Q003",  # avoidable escaped quote
+    "Q004",  # unnecessary escaped quote
 ]
 ignore = [
     "E501", # line too long