Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs/guide/builtins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1459,10 +1459,19 @@ Built-in Rules
Modify lint rule test cases from Fixit 1 to remove deprecated keyword arguments
and convert the line and column values into a CodeRange.

.. important::
The use of ``fixit.ValidTestCase`` and ``fixit.InvalidTestCase`` have been
deprecated. This rule provides upgrades only to the temporary aliases.

Use ``fixit upgrade`` to replace the aliases with :class:`fixit.Valid` and
:class:`fixit.Invalid`.

See the :ref:`Version 2 API Changes <v2-api-changes>` for more details.

.. attribute:: MESSAGE
:no-index:

Fix deprecated Valid/Invalid keyword arguments
Fix deprecated ValidTestCase/InvalidTestCase keyword arguments

.. attribute:: AUTOFIX
:no-index:
Expand All @@ -1487,6 +1496,7 @@ Built-in Rules
.. code:: python

from fixit import InvalidTestCase

InvalidTestCase(
"print('hello')",
line=3,
Expand All @@ -1498,6 +1508,7 @@ Built-in Rules

# suggested fix
from fixit import InvalidTestCase

InvalidTestCase(
"print('hello')",
range = CodeRange(start=CodePosition(3, 10), end=CodePosition(1 + 3, 0)))
Expand Down
8 changes: 4 additions & 4 deletions docs/guide/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,25 @@ Custom Rules
Fixit makes it easy to write and enable new lint rules, directly in your
existing codebase alongside the code they will be linting.

Lint rules in Fixit are built on top of `LibCST <https://libcst.rtfd.io>`_
Lint rules in Fixit are built on top of `LibCST <https://libcst.rtfd.io>`_
using a :class:`~fixit.LintRule` to combine visitors and tests together
in a single unit. A (very) simple rule looks like this:

.. code:: python

# teambread/rules/hollywood.py

from fixit import LintRule, InvalidTestCase, ValidTestCase
from fixit import LintRule, Invalid, Valid
import libcst

class HollywoodNameRule(LintRule):
# clean code samples
VALID = [
ValidTestCase('name = "Susan"'),
Valid('name = "Susan"'),
]
# code that triggers this rule
INVALID = [
InvalidTestCase('name = "Paul"'),
Invalid('name = "Paul"'),
]

def visit_SimpleString(self, node: libcst.SimpleString) -> None:
Expand Down
2 changes: 2 additions & 0 deletions docs/upgrade.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ in a future release:

All renames should be automatically upgraded with the ``fixit upgrade`` command.

.. _v2-api-changes:

Changes
%%%%%%%

Expand Down
2 changes: 1 addition & 1 deletion src/fixit/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def add_lint_rule_tests_to_module(
If argument is omitted, will default to the `LintRuleTestCase` class from fixit.common.testing.

custom_test_method_name: A member method of the class passed into `test_case_type` parameter that contains the logic around asserting success or failure of
LintRule's `ValidTestCase` and `InvalidTestCase` test cases. The method will be dynamically renamed to `test_<VALID/INVALID>_<test case index>` for discovery
LintRule's `Valid` and `Invalid` test cases. The method will be dynamically renamed to `test_<VALID/INVALID>_<test case index>` for discovery
by unittest. If argument is omitted, `add_lint_rule_tests_to_module` will look for a test method named `_test_method` member of `test_case_type`.

fixture_dir: The directory in which fixture files for the passed rules live. Necessary only if any lint rules require fixture data for testing.
Expand Down
13 changes: 12 additions & 1 deletion src/fixit/upgrade/deprecated_testcase_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ class FixitDeprecatedTestCaseKeywords(LintRule):
"""
Modify lint rule test cases from Fixit 1 to remove deprecated keyword arguments
and convert the line and column values into a CodeRange.

.. important::
The use of ``fixit.ValidTestCase`` and ``fixit.InvalidTestCase`` have been
deprecated. This rule provides upgrades only to the temporary aliases.

Use ``fixit upgrade`` to replace the aliases with :class:`fixit.Valid` and
:class:`fixit.Invalid`.

See the :ref:`Version 2 API Changes <v2-api-changes>` for more details.
"""

MESSAGE = "Fix deprecated Valid/Invalid keyword arguments"
MESSAGE = "Fix deprecated ValidTestCase/InvalidTestCase keyword arguments"
METADATA_DEPENDENCIES = (QualifiedNameProvider,)

VALID = [
Expand All @@ -45,6 +54,7 @@ class FixitDeprecatedTestCaseKeywords(LintRule):
Invalid(
"""
from fixit import InvalidTestCase

InvalidTestCase(
"print('hello')",
line=3,
Expand All @@ -56,6 +66,7 @@ class FixitDeprecatedTestCaseKeywords(LintRule):
""",
expected_replacement="""
from fixit import InvalidTestCase

InvalidTestCase(
"print('hello')",
range = CodeRange(start=CodePosition(3, 10), end=CodePosition(1 + 3, 0)))
Expand Down