Ver Fonte

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 há 2 dias atrás
pai
commit
9531bb5382
2 ficheiros alterados com 13 adições e 0 exclusões
  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.pytestArgs": ["."],
   "python.testing.pytestEnabled": true,
   "python.testing.pytestEnabled": true,
   "python.testing.unittestEnabled": false,
   "python.testing.unittestEnabled": false,
+  "files.insertFinalNewline": true,
   "[python]": {
   "[python]": {
     "editor.defaultFormatter": "ms-python.autopep8",
     "editor.defaultFormatter": "ms-python.autopep8",
     "editor.codeActionsOnSave": {
     "editor.codeActionsOnSave": {

+ 12 - 0
pyproject.toml

@@ -137,6 +137,12 @@ target-version = "py38"
 indent-width = 4
 indent-width = 4
 line-length = 120
 line-length = 120
 
 
+[tool.ruff.lint.flake8-quotes]
+inline-quotes = "single"
+multiline-quotes = "single"
+docstring-quotes = "double"
+avoid-escape = true
+
 [tool.ruff.lint]
 [tool.ruff.lint]
 # See complete list: https://docs.astral.sh/ruff/rules/
 # See complete list: https://docs.astral.sh/ruff/rules/
 select = [
 select = [
@@ -148,10 +154,16 @@ select = [
     "UP", # pyupgrade
     "UP", # pyupgrade
     "RUF", # ruff
     "RUF", # ruff
     "PL", # pylint
     "PL", # pylint
+    "Q", # flake8-quotes
 ]
 ]
 fixable = [
 fixable = [
     "I",  # isort
     "I",  # isort
     "RUF022", # `__all__` is not sorted
     "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 = [
 ignore = [
     "E501", # line too long
     "E501", # line too long