Skip to content

Commit ba9668b

Browse files
committed
Move two rules to new extra subpackage, remove IG code rule
ghstack-source-id: d503432 Pull Request resolved: #362
1 parent a2f26d9 commit ba9668b

File tree

7 files changed

+114
-276
lines changed

7 files changed

+114
-276
lines changed

docs/guide/builtins.rst

Lines changed: 104 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Built-in Rules
99
--------------
1010

1111
- :mod:`fixit.rules`
12+
- :mod:`fixit.rules.extra`
1213
- :mod:`fixit.upgrade`
1314

1415

@@ -22,7 +23,6 @@ Built-in Rules
2223
- :class:`ComparePrimitivesByEqual`
2324
- :class:`CompareSingletonPrimitivesByIs`
2425
- :class:`DeprecatedUnittestAsserts`
25-
- :class:`ExplicitFrozenDataclass`
2626
- :class:`NoAssertTrueForComparisons`
2727
- :class:`NoInheritFromObject`
2828
- :class:`NoNamedTuple`
@@ -39,10 +39,8 @@ Built-in Rules
3939
- :class:`UseAssertIn`
4040
- :class:`UseAssertIsNotNone`
4141
- :class:`UseAsyncSleepInAsyncDef`
42-
- :class:`UseClassNameAsCode`
4342
- :class:`UseClsInClassmethod`
4443
- :class:`UseFstring`
45-
- :class:`UseLintFixmeComment`
4644
- :class:`UseTypesFromTyping`
4745

4846
.. class:: AvoidOrInExcept
@@ -282,62 +280,6 @@ Built-in Rules
282280
# suggested fix
283281
self.assertNotEqual(a, b)
284282
285-
.. class:: ExplicitFrozenDataclass
286-
287-
Encourages the use of frozen dataclass objects by telling users to specify the
288-
kwarg.
289-
290-
Without this lint rule, most users of dataclass won't know to use the kwarg, and
291-
may unintentionally end up with mutable objects.
292-
293-
.. attribute:: MESSAGE
294-
295-
When using dataclasses, explicitly specify a frozen keyword argument. Example: `@dataclass(frozen=True)` or `@dataclass(frozen=False)`. Docs: https://docs.python.org/3/library/dataclasses.html
296-
297-
.. attribute:: AUTOFIX
298-
:type: Yes
299-
300-
301-
.. attribute:: VALID
302-
303-
.. code:: python
304-
305-
@some_other_decorator
306-
class Cls: pass
307-
.. code:: python
308-
309-
from dataclasses import dataclass
310-
@dataclass(frozen=False)
311-
class Cls: pass
312-
313-
.. attribute:: INVALID
314-
315-
.. code:: python
316-
317-
from dataclasses import dataclass
318-
@some_unrelated_decorator
319-
@dataclass # not called as a function
320-
@another_unrelated_decorator
321-
class Cls: pass
322-
323-
# suggested fix
324-
from dataclasses import dataclass
325-
@some_unrelated_decorator
326-
@dataclass(frozen=True) # not called as a function
327-
@another_unrelated_decorator
328-
class Cls: pass
329-
330-
.. code:: python
331-
332-
from dataclasses import dataclass
333-
@dataclass() # called as a function, no kwargs
334-
class Cls: pass
335-
336-
# suggested fix
337-
from dataclasses import dataclass
338-
@dataclass(frozen=True) # called as a function, no kwargs
339-
class Cls: pass
340-
341283
.. class:: NoAssertTrueForComparisons
342284

