Skip to content

Commit a3dfcc9

Browse files
committed
Adjusted Ruff settings and re-linted code
1 parent 6727a40 commit a3dfcc9

14 files changed

+40
-13
lines changed

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import re
99
import shutil
1010

11+
1112
SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
1213

1314

pyproject.toml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,51 +39,54 @@ select = ["ALL"]
3939
ignore = [
4040
# Reason for ignoring:
4141
# DI: Disagree - I disagree with this rule in nearly all cases.
42-
# AL: Alternative - The rule is incompatible with an alternative rule.
42+
# HI: Hint - The rule would be useful at hint-severity, if ruff supported that.
4343
# TB: Too broad - The rule is sometimes useful, but gives too many false positives.
44+
# AL: Alternative - The rule is incompatible with an alternative rule.
4445
# PA: Public API - The fix may require changing a public API, making this rule unusable in many cases.
45-
# HI: Hint - The rule would be useful at hint-severity, if ruff supported that.
46+
# NA: Not applicable - The rule is not applicable in this particular situation / project type / directory.
4647
# PR: Project-specific - There is a project-specific reason to not use this rule.
4748

4849
# Mainly DI
50+
"D203", # incorrect-blank-line-before-class - DI, AL - Disabled in favor of D211.
4951
"RUF010", # explicit-f-string-type-conversion - DI - Explicit conversion is more readable. See also https://peps.python.org/pep-0498/#s-r-and-a-are-redundant
5052

51-
# Mainly AL
52-
"D203", # incorrect-blank-line-before-class - AL - Disabled in favor of D211.
53-
"D213", # multi-line-summary-second-line - AL - Disabled in favor of D212.
53+
# Mainly HI
54+
"FIX", # flake8-fixme - HI
55+
"TD", # flake8-todos - HI
5456

5557
# Mainly TB
5658
"ANN401", # any-type - TB - Any can be useful for very generic interfaces or as an acceptable temporary solution.
5759
"B007", # unused-loop-control-variable - TB - The loop variable may be used after the loop; it might count something. Redundant with F841.
5860
"C90", # mccabe - TB - May be hard to fix, and real issues can be spotted manually.
59-
"D1", # undocumented-* - TB - Documenting everything is not necessary in scripts.
6061
"D105", # undocumented-magic-method - TB - Many magic methods are self-explanatory.
6162
"D202", # blank-line-after-function - TB - Adding a blank line can improve readability when the docstring is short.
6263
"D204", # incorrect-blank-line-after-class - TB - The blank line can be unnecessary for very short classes.
6364
"D205", # missing-blank-line-after-summary - TB - A single line is sometimes too limiting, and most tools can handle multiple lines.
6465
"D209", # new-line-after-last-paragraph - TB - It's a bit nasty, but breaking this rule can help compactify short docstrings.
6566
"D301", # escape-sequence-in-docstring - TB - It's a bit nasty, but breaking this rule with "\n" can help compactify short docstrings.
66-
"D400", # missing-trailing-period - TB - Other punctuation is also acceptable. We use D415 instead.
67+
"D400", # missing-trailing-period - TB, AL - Other punctuation is also acceptable. Disabled in favor of D415.
6768
"D401", # non-imperative-mood - TB - This is very controversial. I personally prefer the descriptive mood in most cases.
6869
"D404", # docstring-starts-with-this - TB - There are valid usages of "this", such as when referring to a method's object.
6970
"E501", # line-too-long - TB - Lines occasionally need to be longer, such as when a comment contains a long link.
7071
"E701", # multiple-statements - TB - Single-line if-statements can be more readable in certain scenarios.
7172
"E741", # ambiguous-variable-name - TB - "l" is often fine, and the others may occasionally be fine as well.
7273
"ERA001", # commented-out-code - TB - Commenting out code is sometimes useful, and this also triggers on intentional code examples.
73-
"FBT001", # boolean-type-hint-positional-argument - TB, PA - Mostly redundant with FBT003.
74-
"FBT002", # boolean-default-value-positional-argument - TB, PA - Mostly redundant with FBT003.
74+
"FBT001", # boolean-type-hint-positional-argument - TB, PA, and mostly redundant with FBT003.
75+
"FBT002", # boolean-default-value-positional-argument - TB, PA, and mostly redundant with FBT003.
7576
"INP001", # implicit-namespace-package - TB - The namespace package may be intentional. Also triggers on Sphinx' conf.py.
7677
"ISC003", # explicit-string-concatenation - TB - In cases where some lines are literals and some expressions, it is clearer to use + everywhere.
7778
"PERF203", # try-except-in-loop - TB - The try-except can often not be taken out of the loop.
7879
"PLR091", # too-many-* - TB, PA - Real issues can be spotted manually.
7980
"PLR2004", # magic-value-comparison - TB - Although this rule is often right, there are also many cases where a constant is overkill.
8081
"PLW2901", # redefined-loop-name - TB - Reuse of the loop variable can help keep names simple. This rule does have a strong case, though.
8182
"PTH", # flake8-use-pathlib - TB, HI - Old-style path manipulation is acceptable, and occasionally even more readable.
83+
"S101", # assert - TB - Assertions can be useful, such as for telling type checkers that a value cannot be None.
8284
"S311", # suspicious-non-cryptographic-random-usage - TB - Not all random usages are cryptographic.
85+
"S603", # subprocess-without-shell-equals-true - TB - (Rule name is misleading.) This triggers so easily that it is practically unusable.
86+
"SIM108", # if-else-block-instead-of-if-exp - TB - A regular if-statement is sometimes more readable or consistent.
8387

84-
# Mainly HI
85-
"FIX", # flake8-fixme - HI
86-
"TD", # flake8-todos - HI
88+
# Mainly NA
89+
"D213", # multi-line-summary-second-line - NA, AL - GDPC uses D212 instead.
8790

8891
# Mainly PR
8992
"N802", # invalid-function-name - PR, PA - For historical reasons, GDPC uses camelCase.
@@ -96,13 +99,24 @@ ignore = [
9699

97100
[tool.ruff.lint.per-file-ignores]
98101
"**.pyi" = [
99-
# These rules are inappropriate for stub files.
100102
"A", # flake8-builtins - Stub files must use the same names as the original code.
101103
"N", # pep8-naming - Stub files must use the same names as the original code.
102104
]
105+
"!src/gdpc/**.py" = [
106+
"D1", # undocumented-* - NA, TB - We only enforce documentation in the main library.
107+
"T20", # flake-8-print - NA, TB - Prints are fine in many cases, but not in the main library.
108+
]
103109

104110
[tool.ruff.lint.flake8-builtins]
105111
ignorelist = [
106112
"id", # Very generic name that is often useful.
107113
"copyright", # The builtin is very unimportant, and this gets used by Sphinx' conf.py.
108114
]
115+
116+
[tool.ruff.lint.isort]
117+
# When set to the default value `-1`, Ruff determines the number of lines automatically, and its
118+
# algorithm seems quite strange. Most notably, it places only one line if the imports are
119+
# followed by a constant, which is a fairly common occurance. We override this value with 2 to
120+
# avoid this issue. An unfortunate side effect is that TYPE_CHECKING blocks also become separated
121+
# by 2 lines, but we consider that the lesser evil.
122+
lines-after-imports = 2

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from setuptools import setup
44

5+
56
SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
67
METADATA_FILE_PATH = os.path.join(SCRIPT_DIR, "src/gdpc/__init__.py")
78

src/gdpc/block.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .block_state_tools import transformAxis, transformFacing, transformHalf, transformRotation
1414
from .nbt_tools import nbtToSnbt
1515

16+
1617
if TYPE_CHECKING:
1718
from .vector_tools import Vec3bLike
1819

src/gdpc/block_state_tools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from pyglm.glm import bvec3, ivec3
1313

14+
1415
if TYPE_CHECKING:
1516
from .vector_tools import Vec3bLike, Vec3iLike
1617

src/gdpc/editor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from .vector_tools import Box, Rect, Vec3iLike, dropY
2626
from .world_slice import WorldSlice
2727

28+
2829
logger = logging.getLogger(__name__)
2930

3031

src/gdpc/editor_tools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .minecraft_tools import getObtrusiveness, lecternBlock, positionToInventoryIndex, signBlock
1515
from .vector_tools import Box, Vec2iLike, Vec3iLike, neighbors3D
1616

17+
1718
if TYPE_CHECKING:
1819
from .editor import Editor
1920

src/gdpc/geometry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
lineSequence3D,
2525
)
2626

27+
2728
if TYPE_CHECKING:
2829
from .editor import Editor
2930

src/gdpc/interface.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from .utils import isIterable, withRetries
3030
from .vector_tools import Box, Vec2iLike, Vec3iLike
3131

32+
3233
DEFAULT_HOST = "http://localhost:9000"
3334
"""Default host"""
3435

src/gdpc/minecraft_tools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .block import Block
1212
from .vector_tools import Rect, Vec2iLike
1313

14+
1415
# ==================================================================================================
1516
# Constants
1617
# ==================================================================================================

0 commit comments

Comments
 (0)