Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch linting from ufmt+usort+flake8+black to Ruff #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
178 changes: 0 additions & 178 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ disclosure of security bugs. In those cases, please go through the process
outlined on that page and do not file a public issue.

## Coding Style
We use flake8 and ufmt to enforce coding style.
We use Ruff to enforce coding style.

## License
By contributing to LibCST, you agree that your contributions will be licensed
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ We have multiple linters, including copyright checks and

hatch run lint

We use `ufmt <https://ufmt.omnilib.dev/en/stable/>`_ to format code. To format
We use `ruff <https://beta.ruff.rs/>`_ to format code. To format
changes to be conformant, run the following in the root:

.. code-block:: shell
Expand Down
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True


# -- autodoc customization
def strip_class_signature(app, what, name, obj, options, signature, return_annotation):
if what == "class":
Expand Down
2 changes: 1 addition & 1 deletion libcst/_nodes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def deep_clone(self: _CSTNodeSelfT) -> _CSTNodeSelfT:
True
"""
cloned_fields: Dict[str, object] = {}
for field in fields(self):
for field in fields(self): # noqa: F402
key = field.name
if key[0] == "_":
continue
Expand Down
3 changes: 2 additions & 1 deletion libcst/_nodes/tests/test_with.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,5 +331,6 @@ def test_adding_parens(self) -> None:
)
module = cst.Module([])
self.assertEqual(
module.code_for_node(node), ("with ( foo(),\n" "bar(), ): pass\n") # noqa
module.code_for_node(node),
("with ( foo(),\n" "bar(), ): pass\n"), # noqa
)
2 changes: 1 addition & 1 deletion libcst/_parser/conversions/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def convert_argslist( # noqa: C901
kwonly_params: List[Param] = []
star_kwarg: Optional[Param] = None

def add_param(
def add_param( # noqa: C901
current_param: Optional[List[Param]], param: Union[Param, ParamStar]
) -> Optional[List[Param]]:
nonlocal star_arg
Expand Down
5 changes: 3 additions & 2 deletions libcst/_typed_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from libcst._removal_sentinel import RemovalSentinel
from libcst._typed_visitor_base import mark_no_op


if TYPE_CHECKING:
from libcst._nodes.expression import ( # noqa: F401
Annotation,
Expand Down Expand Up @@ -75,7 +74,9 @@
UnaryOperation,
Yield,
)
from libcst._nodes.module import Module # noqa: F401
from libcst._nodes.module import ( # noqa: F401
Module,
)
from libcst._nodes.op import ( # noqa: F401
Add,
AddAssign,
Expand Down
1 change: 0 additions & 1 deletion libcst/_typed_visitor_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from typing import Any, Callable, cast, TypeVar


# pyre-fixme[24]: Generic type `Callable` expects 2 type parameters.
F = TypeVar("F", bound=Callable)

Expand Down
2 changes: 1 addition & 1 deletion libcst/codegen/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

def format_file(fname: str) -> None:
subprocess.check_call(
["ufmt", "format", fname],
["ruff", "format", fname],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
Expand Down
1 change: 0 additions & 1 deletion libcst/codemod/commands/add_trailing_commas.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import libcst as cst
from libcst.codemod import CodemodContext, VisitorBasedCodemodCommand


presets_per_formatter: Dict[str, Dict[str, int]] = {
"black": {
"parameter_count": 1,
Expand Down
4 changes: 1 addition & 3 deletions libcst/codemod/visitors/_apply_type_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import libcst as cst
import libcst.matchers as m

from libcst.codemod._context import CodemodContext
from libcst.codemod._visitor import ContextAwareTransformer
from libcst.codemod.visitors._add_imports import AddImportsVisitor
Expand All @@ -19,7 +18,6 @@
from libcst.helpers import get_full_name_for_node
from libcst.metadata import PositionProvider, QualifiedNameProvider


NameOrAttribute = Union[cst.Name, cst.Attribute]
NAME_OR_ATTRIBUTE = (cst.Name, cst.Attribute)
# Union type for *args and **args
Expand Down Expand Up @@ -881,7 +879,7 @@ def _quote_future_annotations(self, annotation: cst.Annotation) -> cst.Annotatio
if (
isinstance(node, cst.Name)
and (node.value in self.global_names)
and not (node.value in self.visited_classes)
and node.value not in self.visited_classes
):
return annotation.with_changes(
annotation=cst.SimpleString(value=f'"{node.value}"')
Expand Down
1 change: 0 additions & 1 deletion libcst/matchers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import libcst as cst
from libcst.matchers._decorators import call_if_inside, call_if_not_inside, leave, visit

from libcst.matchers._matcher_base import (
AbstractBaseMatcherNodeMeta,
AllOf,
Expand Down
2 changes: 1 addition & 1 deletion libcst/matchers/_matcher_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ def _matches_zero_nodes(
MatchIfTrue[libcst.CSTNode],
_BaseMetadataMatcher,
DoNotCareSentinel,
]
],
) -> bool:
if isinstance(matcher, AtLeastN) and matcher.n == 0:
return True
Expand Down
2 changes: 0 additions & 2 deletions libcst/matchers/_return_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
Yield,
)
from libcst._nodes.module import Module

from libcst._nodes.op import (
Add,
AddAssign,
Expand Down Expand Up @@ -202,7 +201,6 @@
)
from libcst._removal_sentinel import RemovalSentinel


TYPED_FUNCTION_RETURN_MAPPING: TypingDict[Type[CSTNode], object] = {
Add: BaseBinaryOp,
AddAssign: BaseAugOp,
Expand Down
1 change: 0 additions & 1 deletion libcst/metadata/accessor_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import dataclasses

import libcst as cst

from libcst.metadata.base_provider import VisitorMetadataProvider


Expand Down
1 change: 0 additions & 1 deletion libcst/metadata/tests/test_accessor_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# LICENSE file in the root directory of this source tree.

import dataclasses

from textwrap import dedent

import libcst as cst
Expand Down
1 change: 0 additions & 1 deletion libcst/tests/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from libcst._parser.entrypoints import is_native


if __name__ == "__main__":
parser_type = "native" if is_native() else "pure"
print(f"running tests with {parser_type!r} parser")
Expand Down
1 change: 0 additions & 1 deletion libcst/tests/test_add_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import ClassVar

from libcst._add_slots import add_slots

from libcst.testing.utils import UnitTest


Expand Down
Loading