mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-27 10:26:26 +00:00
Disallow newlines in format specifiers of single quoted f- or t-strings (#18708)
This commit is contained in:
parent
23261a38a0
commit
1188ffccc4
17 changed files with 521 additions and 513 deletions
|
|
@ -65,28 +65,31 @@ pub enum InterpolatedStringErrorType {
|
|||
LambdaWithoutParentheses,
|
||||
/// Conversion flag does not immediately follow exclamation.
|
||||
ConversionFlagNotImmediatelyAfterExclamation,
|
||||
/// Newline inside of a format spec for a single quoted f- or t-string.
|
||||
NewlineInFormatSpec,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for InterpolatedStringErrorType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
use InterpolatedStringErrorType::{
|
||||
ConversionFlagNotImmediatelyAfterExclamation, InvalidConversionFlag,
|
||||
LambdaWithoutParentheses, SingleRbrace, UnclosedLbrace, UnterminatedString,
|
||||
UnterminatedTripleQuotedString,
|
||||
};
|
||||
match self {
|
||||
UnclosedLbrace => write!(f, "expecting '}}'"),
|
||||
InvalidConversionFlag => write!(f, "invalid conversion character"),
|
||||
SingleRbrace => write!(f, "single '}}' is not allowed"),
|
||||
UnterminatedString => write!(f, "unterminated string"),
|
||||
UnterminatedTripleQuotedString => write!(f, "unterminated triple-quoted string"),
|
||||
LambdaWithoutParentheses => {
|
||||
Self::UnclosedLbrace => write!(f, "expecting '}}'"),
|
||||
Self::InvalidConversionFlag => write!(f, "invalid conversion character"),
|
||||
Self::SingleRbrace => write!(f, "single '}}' is not allowed"),
|
||||
Self::UnterminatedString => write!(f, "unterminated string"),
|
||||
Self::UnterminatedTripleQuotedString => write!(f, "unterminated triple-quoted string"),
|
||||
Self::LambdaWithoutParentheses => {
|
||||
write!(f, "lambda expressions are not allowed without parentheses")
|
||||
}
|
||||
ConversionFlagNotImmediatelyAfterExclamation => write!(
|
||||
Self::ConversionFlagNotImmediatelyAfterExclamation => write!(
|
||||
f,
|
||||
"conversion type must come right after the exclamation mark"
|
||||
),
|
||||
Self::NewlineInFormatSpec => {
|
||||
write!(
|
||||
f,
|
||||
"newlines are not allowed in format specifiers when using single quotes"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -430,31 +433,31 @@ impl LexicalErrorType {
|
|||
impl std::fmt::Display for LexicalErrorType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
LexicalErrorType::StringError => write!(f, "Got unexpected string"),
|
||||
LexicalErrorType::FStringError(error) => write!(f, "f-string: {error}"),
|
||||
LexicalErrorType::TStringError(error) => write!(f, "t-string: {error}"),
|
||||
LexicalErrorType::InvalidByteLiteral => {
|
||||
Self::StringError => write!(f, "Got unexpected string"),
|
||||
Self::FStringError(error) => write!(f, "f-string: {error}"),
|
||||
Self::TStringError(error) => write!(f, "t-string: {error}"),
|
||||
Self::InvalidByteLiteral => {
|
||||
write!(f, "bytes can only contain ASCII literal characters")
|
||||
}
|
||||
LexicalErrorType::UnicodeError => write!(f, "Got unexpected unicode"),
|
||||
LexicalErrorType::IndentationError => {
|
||||
Self::UnicodeError => write!(f, "Got unexpected unicode"),
|
||||
Self::IndentationError => {
|
||||
write!(f, "unindent does not match any outer indentation level")
|
||||
}
|
||||
LexicalErrorType::UnrecognizedToken { tok } => {
|
||||
Self::UnrecognizedToken { tok } => {
|
||||
write!(f, "Got unexpected token {tok}")
|
||||
}
|
||||
LexicalErrorType::LineContinuationError => {
|
||||
Self::LineContinuationError => {
|
||||
write!(f, "Expected a newline after line continuation character")
|
||||
}
|
||||
LexicalErrorType::Eof => write!(f, "unexpected EOF while parsing"),
|
||||
LexicalErrorType::OtherError(msg) => write!(f, "{msg}"),
|
||||
LexicalErrorType::UnclosedStringError => {
|
||||
Self::Eof => write!(f, "unexpected EOF while parsing"),
|
||||
Self::OtherError(msg) => write!(f, "{msg}"),
|
||||
Self::UnclosedStringError => {
|
||||
write!(f, "missing closing quote in string literal")
|
||||
}
|
||||
LexicalErrorType::MissingUnicodeLbrace => {
|
||||
Self::MissingUnicodeLbrace => {
|
||||
write!(f, "Missing `{{` in Unicode escape sequence")
|
||||
}
|
||||
LexicalErrorType::MissingUnicodeRbrace => {
|
||||
Self::MissingUnicodeRbrace => {
|
||||
write!(f, "Missing `}}` in Unicode escape sequence")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue