Skip to content

Commit

Permalink
Merge branch 'main' into line-suffix-client
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer committed Aug 27, 2023
2 parents a4d21fd + fc89976 commit 0c0a43c
Show file tree
Hide file tree
Showing 478 changed files with 1,056 additions and 773 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Test cases for difficult renames."""


def rename_global():
try:
global pandas
import pandas
except ImportError:
return False
3 changes: 2 additions & 1 deletion crates/ruff/src/autofix/codemods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use anyhow::{bail, Result};
use libcst_native::{
Codegen, CodegenState, ImportNames, ParenthesizableWhitespace, SmallStatement, Statement,
};
use ruff_python_ast::{Ranged, Stmt};

use ruff_python_ast::Stmt;
use ruff_python_codegen::Stylist;
use ruff_source_file::Locator;
use ruff_text_size::Ranged;

use crate::cst::helpers::compose_module_path;
use crate::cst::matchers::match_statement;
Expand Down
8 changes: 3 additions & 5 deletions crates/ruff/src/autofix/edits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
use anyhow::{Context, Result};

use ruff_diagnostics::Edit;
use ruff_python_ast::{self as ast, Arguments, ExceptHandler, Expr, Keyword, Ranged, Stmt};
use ruff_python_ast::{self as ast, Arguments, ExceptHandler, Expr, Keyword, Stmt};
use ruff_python_codegen::Stylist;
use ruff_python_index::Indexer;

use ruff_python_trivia::{
has_leading_content, is_python_whitespace, PythonWhitespace, SimpleTokenKind, SimpleTokenizer,
};
use ruff_source_file::{Locator, NewlineWithTrailingNewline};
use ruff_text_size::{TextLen, TextSize};
use ruff_text_size::{Ranged, TextLen, TextSize};

use crate::autofix::codemods;

Expand Down Expand Up @@ -254,10 +253,9 @@ fn next_stmt_break(semicolon: TextSize, locator: &Locator) -> TextSize {
mod tests {
use anyhow::Result;

use ruff_python_ast::Ranged;
use ruff_python_parser::parse_suite;
use ruff_source_file::Locator;
use ruff_text_size::TextSize;
use ruff_text_size::{Ranged, TextSize};

use crate::autofix::edits::{next_stmt_break, trailing_semicolon};

Expand Down
4 changes: 1 addition & 3 deletions crates/ruff/src/autofix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ fn cmp_fix(rule1: Rule, rule2: Rule, fix1: &Fix, fix2: &Fix) -> std::cmp::Orderi
mod tests {
use ruff_text_size::TextSize;

use ruff_diagnostics::Diagnostic;
use ruff_diagnostics::Edit;
use ruff_diagnostics::Fix;
use ruff_diagnostics::{Diagnostic, Edit, Fix};
use ruff_source_file::Locator;

use crate::autofix::source_map::SourceMarker;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast/analyze/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ruff_diagnostics::{Diagnostic, Fix};
use ruff_python_ast::Ranged;
use ruff_text_size::Ranged;

use crate::checkers::ast::Checker;
use crate::codes::Rule;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast/analyze/deferred_scopes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ruff_diagnostics::Diagnostic;
use ruff_python_ast::Ranged;
use ruff_python_semantic::analyze::visibility;
use ruff_python_semantic::{Binding, BindingKind, ScopeKind};
use ruff_text_size::Ranged;

use crate::checkers::ast::Checker;
use crate::codes::Rule;
Expand Down
3 changes: 1 addition & 2 deletions crates/ruff/src/checkers/ast/analyze/definitions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use ruff_python_ast::str::raw_contents_range;
use ruff_python_ast::Ranged;
use ruff_text_size::TextRange;
use ruff_text_size::{Ranged, TextRange};

use ruff_python_semantic::{BindingKind, ContextualizedDefinition, Export};

Expand Down
3 changes: 2 additions & 1 deletion crates/ruff/src/checkers/ast/analyze/except_handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ruff_python_ast::{self as ast, ExceptHandler, Ranged};
use ruff_python_ast::{self as ast, ExceptHandler};
use ruff_text_size::Ranged;

use crate::checkers::ast::Checker;
use crate::registry::Rule;
Expand Down
3 changes: 2 additions & 1 deletion crates/ruff/src/checkers/ast/analyze/expression.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use ruff_python_ast::{self as ast, Arguments, Constant, Expr, ExprContext, Operator, Ranged};
use ruff_python_ast::{self as ast, Arguments, Constant, Expr, ExprContext, Operator};
use ruff_python_literal::cformat::{CFormatError, CFormatErrorType};

use ruff_diagnostics::Diagnostic;

use ruff_python_ast::types::Node;
use ruff_python_semantic::analyze::typing;
use ruff_python_semantic::ScopeKind;
use ruff_text_size::Ranged;

use crate::checkers::ast::Checker;
use crate::registry::Rule;
Expand Down
3 changes: 2 additions & 1 deletion crates/ruff/src/checkers/ast/analyze/parameter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ruff_python_ast::{Parameter, Ranged};
use ruff_python_ast::Parameter;
use ruff_text_size::Ranged;

use crate::checkers::ast::Checker;
use crate::codes::Rule;
Expand Down
5 changes: 2 additions & 3 deletions crates/ruff/src/checkers/ast/analyze/statement.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use ruff_python_ast::{self as ast, Expr, Ranged, Stmt};

use ruff_diagnostics::Diagnostic;
use ruff_python_ast::helpers;

use ruff_python_ast::types::Node;
use ruff_python_ast::{self as ast, Expr, Stmt};
use ruff_python_semantic::analyze::typing;
use ruff_python_semantic::ScopeKind;
use ruff_text_size::Ranged;

use crate::checkers::ast::Checker;
use crate::registry::Rule;
Expand Down
8 changes: 5 additions & 3 deletions crates/ruff/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ use itertools::Itertools;
use log::error;
use ruff_python_ast::{
self as ast, Arguments, Comprehension, Constant, ElifElseClause, ExceptHandler, Expr,
ExprContext, Keyword, MatchCase, Parameter, ParameterWithDefault, Parameters, Pattern, Ranged,
Stmt, Suite, UnaryOp,
ExprContext, Keyword, MatchCase, Parameter, ParameterWithDefault, Parameters, Pattern, Stmt,
Suite, UnaryOp,
};
use ruff_text_size::{TextRange, TextSize};
use ruff_text_size::{Ranged, TextRange, TextSize};

use ruff_diagnostics::{Diagnostic, IsolationLevel};
use ruff_python_ast::all::{extract_all_names, DunderAllFlags};
Expand Down Expand Up @@ -1895,6 +1895,8 @@ impl<'a> Checker<'a> {
for (name, range) in exports {
if let Some(binding_id) = self.semantic.global_scope().get(name) {
// Mark anything referenced in `__all__` as used.
// TODO(charlie): `range` here should be the range of the name in `__all__`, not
// the range of `__all__` itself.
self.semantic.add_global_reference(binding_id, range);
} else {
if self.semantic.global_scope().uses_star_imports() {
Expand Down
5 changes: 2 additions & 3 deletions crates/ruff/src/checkers/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
use std::borrow::Cow;
use std::path::Path;

use ruff_python_ast::{self as ast, PySourceType, Ranged, Stmt, Suite};

use ruff_diagnostics::Diagnostic;
use ruff_python_ast::helpers::to_module_path;
use ruff_python_ast::imports::{ImportMap, ModuleImport};
use ruff_python_ast::statement_visitor::StatementVisitor;
use ruff_python_ast::{self as ast, PySourceType, Stmt, Suite};
use ruff_python_codegen::Stylist;
use ruff_python_index::Indexer;

use ruff_source_file::Locator;
use ruff_text_size::Ranged;

use crate::directives::IsortDirectives;
use crate::registry::Rule;
Expand Down
3 changes: 1 addition & 2 deletions crates/ruff/src/checkers/logical_lines.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use ruff_diagnostics::{Diagnostic, DiagnosticKind};
use ruff_python_ast::Ranged;
use ruff_python_codegen::Stylist;
use ruff_python_parser::lexer::LexResult;
use ruff_python_parser::TokenKind;
use ruff_source_file::Locator;
use ruff_text_size::TextRange;
use ruff_text_size::{Ranged, TextRange};

use crate::registry::{AsRule, Rule};
use crate::rules::pycodestyle::rules::logical_lines::{
Expand Down
3 changes: 1 addition & 2 deletions crates/ruff/src/checkers/noqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use std::path::Path;

use itertools::Itertools;
use ruff_python_ast::Ranged;
use ruff_text_size::{TextLen, TextRange, TextSize};
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};

use ruff_diagnostics::{Diagnostic, Edit, Fix};
use ruff_source_file::Locator;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::str::FromStr;
use bitflags::bitflags;
use ruff_python_parser::lexer::LexResult;
use ruff_python_parser::Tok;
use ruff_text_size::{TextLen, TextRange, TextSize};
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};

use ruff_python_index::Indexer;
use ruff_source_file::Locator;
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/doc_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
use std::iter::FusedIterator;

use ruff_python_ast::{self as ast, Constant, Expr, Ranged, Stmt, Suite};
use ruff_python_ast::{self as ast, Constant, Expr, Stmt, Suite};
use ruff_python_parser::lexer::LexResult;
use ruff_python_parser::Tok;
use ruff_text_size::TextSize;
use ruff_text_size::{Ranged, TextSize};

use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor};
use ruff_source_file::{Locator, UniversalNewlineIterator};
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/docstrings/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::fmt::{Debug, Formatter};
use std::ops::Deref;

use ruff_python_ast::{Expr, Ranged};
use ruff_python_ast::Expr;
use ruff_python_semantic::Definition;
use ruff_text_size::TextRange;
use ruff_text_size::{Ranged, TextRange};

pub(crate) mod extraction;
pub(crate) mod google;
Expand Down
3 changes: 1 addition & 2 deletions crates/ruff/src/docstrings/sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::fmt::{Debug, Formatter};
use std::iter::FusedIterator;

use ruff_python_ast::docstrings::{leading_space, leading_words};
use ruff_python_ast::Ranged;
use ruff_text_size::{TextLen, TextRange, TextSize};
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
use strum_macros::EnumIter;

use ruff_source_file::{Line, UniversalNewlineIterator, UniversalNewlines};
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/importer/insertion.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Insert statements into Python code.
use std::ops::Add;

use ruff_python_ast::{PySourceType, Ranged, Stmt};
use ruff_python_ast::{PySourceType, Stmt};
use ruff_python_parser::{lexer, AsMode, Tok};
use ruff_text_size::TextSize;
use ruff_text_size::{Ranged, TextSize};

use ruff_diagnostics::Edit;
use ruff_python_ast::helpers::is_docstring_stmt;
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/importer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::error::Error;

use anyhow::Result;
use libcst_native::{ImportAlias, Name, NameOrAttribute};
use ruff_python_ast::{self as ast, PySourceType, Ranged, Stmt, Suite};
use ruff_text_size::TextSize;
use ruff_python_ast::{self as ast, PySourceType, Stmt, Suite};
use ruff_text_size::{Ranged, TextSize};

use ruff_diagnostics::Edit;
use ruff_python_ast::imports::{AnyImport, Import, ImportFrom};
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/message/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bitflags::bitflags;
use colored::Colorize;

use ruff_source_file::{OneIndexed, SourceLocation};
use ruff_text_size::{TextRange, TextSize};
use ruff_text_size::{Ranged, TextRange, TextSize};

use crate::fs::relativize_path;
use crate::jupyter::{Notebook, NotebookIndex};
Expand Down
3 changes: 1 addition & 2 deletions crates/ruff/src/noqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use std::path::Path;
use anyhow::Result;
use itertools::Itertools;
use log::warn;
use ruff_python_ast::Ranged;
use ruff_text_size::{TextLen, TextRange, TextSize};
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};

use ruff_diagnostics::Diagnostic;
use ruff_python_trivia::indentation_at_offset;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/renamer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use anyhow::{anyhow, Result};
use itertools::Itertools;

use ruff_diagnostics::Edit;
use ruff_python_ast::Ranged;
use ruff_python_semantic::{Binding, BindingKind, Scope, ScopeId, SemanticModel};
use ruff_text_size::Ranged;

pub(crate) struct Renamer;

Expand Down
21 changes: 8 additions & 13 deletions crates/ruff/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ impl Resolver {
}
}

pub trait ConfigProcessor: Copy + Send + Sync {
pub trait ConfigProcessor: Sync {
fn process_config(&self, config: &mut Configuration);
}

struct NoOpProcessor;
impl ConfigProcessor for &NoOpProcessor {

impl ConfigProcessor for NoOpProcessor {
fn process_config(&self, _config: &mut Configuration) {}
}

Expand All @@ -137,7 +138,7 @@ impl ConfigProcessor for &NoOpProcessor {
pub fn resolve_configuration(
pyproject: &Path,
relativity: &Relativity,
processor: impl ConfigProcessor,
processor: &dyn ConfigProcessor,
) -> Result<Configuration> {
let mut seen = FxHashSet::default();
let mut stack = vec![];
Expand Down Expand Up @@ -183,26 +184,20 @@ pub fn resolve_configuration(
pub fn resolve_scoped_settings(
pyproject: &Path,
relativity: &Relativity,
processor: impl ConfigProcessor,
processor: &dyn ConfigProcessor,
) -> Result<(PathBuf, AllSettings)> {
let configuration = resolve_configuration(pyproject, relativity, processor)?;
let project_root = relativity.resolve(pyproject);
let settings = AllSettings::from_configuration(configuration, &project_root)?;
Ok((project_root, settings))
}

/// Extract the [`Settings`] from a given `pyproject.toml`.
pub fn resolve_settings(pyproject: &Path, relativity: &Relativity) -> Result<AllSettings> {
let (_project_root, settings) = resolve_scoped_settings(pyproject, relativity, &NoOpProcessor)?;
Ok(settings)
}

/// Extract the [`Settings`] from a given `pyproject.toml` and process the
/// configuration with the given [`ConfigProcessor`].
pub fn resolve_settings_with_processor(
pyproject: &Path,
relativity: &Relativity,
processor: impl ConfigProcessor,
processor: &dyn ConfigProcessor,
) -> Result<AllSettings> {
let (_project_root, settings) = resolve_scoped_settings(pyproject, relativity, processor)?;
Ok(settings)
Expand All @@ -222,7 +217,7 @@ fn match_exclusion<P: AsRef<Path>, R: AsRef<Path>>(
pub fn python_files_in_path(
paths: &[PathBuf],
pyproject_config: &PyprojectConfig,
processor: impl ConfigProcessor,
processor: &dyn ConfigProcessor,
) -> Result<(Vec<Result<DirEntry, ignore::Error>>, Resolver)> {
// Normalize every path (e.g., convert from relative to absolute).
let mut paths: Vec<PathBuf> = paths.iter().map(fs::normalize_path).unique().collect();
Expand Down Expand Up @@ -368,7 +363,7 @@ pub fn python_files_in_path(
pub fn python_file_at_path(
path: &Path,
pyproject_config: &PyprojectConfig,
processor: impl ConfigProcessor,
processor: &dyn ConfigProcessor,
) -> Result<bool> {
if !pyproject_config.settings.lib.force_exclude {
return Ok(true);
Expand Down
3 changes: 2 additions & 1 deletion crates/ruff/src/rules/airflow/rules/task_variable_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast as ast;
use ruff_python_ast::Constant;
use ruff_python_ast::{Expr, Ranged};
use ruff_python_ast::Expr;
use ruff_text_size::Ranged;

use crate::checkers::ast::Checker;

Expand Down
3 changes: 2 additions & 1 deletion crates/ruff/src/rules/flake8_2020/rules/compare.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use num_bigint::BigInt;
use ruff_python_ast::{self as ast, CmpOp, Constant, Expr, Ranged};
use ruff_python_ast::{self as ast, CmpOp, Constant, Expr};

use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_text_size::Ranged;

use crate::checkers::ast::Checker;
use crate::registry::Rule;
Expand Down
3 changes: 2 additions & 1 deletion crates/ruff/src/rules/flake8_2020/rules/name_or_attribute.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use ruff_python_ast::{Expr, Ranged};
use ruff_python_ast::Expr;

use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_text_size::Ranged;

use crate::checkers::ast::Checker;

Expand Down
Loading

0 comments on commit 0c0a43c

Please sign in to comment.