Skip to content

Commit

Permalink
Respond to some Micha comments from Discord
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Jan 17, 2024
1 parent dfeb341 commit 23cfdbc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/rules/ruff/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod pairwise_over_zipped;
mod parenthesize_logical_operators;
mod sort_dunder_all;
mod sort_dunder_slots;
mod sorting_helpers;
mod sequence_sorting;
mod static_key_dict_comprehension;
mod unnecessary_iterable_allocation_for_first_element;
mod unnecessary_key_check;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Miscellaneous helpers for sorting constant lists of string literals.
/// Utilities for sorting constant lists of string literals.
///
/// Examples where these are useful:
/// - Sorting `__all__` in the global scope,
Expand Down Expand Up @@ -26,7 +26,7 @@ use itertools::{izip, Itertools};
/// We keep the original AST node around for the
/// Tuple variant so that this can be queried later.
#[derive(Debug)]
pub(crate) enum SequenceKind<'a> {
pub(super) enum SequenceKind<'a> {
List,
Set,
Tuple(&'a ast::ExprTuple),
Expand All @@ -47,15 +47,15 @@ impl SequenceKind<'_> {
}
}

pub(crate) fn opening_token_for_multiline_definition(&self) -> Tok {
pub(super) fn opening_token_for_multiline_definition(&self) -> Tok {
match self {
Self::List => Tok::Lsqb,
Self::Set => Tok::Lbrace,
Self::Tuple(_) => Tok::Lpar,
}
}

pub(crate) fn closing_token_for_multiline_definition(&self) -> Tok {
pub(super) fn closing_token_for_multiline_definition(&self) -> Tok {
match self {
Self::List => Tok::Rsqb,
Self::Set => Tok::Rbrace,
Expand All @@ -68,7 +68,7 @@ impl SequenceKind<'_> {
/// [display literals](https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries)
/// Python provides for builtin containers.
#[derive(Debug, is_macro::Is)]
pub(crate) enum DisplayKind<'a> {
pub(super) enum DisplayKind<'a> {
Sequence(SequenceKind<'a>),
Dict { values: &'a Vec<ast::Expr> },
}
Expand All @@ -77,7 +77,7 @@ pub(crate) enum DisplayKind<'a> {
/// definition of `__all__` or `__slots__` (etc.),
/// that can be inserted into the
/// source code as a `range_replacement` autofix.
pub(crate) fn sort_single_line_elements_sequence<F>(
pub(super) fn sort_single_line_elements_sequence<F>(
kind: &SequenceKind,
elts: &[&ast::Expr],
elements: &[&str],
Expand Down Expand Up @@ -113,7 +113,7 @@ where
/// definition of `__all__` or `__slots__` (etc.),
/// that can be inserted into the
/// source code as a `range_replacement` autofix.
pub(crate) fn sort_single_line_elements_dict<F>(
pub(super) fn sort_single_line_elements_dict<F>(
key_elts: &[&ast::Expr],
elements: &[&str],
value_elts: &[ast::Expr],
Expand Down Expand Up @@ -157,15 +157,15 @@ where
/// 4. The display contains one or more items that are not string
/// literals.
#[derive(Debug, is_macro::Is)]
pub(crate) enum SortClassification<'a> {
pub(super) enum SortClassification<'a> {
Sorted,
UnsortedButUnfixable,
UnsortedAndMaybeFixable { items: Vec<&'a str> },
NotAListOfStringLiterals,
}

impl<'a> SortClassification<'a> {
pub(crate) fn from_elements<F>(elements: &'a [&ast::Expr], mut cmp_fn: F) -> Self
pub(super) fn from_elements<F>(elements: &'a [&ast::Expr], mut cmp_fn: F) -> Self
where
F: FnMut(&str, &str) -> Ordering,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ruff_source_file::Locator;
use ruff_text_size::{Ranged, TextRange, TextSize};

use crate::checkers::ast::Checker;
use crate::rules::ruff::rules::sorting_helpers::{
use crate::rules::ruff::rules::sequence_sorting::{
sort_single_line_elements_sequence, SequenceKind, SortClassification,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ruff_source_file::Locator;
use ruff_text_size::TextRange;

use crate::checkers::ast::Checker;
use crate::rules::ruff::rules::sorting_helpers::{
use crate::rules::ruff::rules::sequence_sorting::{
sort_single_line_elements_dict, sort_single_line_elements_sequence, DisplayKind, SequenceKind,
SortClassification,
};
Expand Down

0 comments on commit 23cfdbc

Please sign in to comment.