343285
Finds incorrect use of ``assertTrue`` when the intention is to compare two values.
@@ -1023,58 +965,6 @@ Built-in Rules
1023965
from time import sleep
1024966
async def func():
1025967
sleep(1)
1026-
.. class:: UseClassNameAsCode
1027-
1028-
Meta lint rule which checks that codes of lint rules are migrated to new format in lint rule class definitions.
1029-
1030-
.. attribute:: MESSAGE
1031-
1032-
`IG`-series codes are deprecated. Use class name as code instead.
1033-
1034-
.. attribute:: AUTOFIX
1035-
:type: Yes
1036-
1037-
1038-
.. attribute:: VALID
1039-
1040-
.. code:: python
1041-
1042-
MESSAGE = "This is a message"
1043-
.. code:: python
1044-
1045-
from fixit.common.base import CstLintRule
1046-
class FakeRule(CstLintRule):
1047-
MESSAGE = "This is a message"
1048-
1049-
.. attribute:: INVALID
1050-
1051-
.. code:: python
1052-
1053-
MESSAGE = "IG90000 Message"
1054-
1055-
# suggested fix
1056-
MESSAGE = "Message"
1057-
1058-
.. code:: python
1059-
1060-
from fixit.common.base import CstLintRule
1061-
class FakeRule(CstLintRule):
1062-
INVALID = [
1063-
Invalid(
1064-
code="",
1065-
kind="IG000"
1066-
)
1067-
]
1068-
1069-
# suggested fix
1070-
from fixit.common.base import CstLintRule
1071-
class FakeRule(CstLintRule):
1072-
INVALID = [
1073-
Invalid(
1074-
code="",
1075-
)
1076-
]
1077-
1078968
.. class:: UseClsInClassmethod
1079969

1080970
Enforces using ``cls`` as the first argument in a ``@classmethod``.
@@ -1184,44 +1074,6 @@ Built-in Rules
11841074
# suggested fix
11851075
f"{'hi'}"
11861076
1187-
.. class:: UseLintFixmeComment
1188-
1189-
To silence a lint warning, use ``lint-fixme`` (when plans to fix the issue later) or ``lint-ignore``
1190-
(when the lint warning is not valid) comments.
1191-
The comment requires to be in a standalone comment line and follows the format ``lint-fixme: RULE_NAMES EXTRA_COMMENTS``.
1192-
It suppresses the lint warning with the RULE_NAMES in the next line.
1193-
RULE_NAMES can be one or more lint rule names separated by comma.
1194-
``noqa`` is deprecated and not supported because explicitly providing lint rule names to be suppressed
1195-
in lint-fixme comment is preferred over implicit noqa comments. Implicit noqa suppression comments
1196-
sometimes accidentally silence warnings unexpectedly.
1197-
1198-
.. attribute:: MESSAGE
1199-
1200-
noqa is deprecated. Use `lint-fixme` or `lint-ignore` instead.
1201-
1202-
1203-
.. attribute:: VALID
1204-
1205-
.. code:: python
1206-
1207-
# lint-fixme: UseFstringRule
1208-
"%s" % "hi"
1209-
.. code:: python
1210-
1211-
# lint-ignore: UsePlusForStringConcatRule
1212-
'ab' 'cd'
1213-
1214-
.. attribute:: INVALID
1215-
1216-
.. code:: python
1217-
1218-
fn() # noqa
1219-
.. code:: python
1220-
1221-
(
1222-
1,
1223-
2, # noqa
1224-
)
12251077
.. class:: UseTypesFromTyping
12261078

