Extend UP032 to support implicitly concatenated strings (#6263)

This commit is contained in:
Harutaka Kawamura 2023-08-03 03:56:24 +09:00 committed by GitHub
parent bcc41ba062
commit ec8fad5b02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 359 additions and 96 deletions

View file

@ -1,6 +1,7 @@
use itertools::{Itertools, PeekingNext};
use num_traits::{cast::ToPrimitive, FromPrimitive, Signed};
use std::error::Error;
use std::ops::Deref;
use std::{cmp, str::FromStr};
@ -744,6 +745,39 @@ pub enum FormatParseError {
InvalidCharacterAfterRightBracket,
}
impl std::fmt::Display for FormatParseError {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::UnmatchedBracket => {
std::write!(fmt, "unmatched bracket in format string")
}
Self::MissingStartBracket => {
std::write!(fmt, "missing start bracket in format string")
}
Self::UnescapedStartBracketInLiteral => {
std::write!(fmt, "unescaped start bracket in literal")
}
Self::InvalidFormatSpecifier => {
std::write!(fmt, "invalid format specifier")
}
Self::UnknownConversion => {
std::write!(fmt, "unknown conversion")
}
Self::EmptyAttribute => {
std::write!(fmt, "empty attribute")
}
Self::MissingRightBracket => {
std::write!(fmt, "missing right bracket")
}
Self::InvalidCharacterAfterRightBracket => {
std::write!(fmt, "invalid character after right bracket")
}
}
}
}
impl Error for FormatParseError {}
impl FromStr for FormatSpec {
type Err = FormatSpecError;
fn from_str(s: &str) -> Result<Self, Self::Err> {