repo
stringlengths
6
65
file_url
stringlengths
81
311
file_path
stringlengths
6
227
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:31:58
2026-01-04 20:25:31
truncated
bool
2 classes
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_macros/src/newtype_index.rs
crates/ruff_macros/src/newtype_index.rs
use quote::quote; use syn::spanned::Spanned; use syn::{Error, ItemStruct}; pub(super) fn generate_newtype_index(item: ItemStruct) -> syn::Result<proc_macro2::TokenStream> { if !item.fields.is_empty() { return Err(Error::new( item.span(), "A new type index cannot have any fields.", ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_macros/src/kebab_case.rs
crates/ruff_macros/src/kebab_case.rs
use heck::ToKebabCase; use proc_macro2::TokenStream; pub(crate) fn kebab_case(input: &syn::Ident) -> TokenStream { let s = input.to_string(); let kebab_case_lit = syn::LitStr::new(&s.to_kebab_case(), input.span()); quote::quote!(#kebab_case_lit) }
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_macros/src/lib.rs
crates/ruff_macros/src/lib.rs
//! This crate implements internal macros for the `ruff` and `ty` libraries. use crate::cache_key::derive_cache_key; use crate::newtype_index::generate_newtype_index; use crate::violation_metadata::violation_metadata; use proc_macro::TokenStream; use syn::{DeriveInput, Error, ItemFn, ItemStruct, parse_macro_input}; m...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_macros/src/rust_doc.rs
crates/ruff_macros/src/rust_doc.rs
use proc_macro2::TokenStream; use quote::quote; use syn::{Attribute, DeriveInput, Error, Lit, LitStr, Meta}; pub(crate) fn derive_impl(input: DeriveInput) -> syn::Result<TokenStream> { let docs = get_docs(&input.attrs)?; let name = input.ident; let (impl_generics, ty_generics, where_clause) = &input.gene...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_macros/src/derive_message_formats.rs
crates/ruff_macros/src/derive_message_formats.rs
use proc_macro2::TokenStream; use quote::{ToTokens, quote, quote_spanned}; use syn::spanned::Spanned; use syn::token::{Dot, Paren}; use syn::{Block, Expr, ExprLit, ExprMethodCall, ItemFn, Lit, Stmt}; pub(crate) fn derive_message_formats(func: &ItemFn) -> TokenStream { let mut strings = quote!(); if let Err(er...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_macros/src/cache_key.rs
crates/ruff_macros/src/cache_key.rs
use proc_macro2::{Ident, TokenStream}; use quote::{format_ident, quote}; use syn::parse::{Parse, ParseStream}; use syn::spanned::Spanned; use syn::{Data, DeriveInput, Error, Field, Fields, Token}; pub(crate) fn derive_cache_key(item: &DeriveInput) -> syn::Result<TokenStream> { let fields = match &item.data { ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_macros/src/rule_namespace.rs
crates/ruff_macros/src/rule_namespace.rs
use std::cmp::Reverse; use std::collections::HashSet; use quote::quote; use syn::spanned::Spanned; use syn::{Attribute, Data, DataEnum, DeriveInput, Error, ExprLit, Lit, Meta, MetaNameValue}; pub(crate) fn derive_impl(input: DeriveInput) -> syn::Result<proc_macro2::TokenStream> { let DeriveInput { ident, ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_macros/src/combine.rs
crates/ruff_macros/src/combine.rs
use quote::{quote, quote_spanned}; use syn::spanned::Spanned; use syn::{Data, DataStruct, DeriveInput}; pub(crate) fn derive_impl(input: DeriveInput) -> syn::Result<proc_macro2::TokenStream> { let DeriveInput { ident, data, .. } = input; match data { Data::Struct(DataStruct { fields, .. }) => { ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_macros/src/rule_code_prefix.rs
crates/ruff_macros/src/rule_code_prefix.rs
use std::collections::{BTreeMap, BTreeSet}; use proc_macro2::Span; use quote::quote; use syn::{Attribute, Ident}; pub(crate) fn expand<'a>( prefix_ident: &Ident, variants: impl Iterator<Item = (&'a str, &'a Vec<Attribute>)>, ) -> proc_macro2::TokenStream { // Build up a map from prefix to matching RuleCod...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_macros/src/env_vars.rs
crates/ruff_macros/src/env_vars.rs
use proc_macro2::TokenStream; use quote::quote; use syn::{ImplItem, ItemImpl}; pub(crate) fn attribute_env_vars_metadata(mut input: ItemImpl) -> TokenStream { // Verify that this is an impl for EnvVars let impl_type = &input.self_ty; let mut env_var_entries = Vec::new(); let mut hidden_vars = Vec::new...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_macros/src/map_codes.rs
crates/ruff_macros/src/map_codes.rs
use std::collections::{BTreeMap, HashMap}; use itertools::Itertools; use proc_macro2::TokenStream; use quote::{ToTokens, quote}; use syn::{ Attribute, Error, Expr, ExprCall, ExprMatch, Ident, ItemFn, LitStr, Pat, Path, Stmt, Token, parenthesized, parse::Parse, spanned::Spanned, }; use crate::rule_code_prefix:...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_macros/src/violation_metadata.rs
crates/ruff_macros/src/violation_metadata.rs
use proc_macro2::TokenStream; use quote::quote; use syn::{Attribute, DeriveInput, Error, Lit, LitStr, Meta}; pub(crate) fn violation_metadata(input: DeriveInput) -> syn::Result<TokenStream> { let docs = get_docs(&input.attrs)?; let Some(group) = get_rule_status(&input.attrs)? else { return Err(Error::...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ty_wasm/build.rs
crates/ty_wasm/build.rs
use std::{ fs, path::{Path, PathBuf}, process::Command, }; fn main() { // The workspace root directory is not available without walking up the tree // https://github.com/rust-lang/cargo/issues/3946 let workspace_root = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()) .join("..")...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ty_wasm/src/lib.rs
crates/ty_wasm/src/lib.rs
use std::any::Any; use js_sys::{Error, JsString}; use ruff_db::Db as _; use ruff_db::diagnostic::{self, DisplayDiagnosticConfig}; use ruff_db::files::{File, FilePath, FileRange, system_path_to_file, vendored_path_to_file}; use ruff_db::source::{SourceText, line_index, source_text}; use ruff_db::system::walk_directory:...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
true
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ty_wasm/tests/api.rs
crates/ty_wasm/tests/api.rs
#![cfg(target_arch = "wasm32")] use ty_wasm::{Position, PositionEncoding, Workspace}; use wasm_bindgen_test::wasm_bindgen_test; #[wasm_bindgen_test] fn check() { ty_wasm::before_main(); let mut workspace = Workspace::new( "/", PositionEncoding::Utf32, js_sys::JSON::parse("{}").unwrap(...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_trivia_integration_tests/src/lib.rs
crates/ruff_python_trivia_integration_tests/src/lib.rs
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_trivia_integration_tests/tests/whitespace.rs
crates/ruff_python_trivia_integration_tests/tests/whitespace.rs
use ruff_python_parser::{ParseError, parse_module}; use ruff_python_trivia::has_trailing_content; use ruff_text_size::Ranged; #[test] fn trailing_content() -> Result<(), ParseError> { let contents = "x = 1"; let suite = parse_module(contents)?.into_suite(); let stmt = suite.first().unwrap(); assert!(!h...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_trivia_integration_tests/tests/block_comments.rs
crates/ruff_python_trivia_integration_tests/tests/block_comments.rs
use ruff_python_parser::{Mode, ParseOptions, parse_unchecked}; use ruff_python_trivia::CommentRanges; use ruff_text_size::TextSize; #[test] fn block_comments_two_line_block_at_start() { // arrange let source = "# line 1\n# line 2\n"; let parsed = parse_unchecked(source, ParseOptions::from(Mode::Module)); ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_trivia_integration_tests/tests/simple_tokenizer.rs
crates/ruff_python_trivia_integration_tests/tests/simple_tokenizer.rs
use insta::assert_debug_snapshot; use ruff_python_parser::{Mode, ParseOptions, parse_unchecked}; use ruff_python_trivia::{BackwardsTokenizer, SimpleTokenKind}; use ruff_python_trivia::{CommentRanges, SimpleToken, SimpleTokenizer, lines_after, lines_before}; use ruff_text_size::{TextLen, TextRange, TextSize}; struct T...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_notebook/src/notebook.rs
crates/ruff_notebook/src/notebook.rs
use itertools::Itertools; use rand::{Rng, SeedableRng}; use serde::Serialize; use serde_json::error::Category; use std::cmp::Ordering; use std::collections::HashSet; use std::fs::File; use std::io; use std::io::{BufReader, Cursor, Read, Seek, SeekFrom, Write}; use std::path::Path; use std::sync::OnceLock; use thiserror...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_notebook/src/lib.rs
crates/ruff_notebook/src/lib.rs
//! Utils for reading and writing jupyter notebooks pub use cell::*; pub use index::*; pub use notebook::*; pub use schema::*; mod cell; mod index; mod notebook; mod schema;
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_notebook/src/index.rs
crates/ruff_notebook/src/index.rs
use serde::{Deserialize, Serialize}; use ruff_source_file::{LineColumn, OneIndexed, SourceLocation}; /// Jupyter Notebook indexing table /// /// When we lint a jupyter notebook, we have to translate the row/column based on /// [`ruff_text_size::TextSize`] to jupyter notebook cell/row/column. #[derive(Clone, Debug, Eq...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_notebook/src/schema.rs
crates/ruff_notebook/src/schema.rs
//! The JSON schema of a Jupyter Notebook, entrypoint is [`RawNotebook`] //! //! Generated by <https://app.quicktype.io/> from //! <https://github.com/jupyter/nbformat/blob/16b53251aabf472ad9406ddb1f78b0421c014eeb/nbformat/v4/nbformat.v4.schema.json> //! Jupyter Notebook v4.5 JSON schema. //! //! The following changes ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_notebook/src/cell.rs
crates/ruff_notebook/src/cell.rs
use std::fmt; use std::ops::{Deref, DerefMut}; use itertools::Itertools; use ruff_text_size::{TextRange, TextSize}; use crate::CellMetadata; use crate::schema::{Cell, SourceValue}; impl fmt::Display for SourceValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Sou...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_trivia/src/textwrap.rs
crates/ruff_python_trivia/src/textwrap.rs
//! Functions related to adding and removing indentation from lines of //! text. use std::borrow::Cow; use std::cmp; use ruff_source_file::UniversalNewlines; use crate::PythonWhitespace; /// Indent each line by the given prefix. /// /// # Examples /// /// ``` /// # use ruff_python_trivia::textwrap::indent; /// /// ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_trivia/src/cursor.rs
crates/ruff_python_trivia/src/cursor.rs
use std::str::Chars; use ruff_text_size::{TextLen, TextSize}; pub const EOF_CHAR: char = '\0'; /// A [`Cursor`] over a string. /// /// Based on [`rustc`'s `Cursor`](https://github.com/rust-lang/rust/blob/d1b7355d3d7b4ead564dbecb1d240fcc74fff21b/compiler/rustc_lexer/src/cursor.rs) #[derive(Debug, Clone)] pub struct C...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_trivia/src/lib.rs
crates/ruff_python_trivia/src/lib.rs
mod comment_ranges; mod comments; mod cursor; mod pragmas; pub mod textwrap; mod tokenizer; mod whitespace; pub use comment_ranges::CommentRanges; pub use comments::*; pub use cursor::*; pub use pragmas::*; pub use tokenizer::*; pub use whitespace::*;
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_trivia/src/comments.rs
crates/ruff_python_trivia/src/comments.rs
use ruff_text_size::TextRange; use crate::{PythonWhitespace, is_python_whitespace}; #[derive(Copy, Clone, Eq, PartialEq, Debug)] pub enum SuppressionKind { /// A `fmt: off` or `yapf: disable` comment Off, /// A `fmt: on` or `yapf: enable` comment On, /// A `fmt: skip` comment Skip, } impl Sup...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_trivia/src/comment_ranges.rs
crates/ruff_python_trivia/src/comment_ranges.rs
use std::fmt::{Debug, Formatter}; use std::ops::Deref; use itertools::Itertools; use ruff_source_file::LineRanges; use ruff_text_size::{Ranged, TextRange, TextSize}; use crate::{has_leading_content, has_trailing_content, is_python_whitespace}; /// Stores the ranges of comments sorted by [`TextRange::start`] in incr...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_trivia/src/whitespace.rs
crates/ruff_python_trivia/src/whitespace.rs
use ruff_source_file::LineRanges; use ruff_text_size::{TextRange, TextSize}; /// Extract the leading indentation from a line. pub fn indentation_at_offset(offset: TextSize, source: &str) -> Option<&str> { let line_start = source.line_start(offset); let indentation = &source[TextRange::new(line_start, offset)];...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_trivia/src/pragmas.rs
crates/ruff_python_trivia/src/pragmas.rs
/// Returns `true` if a comment appears to be a pragma comment. /// /// ``` /// assert!(ruff_python_trivia::is_pragma_comment("# type: ignore")); /// assert!(ruff_python_trivia::is_pragma_comment("# noqa: F401")); /// assert!(ruff_python_trivia::is_pragma_comment("# noqa")); /// assert!(ruff_python_trivia::is_pragma_co...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_trivia/src/tokenizer.rs
crates/ruff_python_trivia/src/tokenizer.rs
use unicode_ident::{is_xid_continue, is_xid_start}; use ruff_text_size::{Ranged, TextLen, TextRange, TextSize}; use crate::{Cursor, is_python_whitespace}; /// Searches for the first non-trivia character after `offset`. /// /// The search skips over any whitespace and comments. /// /// Returns `Some` if the source co...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/src/lib.rs
crates/ruff_annotate_snippets/src/lib.rs
#![expect(clippy::needless_doctest_main)] //! A library for formatting of text or programming code snippets. //! //! It's primary purpose is to build an ASCII-graphical representation of the snippet //! with annotations. //! //! # Example //! //! ```rust #![doc = include_str!("../examples/expected_type.rs")] //! ``` /...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/src/snippet.rs
crates/ruff_annotate_snippets/src/snippet.rs
//! Structures used as an input for the library. //! //! Example: //! //! ``` //! use ruff_annotate_snippets::*; //! //! Level::Error.title("mismatched types") //! .snippet(Snippet::source("Foo").line_start(51).origin("src/format.rs")) //! .snippet(Snippet::source("Faa").line_start(129).origin("src/display.rs")...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/src/renderer/display_list.rs
crates/ruff_annotate_snippets/src/renderer/display_list.rs
//! `display_list` module stores the output model for the snippet. //! //! `DisplayList` is a central structure in the crate, which contains //! the structured list of lines to be displayed. //! //! It is made of two types of lines: `Source` and `Raw`. All `Source` lines //! are structured using four columns: //! //! `...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
true
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/src/renderer/styled_buffer.rs
crates/ruff_annotate_snippets/src/renderer/styled_buffer.rs
//! Adapted from [styled_buffer] //! //! [styled_buffer]: https://github.com/rust-lang/rust/blob/894f7a4ba6554d3797404bbf550d9919df060b97/compiler/rustc_errors/src/styled_buffer.rs use crate::renderer::stylesheet::Stylesheet; use anstyle::Style; use std::fmt; use std::fmt::Write; #[derive(Debug)] pub(crate) struct St...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/src/renderer/stylesheet.rs
crates/ruff_annotate_snippets/src/renderer/stylesheet.rs
use anstyle::Style; #[derive(Clone, Copy, Debug)] pub(crate) struct Stylesheet { pub(crate) error: Style, pub(crate) warning: Style, pub(crate) info: Style, pub(crate) note: Style, pub(crate) help: Style, pub(crate) line_no: Style, pub(crate) emphasis: Style, pub(crate) none: Style, ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/src/renderer/margin.rs
crates/ruff_annotate_snippets/src/renderer/margin.rs
use std::cmp::{max, min}; const ELLIPSIS_PASSING: usize = 6; const LONG_WHITESPACE: usize = 20; const LONG_WHITESPACE_PADDING: usize = 4; #[derive(Clone, Copy, Debug, PartialEq)] pub(crate) struct Margin { /// The available whitespace in the left that can be consumed when centering. whitespace_left: usize, ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/src/renderer/mod.rs
crates/ruff_annotate_snippets/src/renderer/mod.rs
//! The renderer for [`Message`]s //! //! # Example //! ``` //! use ruff_annotate_snippets::{Renderer, Snippet, Level}; //! let snippet = Level::Error.title("mismatched types") //! .snippet(Snippet::source("Foo").line_start(51).origin("src/format.rs")) //! .snippet(Snippet::source("Faa").line_start(129).origin(...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/tests/rustc_tests.rs
crates/ruff_annotate_snippets/tests/rustc_tests.rs
//! These tests have been adapted from [Rust's parser tests][parser-tests]. //! //! [parser-tests]: https://github.com/rust-lang/rust/blob/894f7a4ba6554d3797404bbf550d9919df060b97/compiler/rustc_parse/src/parser/tests.rs use ruff_annotate_snippets::{Level, Renderer, Snippet}; use snapbox::{assert_data_eq, str}; #[te...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/tests/formatter.rs
crates/ruff_annotate_snippets/tests/formatter.rs
// Since this is a vendored copy of `annotate-snippets`, we squash Clippy // warnings from upstream in order to the reduce the diff. If our copy drifts // far from upstream such that patches become impractical to apply in both // places, then we can get rid of these suppressions and fix the lints. #![allow(clippy::redu...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/tests/examples.rs
crates/ruff_annotate_snippets/tests/examples.rs
#[test] fn expected_type() { let target = "expected_type"; let expected = snapbox::file!["../examples/expected_type.svg": TermSvg]; assert_example(target, expected); } #[test] fn footer() { let target = "footer"; let expected = snapbox::file!["../examples/footer.svg": TermSvg]; assert_example(t...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/tests/fixtures/deserialize.rs
crates/ruff_annotate_snippets/tests/fixtures/deserialize.rs
use serde::Deserialize; use std::ops::Range; use ruff_annotate_snippets::renderer::DEFAULT_TERM_WIDTH; use ruff_annotate_snippets::{Annotation, Level, Message, Renderer, Snippet}; #[derive(Deserialize)] pub(crate) struct Fixture { #[serde(default)] pub(crate) renderer: RendererDef, pub(crate) message: Mes...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/tests/fixtures/main.rs
crates/ruff_annotate_snippets/tests/fixtures/main.rs
mod deserialize; use crate::deserialize::Fixture; use ruff_annotate_snippets::{Message, Renderer}; use snapbox::Data; use snapbox::data::DataFormat; use std::error::Error; fn main() { tryfn::Harness::new("tests/fixtures/", setup, test) .select(["*/*.toml"]) .test(); } fn setup(input_path: std::pa...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/examples/expected_type.rs
crates/ruff_annotate_snippets/examples/expected_type.rs
use ruff_annotate_snippets::{Level, Renderer, Snippet}; fn main() { let source = r#" annotations: vec![SourceAnnotation { label: "expected struct `annotate_snippets::snippet::Slice`, found reference" , range: <22, 25>,"#; let message = Level::E...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/examples/footer.rs
crates/ruff_annotate_snippets/examples/footer.rs
use ruff_annotate_snippets::{Level, Renderer, Snippet}; fn main() { let message = Level::Error .title("mismatched types") .id("E0308") .snippet( Snippet::source(" slices: vec![\"A\",") .line_start(13) .origin...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/examples/format.rs
crates/ruff_annotate_snippets/examples/format.rs
use ruff_annotate_snippets::{Level, Renderer, Snippet}; fn main() { let source = r#") -> Option<String> { for ann in annotations { match (ann.range.0, ann.range.1) { (None, None) => continue, (Some(start), Some(end)) if start > end_index => continue, (Some(start), So...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_annotate_snippets/examples/multislice.rs
crates/ruff_annotate_snippets/examples/multislice.rs
use ruff_annotate_snippets::{Level, Renderer, Snippet}; fn main() { let message = Level::Error .title("mismatched types") .snippet( Snippet::source("Foo") .line_start(51) .origin("src/format.rs"), ) .snippet( Snippet::source("F...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/reference.rs
crates/ruff_python_semantic/src/reference.rs
use std::ops::Deref; use bitflags::bitflags; use ruff_index::{IndexSlice, IndexVec, newtype_index}; use ruff_python_ast::ExprContext; use ruff_text_size::{Ranged, TextRange}; use crate::scope::ScopeId; use crate::{Exceptions, NodeId, SemanticModelFlags}; /// A resolved read reference to a name in a program. #[deriv...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/star_import.rs
crates/ruff_python_semantic/src/star_import.rs
#[derive(Debug, Clone)] pub struct StarImport<'a> { /// The level of the import. `0` indicates an absolute import. pub level: u32, /// The module being imported. `None` indicates a wildcard import. pub module: Option<&'a str>, }
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/imports.rs
crates/ruff_python_semantic/src/imports.rs
use ruff_macros::CacheKey; use ruff_python_ast::helpers::collect_import_from_member; use ruff_python_ast::name::QualifiedName; use crate::{AnyImport, Imported}; /// A list of names imported via any import statement. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, CacheKey)] pub struct NameImports(Vec<NameImpor...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/lib.rs
crates/ruff_python_semantic/src/lib.rs
pub mod analyze; mod binding; mod branches; pub mod cfg; mod context; mod definition; mod globals; mod imports; mod model; mod nodes; mod reference; mod scope; mod star_import; pub use binding::*; pub use branches::*; pub use context::*; pub use definition::*; pub use globals::*; pub use imports::*; pub use model::*; ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/globals.rs
crates/ruff_python_semantic/src/globals.rs
//! When building a semantic model, we often need to know which names in a given scope are declared //! as `global`. This module provides data structures for storing and querying the set of `global` //! names in a given scope. use std::ops::Index; use ruff_python_ast::{self as ast, Stmt}; use ruff_text_size::{Ranged,...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/scope.rs
crates/ruff_python_semantic/src/scope.rs
use std::ops::{Deref, DerefMut}; use bitflags::bitflags; use ruff_python_ast as ast; use rustc_hash::FxHashMap; use ruff_index::{Idx, IndexSlice, IndexVec, newtype_index}; use crate::binding::BindingId; use crate::globals::GlobalsId; use crate::star_import::StarImport; #[derive(Debug)] pub struct Scope<'a> { //...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/model.rs
crates/ruff_python_semantic/src/model.rs
use std::path::Path; use bitflags::bitflags; use rustc_hash::FxHashMap; use ruff_python_ast::helpers::{from_relative_import, map_subscript}; use ruff_python_ast::name::{QualifiedName, UnqualifiedName}; use ruff_python_ast::{self as ast, Expr, ExprContext, PySourceType, Stmt}; use ruff_text_size::{Ranged, TextRange, T...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
true
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/nodes.rs
crates/ruff_python_semantic/src/nodes.rs
use std::ops::Index; use ruff_index::{IndexVec, newtype_index}; use ruff_python_ast::{Expr, Stmt}; use ruff_text_size::{Ranged, TextRange}; use crate::BranchId; /// Id uniquely identifying an AST node in a program. /// /// Using a `u32` is sufficient because Ruff only supports parsing documents with a size of max //...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/definition.rs
crates/ruff_python_semantic/src/definition.rs
//! Definitions within a Python program. In this context, a "definition" is any named entity that //! can be documented, such as a module, class, or function. use std::fmt::Debug; use std::ops::Deref; use std::path::Path; use ruff_index::{IndexSlice, IndexVec, newtype_index}; use ruff_python_ast::name::QualifiedName;...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/binding.rs
crates/ruff_python_semantic/src/binding.rs
use std::borrow::Cow; use std::ops::{Deref, DerefMut}; use bitflags::bitflags; use crate::all::DunderAllName; use ruff_index::{IndexSlice, IndexVec, newtype_index}; use ruff_python_ast::helpers::extract_handled_exceptions; use ruff_python_ast::name::QualifiedName; use ruff_python_ast::{self as ast, Stmt}; use ruff_te...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/context.rs
crates/ruff_python_semantic/src/context.rs
#[derive(Debug, Copy, Clone, is_macro::Is)] pub enum ExecutionContext { /// The reference occurs in a runtime context. Runtime, /// The reference occurs in a typing-only context. Typing, }
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/branches.rs
crates/ruff_python_semantic/src/branches.rs
use std::ops::Index; use ruff_index::{IndexVec, newtype_index}; /// ID uniquely identifying a branch in a program. /// /// For example, given: /// ```python /// if x > 0: /// pass /// elif x > 1: /// pass /// else: /// pass /// ``` /// /// Each of the three arms of the `if`-`elif`-`else` would be consider...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/model/all.rs
crates/ruff_python_semantic/src/model/all.rs
//! Utilities for semantic analysis of `__all__` definitions use bitflags::bitflags; use ruff_python_ast::{self as ast, Expr, Stmt, helpers::map_subscript}; use ruff_text_size::{Ranged, TextRange}; use crate::SemanticModel; bitflags! { #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] pub struct DunderA...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/analyze/visibility.rs
crates/ruff_python_semantic/src/analyze/visibility.rs
use ruff_python_ast::{self as ast, Decorator, Expr}; use ruff_python_ast::helpers::map_callable; use ruff_python_ast::name::{QualifiedName, UnqualifiedName}; use crate::model::SemanticModel; use crate::{Module, ModuleSource}; #[derive(Debug, Clone, Copy, is_macro::Is)] pub enum Visibility { Public, Private, ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/analyze/imports.rs
crates/ruff_python_semantic/src/analyze/imports.rs
use ruff_python_ast::helpers::map_subscript; use ruff_python_ast::{self as ast, Expr, Stmt}; use crate::SemanticModel; /// Returns `true` if a [`Stmt`] is a `sys.path` modification, as in: /// ```python /// import sys /// /// sys.path.append("../") /// sys.path += ["../"] /// ``` pub fn is_sys_path_modification(stmt:...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/analyze/class.rs
crates/ruff_python_semantic/src/analyze/class.rs
use std::collections::VecDeque; use rustc_hash::FxHashSet; use crate::analyze::typing; use crate::{BindingId, SemanticModel}; use ruff_python_ast as ast; use ruff_python_ast::helpers::map_subscript; use ruff_python_ast::name::QualifiedName; use ruff_python_ast::{ ExceptHandler, Expr, ExprName, ExprStarred, ExprSu...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/analyze/function_type.rs
crates/ruff_python_semantic/src/analyze/function_type.rs
use ruff_python_ast::helpers::map_callable; use ruff_python_ast::name::{QualifiedName, UnqualifiedName}; use ruff_python_ast::{Decorator, Expr, Stmt, StmtExpr, StmtFunctionDef, StmtRaise}; use crate::model::SemanticModel; use crate::scope::Scope; #[derive(Debug, Copy, Clone)] pub enum FunctionType { Function, ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/analyze/terminal.rs
crates/ruff_python_semantic/src/analyze/terminal.rs
use ruff_python_ast::{self as ast, ExceptHandler, Stmt}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Terminal { /// There is no known terminal. None, /// There is an implicit return (e.g., a path that doesn't return). Implicit, /// Every path through the function ends with a `raise` state...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/analyze/mod.rs
crates/ruff_python_semantic/src/analyze/mod.rs
pub mod class; pub mod function_type; pub mod imports; pub mod logging; pub mod terminal; pub mod type_inference; pub mod typing; pub mod visibility;
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/analyze/typing.rs
crates/ruff_python_semantic/src/analyze/typing.rs
//! Analysis rules for the `typing` module. use ruff_python_ast::helpers::{any_over_expr, map_subscript}; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::name::QualifiedName; use ruff_python_ast::{ self as ast, Expr, ExprCall, ExprName, Operator, ParameterWithDefault, Parameters, Stmt, StmtAs...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
true
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/analyze/logging.rs
crates/ruff_python_semantic/src/analyze/logging.rs
use ruff_python_ast::helpers::is_const_true; use ruff_python_ast::name::{QualifiedName, UnqualifiedName}; use ruff_python_ast::{self as ast, Arguments, Expr, Keyword}; use crate::model::SemanticModel; /// Return `true` if the given `Expr` is a potential logging call. Matches /// `logging.error`, `logger.error`, `self...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/analyze/type_inference.rs
crates/ruff_python_semantic/src/analyze/type_inference.rs
//! Analysis rules to perform basic type inference on individual expressions. use rustc_hash::FxHashSet; use ruff_python_ast as ast; use ruff_python_ast::{Expr, Operator, UnaryOp}; #[derive(Debug, Clone, PartialEq, Eq)] pub enum ResolvedPythonType { /// The expression resolved to a single known type, like `str` ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/cfg/mod.rs
crates/ruff_python_semantic/src/cfg/mod.rs
pub mod graph; pub mod visualize; #[cfg(test)] mod tests { use std::fmt::Write; use std::fs; use std::path::PathBuf; use crate::cfg::graph::build_cfg; use crate::cfg::visualize::draw_cfg; use insta; use ruff_python_parser::parse_module; use ruff_text_size::Ranged; use test_case::t...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/cfg/visualize.rs
crates/ruff_python_semantic/src/cfg/visualize.rs
//! Heavily inspired by rustc data structures use ruff_index::Idx; use ruff_text_size::Ranged; use std::fmt::{self, Display}; use crate::cfg::graph::{BlockId, BlockKind, Condition, ControlFlowGraph}; /// Returns control flow graph in Mermaid syntax. pub fn draw_cfg(graph: ControlFlowGraph, source: &str) -> String { ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_semantic/src/cfg/graph.rs
crates/ruff_python_semantic/src/cfg/graph.rs
use ruff_index::{IndexVec, newtype_index}; use ruff_python_ast::Stmt; use ruff_text_size::{Ranged, TextRange}; use smallvec::{SmallVec, smallvec}; /// Returns the control flow graph associated to an array of statements pub fn build_cfg(stmts: &[Stmt]) -> ControlFlowGraph<'_> { let mut builder = CFGBuilder::with_ca...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_cache/src/lib.rs
crates/ruff_cache/src/lib.rs
use std::path::{Path, PathBuf}; pub use cache_key::{CacheKey, CacheKeyHasher}; mod cache_key; pub mod filetime; pub mod globset; pub const CACHE_DIR_NAME: &str = ".ruff_cache"; /// Return the cache directory for a given project root. pub fn cache_dir(project_root: &Path) -> PathBuf { project_root.join(CACHE_DIR...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_cache/src/globset.rs
crates/ruff_cache/src/globset.rs
use globset::{Glob, GlobMatcher}; use crate::{CacheKey, CacheKeyHasher}; impl CacheKey for GlobMatcher { fn cache_key(&self, state: &mut CacheKeyHasher) { self.glob().cache_key(state); } } impl CacheKey for Glob { fn cache_key(&self, state: &mut CacheKeyHasher) { self.glob().cache_key(sta...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_cache/src/cache_key.rs
crates/ruff_cache/src/cache_key.rs
use std::borrow::Cow; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use std::hash::{Hash, Hasher}; use std::num::{ NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI128, NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU128, }; use std::path::{Path, PathBuf}; use glob::Pattern; use it...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_cache/src/filetime.rs
crates/ruff_cache/src/filetime.rs
use std::hash::Hash; use filetime::FileTime; use crate::{CacheKey, CacheKeyHasher}; impl CacheKey for FileTime { fn cache_key(&self, state: &mut CacheKeyHasher) { self.hash(&mut *state); } }
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_cache/tests/cache_key.rs
crates/ruff_cache/tests/cache_key.rs
use std::hash::{Hash, Hasher}; use ruff_cache::{CacheKey, CacheKeyHasher}; use ruff_macros::CacheKey; #[test] fn unit_struct_cache_key() { #[derive(CacheKey, Hash)] struct UnitStruct; let mut key = CacheKeyHasher::new(); UnitStruct.cache_key(&mut key); let mut hash = CacheKeyHasher::new(); ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_index/src/multiline_ranges.rs
crates/ruff_python_index/src/multiline_ranges.rs
use ruff_python_ast::token::{Token, TokenKind}; use ruff_text_size::{Ranged, TextRange}; /// Stores the range of all multiline strings in a file sorted by /// [`TextRange::start`]. pub struct MultilineRanges { ranges: Vec<TextRange>, } impl MultilineRanges { /// Returns `true` if the given range is inside a m...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_index/src/lib.rs
crates/ruff_python_index/src/lib.rs
mod indexer; mod interpolated_string_ranges; mod multiline_ranges; pub use indexer::Indexer;
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_index/src/interpolated_string_ranges.rs
crates/ruff_python_index/src/interpolated_string_ranges.rs
use std::collections::BTreeMap; use ruff_python_ast::token::{Token, TokenKind}; use ruff_text_size::{Ranged, TextRange, TextSize}; /// Stores the ranges of all interpolated strings in a file sorted by [`TextRange::start`]. /// There can be multiple overlapping ranges for nested interpolated strings. /// /// Note that...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_python_index/src/indexer.rs
crates/ruff_python_index/src/indexer.rs
//! Struct used to index source code, to enable efficient lookup of tokens that //! are omitted from the AST (e.g., commented lines). use ruff_python_ast::Stmt; use ruff_python_ast::token::{TokenKind, Tokens}; use ruff_python_trivia::{ CommentRanges, has_leading_content, has_trailing_content, is_python_whitespace,...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/workspace.rs
crates/ruff_server/src/workspace.rs
use std::ops::Deref; use lsp_types::{Url, WorkspaceFolder}; use thiserror::Error; use crate::session::{ClientOptions, WorkspaceOptionsMap}; #[derive(Debug)] pub struct Workspaces(Vec<Workspace>); impl Workspaces { pub fn new(workspaces: Vec<Workspace>) -> Self { Self(workspaces) } /// Create th...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/lib.rs
crates/ruff_server/src/lib.rs
//! ## The Ruff Language Server use std::num::NonZeroUsize; use anyhow::Context as _; pub use edit::{DocumentKey, NotebookDocument, PositionEncoding, TextDocument}; use lsp_types::CodeActionKind; pub use server::{ConnectionSender, MainLoopSender, Server}; pub use session::{Client, ClientOptions, DocumentQuery, Docume...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/fix.rs
crates/ruff_server/src/fix.rs
use std::borrow::Cow; use rustc_hash::FxHashMap; use crate::{ PositionEncoding, edit::{Replacement, ToRangeExt}, resolve::is_document_excluded_for_linting, session::DocumentQuery, }; use ruff_linter::package::PackageRoot; use ruff_linter::{ linter::FixerResult, packaging::detect_package_root, ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/session.rs
crates/ruff_server/src/session.rs
//! Data model, state management, and configuration resolution. use std::path::Path; use std::sync::Arc; use lsp_types::{ClientCapabilities, FileEvent, NotebookDocumentCellChange, Url}; use settings::ClientSettings; use crate::edit::{DocumentKey, DocumentVersion, NotebookDocument}; use crate::session::request_queue:...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/lint.rs
crates/ruff_server/src/lint.rs
//! Access to the Ruff linting API for the LSP use rustc_hash::FxHashMap; use serde::{Deserialize, Serialize}; use crate::{ DIAGNOSTIC_NAME, PositionEncoding, edit::{NotebookRange, ToRangeExt}, resolve::is_document_excluded_for_linting, session::DocumentQuery, }; use ruff_db::diagnostic::Diagnostic; u...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/format.rs
crates/ruff_server/src/format.rs
use std::io::Write; use std::path::Path; use std::process::{Command, Stdio}; use anyhow::Context; use ruff_formatter::{FormatOptions, PrintedRange}; use ruff_python_ast::PySourceType; use ruff_python_formatter::{FormatModuleError, PyFormatOptions, format_module_source}; use ruff_source_file::LineIndex; use ruff_text_...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/resolve.rs
crates/ruff_server/src/resolve.rs
use std::path::Path; use ruff_linter::settings::LinterSettings; use ruff_workspace::resolver::{match_any_exclusion, match_any_inclusion}; use ruff_workspace::{FileResolverSettings, FormatterSettings}; use crate::edit::LanguageId; /// Return `true` if the document at the given [`Path`] should be excluded from linting...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/server.rs
crates/ruff_server/src/server.rs
//! Scheduling, I/O, and API endpoints. use lsp_server::Connection; use lsp_types as types; use lsp_types::InitializeParams; use lsp_types::MessageType; use std::num::NonZeroUsize; use std::panic::PanicHookInfo; use std::str::FromStr; use std::sync::Arc; use types::ClientCapabilities; use types::CodeActionKind; use ty...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/edit.rs
crates/ruff_server/src/edit.rs
//! Types and utilities for working with text, modifying source files, and `Ruff <-> LSP` type conversion. mod notebook; mod range; mod replacement; mod text_document; use std::collections::HashMap; use lsp_types::{PositionEncodingKind, Url}; pub use notebook::NotebookDocument; pub(crate) use range::{NotebookRange, ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/logging.rs
crates/ruff_server/src/logging.rs
//! The logging system for `ruff server`. //! //! Log messages are controlled by the `logLevel` setting which defaults to `"info"`. Log messages //! are written to `stderr` by default, which should appear in the logs for most LSP clients. A //! `logFile` path can also be specified in the settings, and output will be di...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/edit/notebook.rs
crates/ruff_server/src/edit/notebook.rs
use anyhow::Ok; use lsp_types::NotebookCellKind; use ruff_notebook::CellMetadata; use rustc_hash::{FxBuildHasher, FxHashMap}; use crate::{PositionEncoding, TextDocument}; use super::DocumentVersion; pub(super) type CellId = usize; /// The state of a notebook document in the server. Contains an array of cells whose ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/edit/range.rs
crates/ruff_server/src/edit/range.rs
use super::PositionEncoding; use super::notebook; use lsp_types as types; use ruff_notebook::NotebookIndex; use ruff_source_file::LineIndex; use ruff_source_file::{OneIndexed, SourceLocation}; use ruff_text_size::TextRange; pub(crate) struct NotebookRange { pub(crate) cell: notebook::CellId, pub(crate) range: ...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/edit/replacement.rs
crates/ruff_server/src/edit/replacement.rs
use ruff_text_size::{TextLen, TextRange, TextSize}; #[derive(Debug)] pub(crate) struct Replacement { pub(crate) source_range: TextRange, pub(crate) modified_range: TextRange, } impl Replacement { /// Creates a [`Replacement`] that describes the `source_range` of `source` to replace /// with `modified`...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/edit/text_document.rs
crates/ruff_server/src/edit/text_document.rs
use lsp_types::TextDocumentContentChangeEvent; use ruff_source_file::LineIndex; use crate::PositionEncoding; use super::RangeExt; pub(crate) type DocumentVersion = i32; /// The state of an individual document in the server. Stays up-to-date /// with changes made by the user, including unsaved changes. #[derive(Debu...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/session/settings.rs
crates/ruff_server/src/session/settings.rs
use std::{path::PathBuf, sync::Arc}; use thiserror::Error; use ruff_linter::RuleSelector; use ruff_linter::line_width::LineLength; use ruff_workspace::options::Options; use crate::{ ClientOptions, format::FormatBackend, session::{ Client, options::{ClientConfiguration, ConfigurationPrefer...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/session/index.rs
crates/ruff_server/src/session/index.rs
use std::borrow::Cow; use std::ops::{Deref, DerefMut}; use std::path::PathBuf; use std::{collections::BTreeMap, path::Path, sync::Arc}; use anyhow::anyhow; use lsp_types::{FileEvent, Url}; use rustc_hash::{FxHashMap, FxHashSet}; use thiserror::Error; pub(crate) use ruff_settings::RuffSettings; use crate::edit::Langu...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/session/client.rs
crates/ruff_server/src/session/client.rs
use crate::Session; use crate::server::{ConnectionSender, Event, MainLoopSender}; use anyhow::{Context, anyhow}; use lsp_server::{ErrorCode, Message, Notification, RequestId, ResponseError}; use serde_json::Value; use std::any::TypeId; use std::fmt::Display; pub(crate) type ClientResponseHandler = Box<dyn FnOnce(&Clie...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
false
astral-sh/ruff
https://github.com/astral-sh/ruff/blob/8464aca795bc3580ca15fcb52b21616939cea9a9/crates/ruff_server/src/session/options.rs
crates/ruff_server/src/session/options.rs
use std::{path::PathBuf, str::FromStr as _}; use lsp_types::Url; use rustc_hash::FxHashMap; use serde::Deserialize; use serde_json::{Map, Value}; use ruff_linter::{RuleSelector, line_width::LineLength, rule_selector::ParseError}; use crate::{ format::FormatBackend, session::{ Client, settings...
rust
MIT
8464aca795bc3580ca15fcb52b21616939cea9a9
2026-01-04T15:31:59.413821Z
true