12271079
Enforces the use of types from the ``typing`` module in type annotations in place
@@ -1263,6 +1115,109 @@ Built-in Rules
12631115
def function(list: list[str]) -> None:
12641116
pass
12651117
1118+
``fixit.rules.extra``
1119+
^^^^^^^^^^^^^^^^^^^^^
1120+
1121+
.. automodule:: fixit.rules.extra
1122+
1123+
- :class:`ExplicitFrozenDataclass`
1124+
- :class:`UseLintFixmeComment`
1125+
1126+
.. class:: ExplicitFrozenDataclass
1127+
1128+
Encourages the use of frozen dataclass objects by telling users to specify the
1129+
kwarg.
1130+
1131+
Without this lint rule, most users of dataclass won't know to use the kwarg, and
1132+
may unintentionally end up with mutable objects.
1133+
1134+
.. attribute:: MESSAGE
1135+
1136+
When using dataclasses, explicitly specify a frozen keyword argument. Example: `@dataclass(frozen=True)` or `@dataclass(frozen=False)`. Docs: https://docs.python.org/3/library/dataclasses.html
1137+
1138+
.. attribute:: AUTOFIX
1139+
:type: Yes
1140+
1141+
1142+
.. attribute:: VALID
1143+
1144+
.. code:: python
1145+
1146+
@some_other_decorator
1147+
class Cls: pass
1148+
.. code:: python
1149+
1150+
from dataclasses import dataclass
1151+
@dataclass(frozen=False)
1152+
class Cls: pass
1153+
1154+
.. attribute:: INVALID
1155+
1156+
.. code:: python
1157+
1158+
from dataclasses import dataclass
1159+
@some_unrelated_decorator
1160+
@dataclass # not called as a function
1161+
@another_unrelated_decorator
1162+
class Cls: pass
1163+
1164+
# suggested fix
1165+
from dataclasses import dataclass
1166+
@some_unrelated_decorator
1167+
@dataclass(frozen=True) # not called as a function
1168+
@another_unrelated_decorator
1169+
class Cls: pass
1170+
1171+
.. code:: python
1172+
1173+
from dataclasses import dataclass
1174+
@dataclass() # called as a function, no kwargs
1175+
class Cls: pass
1176+
1177+
# suggested fix
1178+
from dataclasses import dataclass
1179+
@dataclass(frozen=True) # called as a function, no kwargs
1180+
class Cls: pass
1181+
1182+
.. class:: UseLintFixmeComment
1183+
1184+
To silence a lint warning, use ``lint-fixme`` (when plans to fix the issue later) or ``lint-ignore``
1185+
(when the lint warning is not valid) comments.
1186+
The comment requires to be in a standalone comment line and follows the format ``lint-fixme: RULE_NAMES EXTRA_COMMENTS``.
1187+
It suppresses the lint warning with the RULE_NAMES in the next line.
1188+
RULE_NAMES can be one or more lint rule names separated by comma.
1189+
``noqa`` is deprecated and not supported because explicitly providing lint rule names to be suppressed
1190+
in lint-fixme comment is preferred over implicit noqa comments. Implicit noqa suppression comments
1191+
sometimes accidentally silence warnings unexpectedly.
1192+
1193+
.. attribute:: MESSAGE
1194+
1195+
noqa is deprecated. Use `lint-fixme` or `lint-ignore` instead.
1196+
1197+
1198+
.. attribute:: VALID
1199+
1200+
.. code:: python
1201+
1202+
# lint-fixme: UseFstringRule
1203+
"%s" % "hi"
1204+
.. code:: python
1205+
1206+
# lint-ignore: UsePlusForStringConcatRule
1207+
'ab' 'cd'
1208+
1209+
.. attribute:: INVALID
1210+
1211+
.. code:: python
1212+
1213+
fn() # noqa
1214+
.. code:: python
1215+
1216+
(
1217+
1,
1218+
2, # noqa
1219+
)
1220+
12661221
``fixit.upgrade``
12671222
^^^^^^^^^^^^^^^^^
12681223

pyproject.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ build = [
112112

113113
[tool.fixit]
114114
enable = ["fixit.rules"]
115-
disable = [
116-
# We don't want everything to be frozen or have to set frozen=False
117-
"fixit.rules:ExplicitFrozenDataclass",
118-
# We need noqa for compat with flake8 until we jettison flake8
119-
"fixit.rules:UseLintFixmeComment",
120-
]
121115
python-version = "3.10"
122116
formatter = "ufmt"
123117

scripts/document_rules.py

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

1212
from jinja2 import Template
1313

14-
RULES = ["fixit.rules", "fixit.upgrade"]
14+
RULES = ["fixit.rules", "fixit.rules.extra", "fixit.upgrade"]
1515

1616
RULES_DOC = Path(__file__).parent.parent / "docs" / "guide" / "builtins.rst"
1717

src/fixit/rules/extra/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
"""
7+
These are highly opinionated rules, and are not enabled by default.
8+
They can be enabled in your project's :attr:`enable` configuration option.
9+
"""

0 commit comments

Comments
 (0)