Derive message formats macro support to string (#14093)

This commit is contained in:
Simon Brugman 2024-11-04 18:06:25 +01:00 committed by GitHub
parent bc0586d922
commit fb94b71e63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
382 changed files with 843 additions and 854 deletions

View file

@ -37,7 +37,7 @@ impl Violation for CommentedOutCode {
#[derive_message_formats]
fn message(&self) -> String {
format!("Found commented-out code")
"Found commented-out code".to_string()
}
fn fix_title(&self) -> Option<String> {

View file

@ -64,7 +64,7 @@ impl Violation for FastApiNonAnnotatedDependency {
#[derive_message_formats]
fn message(&self) -> String {
format!("FastAPI dependency without `Annotated`")
"FastAPI dependency without `Annotated`".to_string()
}
fn fix_title(&self) -> Option<String> {

View file

@ -65,7 +65,7 @@ pub struct FastApiRedundantResponseModel;
impl AlwaysFixableViolation for FastApiRedundantResponseModel {
#[derive_message_formats]
fn message(&self) -> String {
format!("FastAPI route with redundant `response_model` argument")
"FastAPI route with redundant `response_model` argument".to_string()
}
fn fix_title(&self) -> String {

View file

@ -46,7 +46,7 @@ pub struct SysVersionCmpStr3;
impl Violation for SysVersionCmpStr3 {
#[derive_message_formats]
fn message(&self) -> String {
format!("`sys.version` compared to string (python3.10), use `sys.version_info`")
"`sys.version` compared to string (python3.10), use `sys.version_info`".to_string()
}
}
@ -93,7 +93,7 @@ pub struct SysVersionInfo0Eq3;
impl Violation for SysVersionInfo0Eq3 {
#[derive_message_formats]
fn message(&self) -> String {
format!("`sys.version_info[0] == 3` referenced (python4), use `>=`")
"`sys.version_info[0] == 3` referenced (python4), use `>=`".to_string()
}
}
@ -133,10 +133,9 @@ pub struct SysVersionInfo1CmpInt;
impl Violation for SysVersionInfo1CmpInt {
#[derive_message_formats]
fn message(&self) -> String {
format!(
"`sys.version_info[1]` compared to integer (python4), compare `sys.version_info` to \
"`sys.version_info[1]` compared to integer (python4), compare `sys.version_info` to \
tuple"
)
.to_string()
}
}
@ -176,10 +175,9 @@ pub struct SysVersionInfoMinorCmpInt;
impl Violation for SysVersionInfoMinorCmpInt {
#[derive_message_formats]
fn message(&self) -> String {
format!(
"`sys.version_info.minor` compared to integer (python4), compare `sys.version_info` \
"`sys.version_info.minor` compared to integer (python4), compare `sys.version_info` \
to tuple"
)
.to_string()
}
}
@ -220,7 +218,7 @@ pub struct SysVersionCmpStr10;
impl Violation for SysVersionCmpStr10 {
#[derive_message_formats]
fn message(&self) -> String {
format!("`sys.version` compared to string (python10), use `sys.version_info`")
"`sys.version` compared to string (python10), use `sys.version_info`".to_string()
}
}

View file

@ -41,7 +41,7 @@ pub struct SixPY3;
impl Violation for SixPY3 {
#[derive_message_formats]
fn message(&self) -> String {
format!("`six.PY3` referenced (python4), use `not six.PY2`")
"`six.PY3` referenced (python4), use `not six.PY2`".to_string()
}
}

View file

@ -43,7 +43,7 @@ pub struct SysVersionSlice3;
impl Violation for SysVersionSlice3 {
#[derive_message_formats]
fn message(&self) -> String {
format!("`sys.version[:3]` referenced (python3.10), use `sys.version_info`")
"`sys.version[:3]` referenced (python3.10), use `sys.version_info`".to_string()
}
}
@ -83,7 +83,7 @@ pub struct SysVersion2;
impl Violation for SysVersion2 {
#[derive_message_formats]
fn message(&self) -> String {
format!("`sys.version[2]` referenced (python3.10), use `sys.version_info`")
"`sys.version[2]` referenced (python3.10), use `sys.version_info`".to_string()
}
}
@ -123,7 +123,7 @@ pub struct SysVersion0;
impl Violation for SysVersion0 {
#[derive_message_formats]
fn message(&self) -> String {
format!("`sys.version[0]` referenced (python10), use `sys.version_info`")
"`sys.version[0]` referenced (python10), use `sys.version_info`".to_string()
}
}
@ -163,7 +163,7 @@ pub struct SysVersionSlice1;
impl Violation for SysVersionSlice1 {
#[derive_message_formats]
fn message(&self) -> String {
format!("`sys.version[:1]` referenced (python10), use `sys.version_info`")
"`sys.version[:1]` referenced (python10), use `sys.version_info`".to_string()
}
}

View file

@ -71,7 +71,7 @@ pub struct AsyncFunctionWithTimeout {
impl Violation for AsyncFunctionWithTimeout {
#[derive_message_formats]
fn message(&self) -> String {
format!("Async function definition with a `timeout` parameter")
"Async function definition with a `timeout` parameter".to_string()
}
fn fix_title(&self) -> Option<String> {

View file

@ -37,7 +37,7 @@ pub struct BlockingHttpCallInAsyncFunction;
impl Violation for BlockingHttpCallInAsyncFunction {
#[derive_message_formats]
fn message(&self) -> String {
format!("Async functions should not call blocking HTTP methods")
"Async functions should not call blocking HTTP methods".to_string()
}
}

View file

@ -39,7 +39,7 @@ pub struct BlockingOpenCallInAsyncFunction;
impl Violation for BlockingOpenCallInAsyncFunction {
#[derive_message_formats]
fn message(&self) -> String {
format!("Async functions should not open files with blocking methods like `open`")
"Async functions should not open files with blocking methods like `open`".to_string()
}
}

View file

@ -36,7 +36,7 @@ pub struct CreateSubprocessInAsyncFunction;
impl Violation for CreateSubprocessInAsyncFunction {
#[derive_message_formats]
fn message(&self) -> String {
format!("Async functions should not create subprocesses with blocking methods")
"Async functions should not create subprocesses with blocking methods".to_string()
}
}
@ -68,7 +68,7 @@ pub struct RunProcessInAsyncFunction;
impl Violation for RunProcessInAsyncFunction {
#[derive_message_formats]
fn message(&self) -> String {
format!("Async functions should not run processes with blocking methods")
"Async functions should not run processes with blocking methods".to_string()
}
}
@ -104,7 +104,7 @@ pub struct WaitForProcessInAsyncFunction;
impl Violation for WaitForProcessInAsyncFunction {
#[derive_message_formats]
fn message(&self) -> String {
format!("Async functions should not wait on processes with blocking methods")
"Async functions should not wait on processes with blocking methods".to_string()
}
}

View file

@ -34,7 +34,7 @@ pub struct BlockingSleepInAsyncFunction;
impl Violation for BlockingSleepInAsyncFunction {
#[derive_message_formats]
fn message(&self) -> String {
format!("Async functions should not call `time.sleep`")
"Async functions should not call `time.sleep`".to_string()
}
}

View file

@ -36,7 +36,7 @@ pub struct Assert;
impl Violation for Assert {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use of `assert` detected")
"Use of `assert` detected".to_string()
}
}

View file

@ -47,7 +47,9 @@ impl Violation for BadFilePermissions {
Reason::Permissive(mask) => {
format!("`os.chmod` setting a permissive mask `{mask:#o}` on file or directory")
}
Reason::Invalid => format!("`os.chmod` setting an invalid mask on file or directory"),
Reason::Invalid => {
"`os.chmod` setting an invalid mask on file or directory".to_string()
}
}
}
}

View file

@ -39,7 +39,7 @@ pub struct DjangoExtra;
impl Violation for DjangoExtra {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use of Django `extra` can lead to SQL injection vulnerabilities")
"Use of Django `extra` can lead to SQL injection vulnerabilities".to_string()
}
}

View file

@ -30,7 +30,7 @@ pub struct DjangoRawSql;
impl Violation for DjangoRawSql {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use of `RawSQL` can lead to SQL injection vulnerabilities")
"Use of `RawSQL` can lead to SQL injection vulnerabilities".to_string()
}
}

View file

@ -27,7 +27,7 @@ pub struct ExecBuiltin;
impl Violation for ExecBuiltin {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use of `exec` detected")
"Use of `exec` detected".to_string()
}
}

View file

@ -42,7 +42,7 @@ pub struct FlaskDebugTrue;
impl Violation for FlaskDebugTrue {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use of `debug=True` in Flask app detected")
"Use of `debug=True` in Flask app detected".to_string()
}
}

View file

@ -32,7 +32,7 @@ pub struct HardcodedBindAllInterfaces;
impl Violation for HardcodedBindAllInterfaces {
#[derive_message_formats]
fn message(&self) -> String {
format!("Possible binding to all interfaces")
"Possible binding to all interfaces".to_string()
}
}

View file

@ -41,7 +41,7 @@ pub struct HardcodedSQLExpression;
impl Violation for HardcodedSQLExpression {
#[derive_message_formats]
fn message(&self) -> String {
format!("Possible SQL injection vector through string-based query construction")
"Possible SQL injection vector through string-based query construction".to_string()
}
}

View file

@ -42,17 +42,15 @@ pub struct Jinja2AutoescapeFalse {
impl Violation for Jinja2AutoescapeFalse {
#[derive_message_formats]
fn message(&self) -> String {
let Jinja2AutoescapeFalse { value } = self;
match value {
true => format!(
"Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. \
if self.value {
"Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. \
Ensure `autoescape=True` or use the `select_autoescape` function."
),
false => format!(
"By default, jinja2 sets `autoescape` to `False`. Consider using \
`autoescape=True` or the `select_autoescape` function to mitigate XSS \
vulnerabilities."
),
.to_string()
} else {
"By default, jinja2 sets `autoescape` to `False`. Consider using \
`autoescape=True` or the `select_autoescape` function to mitigate XSS \
vulnerabilities."
.to_string()
}
}
}

View file

@ -30,7 +30,7 @@ pub struct LoggingConfigInsecureListen;
impl Violation for LoggingConfigInsecureListen {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use of insecure `logging.config.listen` detected")
"Use of insecure `logging.config.listen` detected".to_string()
}
}

View file

@ -37,9 +37,7 @@ pub struct MakoTemplates;
impl Violation for MakoTemplates {
#[derive_message_formats]
fn message(&self) -> String {
format!(
"Mako templates allow HTML and JavaScript rendering by default and are inherently open to XSS attacks"
)
"Mako templates allow HTML and JavaScript rendering by default and are inherently open to XSS attacks".to_string()
}
}

View file

@ -31,7 +31,8 @@ pub struct ParamikoCall;
impl Violation for ParamikoCall {
#[derive_message_formats]
fn message(&self) -> String {
format!("Possible shell injection via Paramiko call; check inputs are properly sanitized")
"Possible shell injection via Paramiko call; check inputs are properly sanitized"
.to_string()
}
}

View file

@ -46,14 +46,10 @@ impl Violation for SubprocessPopenWithShellEqualsTrue {
#[derive_message_formats]
fn message(&self) -> String {
match (self.safety, self.is_exact) {
(Safety::SeemsSafe, true) => format!(
"`subprocess` call with `shell=True` seems safe, but may be changed in the future; consider rewriting without `shell`"
),
(Safety::Unknown, true) => format!("`subprocess` call with `shell=True` identified, security issue"),
(Safety::SeemsSafe, false) => format!(
"`subprocess` call with truthy `shell` seems safe, but may be changed in the future; consider rewriting without `shell`"
),
(Safety::Unknown, false) => format!("`subprocess` call with truthy `shell` identified, security issue"),
(Safety::SeemsSafe, true) => "`subprocess` call with `shell=True` seems safe, but may be changed in the future; consider rewriting without `shell`".to_string(),
(Safety::Unknown, true) => "`subprocess` call with `shell=True` identified, security issue".to_string(),
(Safety::SeemsSafe, false) => "`subprocess` call with truthy `shell` seems safe, but may be changed in the future; consider rewriting without `shell`".to_string(),
(Safety::Unknown, false) => "`subprocess` call with truthy `shell` identified, security issue".to_string(),
}
}
}
@ -88,7 +84,7 @@ pub struct SubprocessWithoutShellEqualsTrue;
impl Violation for SubprocessWithoutShellEqualsTrue {
#[derive_message_formats]
fn message(&self) -> String {
format!("`subprocess` call: check for execution of untrusted input")
"`subprocess` call: check for execution of untrusted input".to_string()
}
}
@ -129,9 +125,9 @@ impl Violation for CallWithShellEqualsTrue {
#[derive_message_formats]
fn message(&self) -> String {
if self.is_exact {
format!("Function call with `shell=True` parameter identified, security issue")
"Function call with `shell=True` parameter identified, security issue".to_string()
} else {
format!("Function call with truthy `shell` parameter identified, security issue")
"Function call with truthy `shell` parameter identified, security issue".to_string()
}
}
}
@ -181,8 +177,8 @@ impl Violation for StartProcessWithAShell {
#[derive_message_formats]
fn message(&self) -> String {
match self.safety {
Safety::SeemsSafe => format!("Starting a process with a shell: seems safe, but may be changed in the future; consider rewriting without `shell`"),
Safety::Unknown => format!("Starting a process with a shell, possible injection detected"),
Safety::SeemsSafe => "Starting a process with a shell: seems safe, but may be changed in the future; consider rewriting without `shell`".to_string(),
Safety::Unknown => "Starting a process with a shell, possible injection detected".to_string(),
}
}
}
@ -219,7 +215,7 @@ pub struct StartProcessWithNoShell;
impl Violation for StartProcessWithNoShell {
#[derive_message_formats]
fn message(&self) -> String {
format!("Starting a process without a shell")
"Starting a process without a shell".to_string()
}
}
@ -254,7 +250,7 @@ pub struct StartProcessWithPartialPath;
impl Violation for StartProcessWithPartialPath {
#[derive_message_formats]
fn message(&self) -> String {
format!("Starting a process with a partial executable path")
"Starting a process with a partial executable path".to_string()
}
}
@ -287,7 +283,7 @@ pub struct UnixCommandWildcardInjection;
impl Violation for UnixCommandWildcardInjection {
#[derive_message_formats]
fn message(&self) -> String {
format!("Possible wildcard injection in call due to `*` usage")
"Possible wildcard injection in call due to `*` usage".to_string()
}
}

View file

@ -36,7 +36,7 @@ pub struct SnmpInsecureVersion;
impl Violation for SnmpInsecureVersion {
#[derive_message_formats]
fn message(&self) -> String {
format!("The use of SNMPv1 and SNMPv2 is insecure. Use SNMPv3 if able.")
"The use of SNMPv1 and SNMPv2 is insecure. Use SNMPv3 if able.".to_string()
}
}

View file

@ -34,9 +34,8 @@ pub struct SnmpWeakCryptography;
impl Violation for SnmpWeakCryptography {
#[derive_message_formats]
fn message(&self) -> String {
format!(
"You should not use SNMPv3 without encryption. `noAuthNoPriv` & `authNoPriv` is insecure."
)
"You should not use SNMPv3 without encryption. `noAuthNoPriv` & `authNoPriv` is insecure."
.to_string()
}
}

View file

@ -39,7 +39,7 @@ pub struct SSHNoHostKeyVerification;
impl Violation for SSHNoHostKeyVerification {
#[derive_message_formats]
fn message(&self) -> String {
format!("Paramiko call with policy set to automatically trust the unknown host key")
"Paramiko call with policy set to automatically trust the unknown host key".to_string()
}
}

View file

@ -31,7 +31,7 @@ pub struct SslWithNoVersion;
impl Violation for SslWithNoVersion {
#[derive_message_formats]
fn message(&self) -> String {
format!("`ssl.wrap_socket` called without an `ssl_version``")
"`ssl.wrap_socket` called without an `ssl_version``".to_string()
}
}

View file

@ -52,7 +52,7 @@ pub struct SuspiciousPickleUsage;
impl Violation for SuspiciousPickleUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("`pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue")
"`pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue".to_string()
}
}
@ -97,7 +97,7 @@ pub struct SuspiciousMarshalUsage;
impl Violation for SuspiciousMarshalUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Deserialization with the `marshal` module is possibly dangerous")
"Deserialization with the `marshal` module is possibly dangerous".to_string()
}
}
@ -143,7 +143,7 @@ pub struct SuspiciousInsecureHashUsage;
impl Violation for SuspiciousInsecureHashUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use of insecure MD2, MD4, MD5, or SHA1 hash function")
"Use of insecure MD2, MD4, MD5, or SHA1 hash function".to_string()
}
}
@ -181,7 +181,7 @@ pub struct SuspiciousInsecureCipherUsage;
impl Violation for SuspiciousInsecureCipherUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use of insecure cipher, replace with a known secure cipher such as AES")
"Use of insecure cipher, replace with a known secure cipher such as AES".to_string()
}
}
@ -221,7 +221,8 @@ pub struct SuspiciousInsecureCipherModeUsage;
impl Violation for SuspiciousInsecureCipherModeUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use of insecure block cipher mode, replace with a known secure mode such as CBC or CTR")
"Use of insecure block cipher mode, replace with a known secure mode such as CBC or CTR"
.to_string()
}
}
@ -265,7 +266,7 @@ pub struct SuspiciousMktempUsage;
impl Violation for SuspiciousMktempUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use of insecure and deprecated function (`mktemp`)")
"Use of insecure and deprecated function (`mktemp`)".to_string()
}
}
@ -301,7 +302,7 @@ pub struct SuspiciousEvalUsage;
impl Violation for SuspiciousEvalUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use of possibly insecure function; consider using `ast.literal_eval`")
"Use of possibly insecure function; consider using `ast.literal_eval`".to_string()
}
}
@ -340,7 +341,7 @@ pub struct SuspiciousMarkSafeUsage;
impl Violation for SuspiciousMarkSafeUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use of `mark_safe` may expose cross-site scripting vulnerabilities")
"Use of `mark_safe` may expose cross-site scripting vulnerabilities".to_string()
}
}
@ -388,7 +389,7 @@ pub struct SuspiciousURLOpenUsage;
impl Violation for SuspiciousURLOpenUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Audit URL open for permitted schemes. Allowing use of `file:` or custom schemes is often unexpected.")
"Audit URL open for permitted schemes. Allowing use of `file:` or custom schemes is often unexpected.".to_string()
}
}
@ -426,7 +427,7 @@ pub struct SuspiciousNonCryptographicRandomUsage;
impl Violation for SuspiciousNonCryptographicRandomUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Standard pseudo-random generators are not suitable for cryptographic purposes")
"Standard pseudo-random generators are not suitable for cryptographic purposes".to_string()
}
}
@ -466,7 +467,7 @@ pub struct SuspiciousXMLCElementTreeUsage;
impl Violation for SuspiciousXMLCElementTreeUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents")
"Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents".to_string()
}
}
@ -506,7 +507,7 @@ pub struct SuspiciousXMLElementTreeUsage;
impl Violation for SuspiciousXMLElementTreeUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents")
"Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents".to_string()
}
}
@ -546,7 +547,7 @@ pub struct SuspiciousXMLExpatReaderUsage;
impl Violation for SuspiciousXMLExpatReaderUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents")
"Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents".to_string()
}
}
@ -586,7 +587,7 @@ pub struct SuspiciousXMLExpatBuilderUsage;
impl Violation for SuspiciousXMLExpatBuilderUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents")
"Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents".to_string()
}
}
@ -626,7 +627,7 @@ pub struct SuspiciousXMLSaxUsage;
impl Violation for SuspiciousXMLSaxUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents")
"Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents".to_string()
}
}
@ -666,7 +667,7 @@ pub struct SuspiciousXMLMiniDOMUsage;
impl Violation for SuspiciousXMLMiniDOMUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents")
"Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents".to_string()
}
}
@ -706,7 +707,7 @@ pub struct SuspiciousXMLPullDOMUsage;
impl Violation for SuspiciousXMLPullDOMUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents")
"Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents".to_string()
}
}
@ -735,7 +736,7 @@ pub struct SuspiciousXMLETreeUsage;
impl Violation for SuspiciousXMLETreeUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Using `lxml` to parse untrusted data is known to be vulnerable to XML attacks")
"Using `lxml` to parse untrusted data is known to be vulnerable to XML attacks".to_string()
}
}
@ -778,7 +779,7 @@ pub struct SuspiciousUnverifiedContextUsage;
impl Violation for SuspiciousUnverifiedContextUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Python allows using an insecure context via the `_create_unverified_context` that reverts to the previous behavior that does not validate certificates or perform hostname checks.")
"Python allows using an insecure context via the `_create_unverified_context` that reverts to the previous behavior that does not validate certificates or perform hostname checks.".to_string()
}
}
@ -799,7 +800,7 @@ pub struct SuspiciousTelnetUsage;
impl Violation for SuspiciousTelnetUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("Telnet-related functions are being called. Telnet is considered insecure. Use SSH or some other encrypted protocol.")
"Telnet-related functions are being called. Telnet is considered insecure. Use SSH or some other encrypted protocol.".to_string()
}
}
@ -820,7 +821,7 @@ pub struct SuspiciousFTPLibUsage;
impl Violation for SuspiciousFTPLibUsage {
#[derive_message_formats]
fn message(&self) -> String {
format!("FTP-related functions are being called. FTP is considered insecure. Use SSH/SFTP/SCP or some other encrypted protocol.")
"FTP-related functions are being called. FTP is considered insecure. Use SSH/SFTP/SCP or some other encrypted protocol.".to_string()
}
}

View file

@ -26,7 +26,7 @@ pub struct SuspiciousTelnetlibImport;
impl Violation for SuspiciousTelnetlibImport {
#[derive_message_formats]
fn message(&self) -> String {
format!("`telnetlib` and related modules are considered insecure. Use SSH or another encrypted protocol.")
"`telnetlib` and related modules are considered insecure. Use SSH or another encrypted protocol.".to_string()
}
}
@ -47,7 +47,7 @@ pub struct SuspiciousFtplibImport;
impl Violation for SuspiciousFtplibImport {
#[derive_message_formats]
fn message(&self) -> String {
format!("`ftplib` and related modules are considered insecure. Use SSH, SFTP, SCP, or another encrypted protocol.")
"`ftplib` and related modules are considered insecure. Use SSH, SFTP, SCP, or another encrypted protocol.".to_string()
}
}
@ -71,7 +71,7 @@ pub struct SuspiciousPickleImport;
impl Violation for SuspiciousPickleImport {
#[derive_message_formats]
fn message(&self) -> String {
format!("`pickle`, `cPickle`, `dill`, and `shelve` modules are possibly insecure")
"`pickle`, `cPickle`, `dill`, and `shelve` modules are possibly insecure".to_string()
}
}
@ -92,7 +92,7 @@ pub struct SuspiciousSubprocessImport;
impl Violation for SuspiciousSubprocessImport {
#[derive_message_formats]
fn message(&self) -> String {
format!("`subprocess` module is possibly insecure")
"`subprocess` module is possibly insecure".to_string()
}
}
@ -115,7 +115,7 @@ pub struct SuspiciousXmlEtreeImport;
impl Violation for SuspiciousXmlEtreeImport {
#[derive_message_formats]
fn message(&self) -> String {
format!("`xml.etree` methods are vulnerable to XML attacks")
"`xml.etree` methods are vulnerable to XML attacks".to_string()
}
}
@ -138,7 +138,7 @@ pub struct SuspiciousXmlSaxImport;
impl Violation for SuspiciousXmlSaxImport {
#[derive_message_formats]
fn message(&self) -> String {
format!("`xml.sax` methods are vulnerable to XML attacks")
"`xml.sax` methods are vulnerable to XML attacks".to_string()
}
}
@ -161,7 +161,7 @@ pub struct SuspiciousXmlExpatImport;
impl Violation for SuspiciousXmlExpatImport {
#[derive_message_formats]
fn message(&self) -> String {
format!("`xml.dom.expatbuilder` is vulnerable to XML attacks")
"`xml.dom.expatbuilder` is vulnerable to XML attacks".to_string()
}
}
@ -184,7 +184,7 @@ pub struct SuspiciousXmlMinidomImport;
impl Violation for SuspiciousXmlMinidomImport {
#[derive_message_formats]
fn message(&self) -> String {
format!("`xml.dom.minidom` is vulnerable to XML attacks")
"`xml.dom.minidom` is vulnerable to XML attacks".to_string()
}
}
@ -207,7 +207,7 @@ pub struct SuspiciousXmlPulldomImport;
impl Violation for SuspiciousXmlPulldomImport {
#[derive_message_formats]
fn message(&self) -> String {
format!("`xml.dom.pulldom` is vulnerable to XML attacks")
"`xml.dom.pulldom` is vulnerable to XML attacks".to_string()
}
}
@ -237,7 +237,7 @@ pub struct SuspiciousLxmlImport;
impl Violation for SuspiciousLxmlImport {
#[derive_message_formats]
fn message(&self) -> String {
format!("`lxml` is vulnerable to XML attacks")
"`lxml` is vulnerable to XML attacks".to_string()
}
}
@ -260,7 +260,7 @@ pub struct SuspiciousXmlrpcImport;
impl Violation for SuspiciousXmlrpcImport {
#[derive_message_formats]
fn message(&self) -> String {
format!("XMLRPC is vulnerable to remote XML attacks")
"XMLRPC is vulnerable to remote XML attacks".to_string()
}
}
@ -286,7 +286,7 @@ pub struct SuspiciousHttpoxyImport;
impl Violation for SuspiciousHttpoxyImport {
#[derive_message_formats]
fn message(&self) -> String {
format!("`httpoxy` is a set of vulnerabilities that affect application code running inCGI, or CGI-like environments. The use of CGI for web applications should be avoided")
"`httpoxy` is a set of vulnerabilities that affect application code running inCGI, or CGI-like environments. The use of CGI for web applications should be avoided".to_string()
}
}
@ -311,9 +311,8 @@ pub struct SuspiciousPycryptoImport;
impl Violation for SuspiciousPycryptoImport {
#[derive_message_formats]
fn message(&self) -> String {
format!(
"`pycrypto` library is known to have publicly disclosed buffer overflow vulnerability"
)
"`pycrypto` library is known to have publicly disclosed buffer overflow vulnerability"
.to_string()
}
}
@ -337,7 +336,8 @@ pub struct SuspiciousPyghmiImport;
impl Violation for SuspiciousPyghmiImport {
#[derive_message_formats]
fn message(&self) -> String {
format!("An IPMI-related module is being imported. Prefer an encrypted protocol over IPMI.")
"An IPMI-related module is being imported. Prefer an encrypted protocol over IPMI."
.to_string()
}
}

View file

@ -43,7 +43,7 @@ pub struct TarfileUnsafeMembers;
impl Violation for TarfileUnsafeMembers {
#[derive_message_formats]
fn message(&self) -> String {
format!("Uses of `tarfile.extractall()`")
"Uses of `tarfile.extractall()`".to_string()
}
}

View file

@ -47,7 +47,7 @@ pub struct TryExceptContinue;
impl Violation for TryExceptContinue {
#[derive_message_formats]
fn message(&self) -> String {
format!("`try`-`except`-`continue` detected, consider logging the exception")
"`try`-`except`-`continue` detected, consider logging the exception".to_string()
}
}

View file

@ -43,7 +43,7 @@ pub struct TryExceptPass;
impl Violation for TryExceptPass {
#[derive_message_formats]
fn message(&self) -> String {
format!("`try`-`except`-`pass` detected, consider logging the exception")
"`try`-`except`-`pass` detected, consider logging the exception".to_string()
}
}

View file

@ -42,18 +42,18 @@ pub struct UnsafeYAMLLoad {
impl Violation for UnsafeYAMLLoad {
#[derive_message_formats]
fn message(&self) -> String {
let UnsafeYAMLLoad { loader } = self;
match loader {
match &self.loader {
Some(name) => {
format!(
"Probable use of unsafe loader `{name}` with `yaml.load`. Allows \
instantiation of arbitrary objects. Consider `yaml.safe_load`."
)
}
None => format!(
None => {
"Probable use of unsafe `yaml.load`. Allows instantiation of arbitrary objects. \
Consider `yaml.safe_load`."
),
.to_string()
}
}
}
}

View file

@ -95,7 +95,7 @@ pub struct BooleanDefaultValuePositionalArgument;
impl Violation for BooleanDefaultValuePositionalArgument {
#[derive_message_formats]
fn message(&self) -> String {
format!("Boolean default positional argument in function definition")
"Boolean default positional argument in function definition".to_string()
}
}

View file

@ -47,7 +47,7 @@ pub struct BooleanPositionalValueInCall;
impl Violation for BooleanPositionalValueInCall {
#[derive_message_formats]
fn message(&self) -> String {
format!("Boolean positional value in function call")
"Boolean positional value in function call".to_string()
}
}

View file

@ -101,7 +101,7 @@ pub struct BooleanTypeHintPositionalArgument;
impl Violation for BooleanTypeHintPositionalArgument {
#[derive_message_formats]
fn message(&self) -> String {
format!("Boolean-typed positional argument in function definition")
"Boolean-typed positional argument in function definition".to_string()
}
}

View file

@ -40,7 +40,8 @@ pub struct AssertFalse;
impl AlwaysFixableViolation for AssertFalse {
#[derive_message_formats]
fn message(&self) -> String {
format!("Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`")
"Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`"
.to_string()
}
fn fix_title(&self) -> String {

View file

@ -45,7 +45,7 @@ pub struct AssignmentToOsEnviron;
impl Violation for AssignmentToOsEnviron {
#[derive_message_formats]
fn message(&self) -> String {
format!("Assigning to `os.environ` doesn't clear the environment")
"Assigning to `os.environ` doesn't clear the environment".to_string()
}
}

View file

@ -68,9 +68,8 @@ pub struct CachedInstanceMethod;
impl Violation for CachedInstanceMethod {
#[derive_message_formats]
fn message(&self) -> String {
format!(
"Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks"
)
"Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks"
.to_string()
}
}

View file

@ -39,7 +39,8 @@ pub struct ExceptWithEmptyTuple;
impl Violation for ExceptWithEmptyTuple {
#[derive_message_formats]
fn message(&self) -> String {
format!("Using `except ():` with an empty tuple does not catch anything; add exceptions to handle")
"Using `except ():` with an empty tuple does not catch anything; add exceptions to handle"
.to_string()
}
}

View file

@ -40,7 +40,8 @@ pub struct ExceptWithNonExceptionClasses;
impl Violation for ExceptWithNonExceptionClasses {
#[derive_message_formats]
fn message(&self) -> String {
format!("`except` handlers should only be exception classes or tuples of exception classes")
"`except` handlers should only be exception classes or tuples of exception classes"
.to_string()
}
}

View file

@ -36,9 +36,7 @@ pub struct FStringDocstring;
impl Violation for FStringDocstring {
#[derive_message_formats]
fn message(&self) -> String {
format!(
"f-string used as docstring. Python will interpret this as a joined string, rather than a docstring."
)
"f-string used as docstring. Python will interpret this as a joined string, rather than a docstring.".to_string()
}
}

View file

@ -72,11 +72,10 @@ pub struct FunctionCallInDefaultArgument {
impl Violation for FunctionCallInDefaultArgument {
#[derive_message_formats]
fn message(&self) -> String {
let FunctionCallInDefaultArgument { name } = self;
if let Some(name) = name {
if let Some(name) = &self.name {
format!("Do not perform function call `{name}` in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable")
} else {
format!("Do not perform function call in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable")
"Do not perform function call in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable".to_string()
}
}
}

View file

@ -37,10 +37,9 @@ pub struct GetAttrWithConstant;
impl AlwaysFixableViolation for GetAttrWithConstant {
#[derive_message_formats]
fn message(&self) -> String {
format!(
"Do not call `getattr` with a constant attribute value. It is not any safer than \
normal property access."
)
"Do not call `getattr` with a constant attribute value. It is not any safer than \
normal property access."
.to_string()
}
fn fix_title(&self) -> String {

View file

@ -44,12 +44,10 @@ pub struct LoopIteratorMutation {
impl Violation for LoopIteratorMutation {
#[derive_message_formats]
fn message(&self) -> String {
let LoopIteratorMutation { name } = self;
if let Some(name) = name.as_ref().and_then(SourceCodeSnippet::full_display) {
if let Some(name) = self.name.as_ref().and_then(SourceCodeSnippet::full_display) {
format!("Mutation to loop iterable `{name}` during iteration")
} else {
format!("Mutation to loop iterable during iteration")
"Mutation to loop iterable during iteration".to_string()
}
}
}

View file

@ -76,7 +76,7 @@ impl Violation for MutableArgumentDefault {
#[derive_message_formats]
fn message(&self) -> String {
format!("Do not use mutable data structures for argument defaults")
"Do not use mutable data structures for argument defaults".to_string()
}
fn fix_title(&self) -> Option<String> {

View file

@ -58,7 +58,7 @@ pub struct MutableContextvarDefault;
impl Violation for MutableContextvarDefault {
#[derive_message_formats]
fn message(&self) -> String {
format!("Do not use mutable data structures for `ContextVar` defaults")
"Do not use mutable data structures for `ContextVar` defaults".to_string()
}
fn fix_title(&self) -> Option<String> {

View file

@ -32,7 +32,7 @@ pub struct NoExplicitStacklevel;
impl Violation for NoExplicitStacklevel {
#[derive_message_formats]
fn message(&self) -> String {
format!("No explicit `stacklevel` keyword argument found")
"No explicit `stacklevel` keyword argument found".to_string()
}
}

View file

@ -32,7 +32,7 @@ pub struct RaiseLiteral;
impl Violation for RaiseLiteral {
#[derive_message_formats]
fn message(&self) -> String {
format!("Cannot raise a literal. Did you intend to return it or raise an Exception?")
"Cannot raise a literal. Did you intend to return it or raise an Exception?".to_string()
}
}

View file

@ -52,10 +52,9 @@ pub struct RaiseWithoutFromInsideExcept;
impl Violation for RaiseWithoutFromInsideExcept {
#[derive_message_formats]
fn message(&self) -> String {
format!(
"Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... \
"Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... \
from None` to distinguish them from errors in exception handling"
)
.to_string()
}
}

View file

@ -43,7 +43,7 @@ pub struct RedundantTupleInExceptionHandler {
impl AlwaysFixableViolation for RedundantTupleInExceptionHandler {
#[derive_message_formats]
fn message(&self) -> String {
format!("A length-one tuple literal is redundant in exception handlers")
"A length-one tuple literal is redundant in exception handlers".to_string()
}
fn fix_title(&self) -> String {

View file

@ -39,7 +39,7 @@ pub struct ReuseOfGroupbyGenerator;
impl Violation for ReuseOfGroupbyGenerator {
#[derive_message_formats]
fn message(&self) -> String {
format!("Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage")
"Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage".to_string()
}
}

View file

@ -36,10 +36,9 @@ pub struct SetAttrWithConstant;
impl AlwaysFixableViolation for SetAttrWithConstant {
#[derive_message_formats]
fn message(&self) -> String {
format!(
"Do not call `setattr` with a constant attribute value. It is not any safer than \
"Do not call `setattr` with a constant attribute value. It is not any safer than \
normal property access."
)
.to_string()
}
fn fix_title(&self) -> String {

View file

@ -51,7 +51,7 @@ pub struct StarArgUnpackingAfterKeywordArg;
impl Violation for StarArgUnpackingAfterKeywordArg {
#[derive_message_formats]
fn message(&self) -> String {
format!("Star-arg unpacking after a keyword argument is strongly discouraged")
"Star-arg unpacking after a keyword argument is strongly discouraged".to_string()
}
}

View file

@ -38,11 +38,10 @@ pub struct StaticKeyDictComprehension {
impl Violation for StaticKeyDictComprehension {
#[derive_message_formats]
fn message(&self) -> String {
let StaticKeyDictComprehension { key } = self;
if let Some(key) = key.full_display() {
if let Some(key) = self.key.full_display() {
format!("Dictionary comprehension uses static key: `{key}`")
} else {
format!("Dictionary comprehension uses static key")
"Dictionary comprehension uses static key".to_string()
}
}
}

View file

@ -50,7 +50,7 @@ pub struct StripWithMultiCharacters;
impl Violation for StripWithMultiCharacters {
#[derive_message_formats]
fn message(&self) -> String {
format!("Using `.strip()` with multi-character strings is misleading")
"Using `.strip()` with multi-character strings is misleading".to_string()
}
}

View file

@ -38,13 +38,12 @@ pub struct UnaryPrefixIncrementDecrement {
impl Violation for UnaryPrefixIncrementDecrement {
#[derive_message_formats]
fn message(&self) -> String {
let UnaryPrefixIncrementDecrement { operator } = self;
match operator {
match self.operator {
UnaryPrefixOperatorType::Increment => {
format!("Python does not support the unary prefix increment operator (`++`)")
"Python does not support the unary prefix increment operator (`++`)".to_string()
}
UnaryPrefixOperatorType::Decrement => {
format!("Python does not support the unary prefix decrement operator (`--`)")
"Python does not support the unary prefix decrement operator (`--`)".to_string()
}
}
}

View file

@ -28,9 +28,8 @@ pub struct UnintentionalTypeAnnotation;
impl Violation for UnintentionalTypeAnnotation {
#[derive_message_formats]
fn message(&self) -> String {
format!(
"Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?"
)
"Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?"
.to_string()
}
}

View file

@ -39,10 +39,9 @@ impl Violation for UnreliableCallableCheck {
#[derive_message_formats]
fn message(&self) -> String {
format!(
"Using `hasattr(x, \"__call__\")` to test if x is callable is unreliable. Use \
"Using `hasattr(x, \"__call__\")` to test if x is callable is unreliable. Use \
`callable(x)` for consistent results."
)
.to_string()
}
fn fix_title(&self) -> Option<String> {

View file

@ -42,14 +42,16 @@ impl Violation for UselessComparison {
#[derive_message_formats]
fn message(&self) -> String {
match self.at {
ComparisonLocationAt::MiddleBody => format!(
ComparisonLocationAt::MiddleBody => {
"Pointless comparison. Did you mean to assign a value? \
Otherwise, prepend `assert` or remove it."
),
ComparisonLocationAt::EndOfFunction => format!(
.to_string()
}
ComparisonLocationAt::EndOfFunction => {
"Pointless comparison at end of function scope. Did you mean \
to return the expression result?"
),
.to_string()
}
}
}
}

View file

@ -42,10 +42,9 @@ pub struct UselessContextlibSuppress;
impl Violation for UselessContextlibSuppress {
#[derive_message_formats]
fn message(&self) -> String {
format!(
"No arguments passed to `contextlib.suppress`. No exceptions will be suppressed and \
therefore this context manager is redundant"
)
"No arguments passed to `contextlib.suppress`. No exceptions will be suppressed and \
therefore this context manager is redundant"
.to_string()
}
}

View file

@ -60,12 +60,11 @@ impl Violation for UselessExpression {
fn message(&self) -> String {
match self.kind {
Kind::Expression => {
format!("Found useless expression. Either assign it to a variable or remove it.")
"Found useless expression. Either assign it to a variable or remove it.".to_string()
}
Kind::Attribute => {
format!(
"Found useless attribute access. Either assign it to a variable or remove it."
)
"Found useless attribute access. Either assign it to a variable or remove it."
.to_string()
}
}
}

View file

@ -43,7 +43,7 @@ pub struct ZipWithoutExplicitStrict;
impl AlwaysFixableViolation for ZipWithoutExplicitStrict {
#[derive_message_formats]
fn message(&self) -> String {
format!("`zip()` without an explicit `strict=` parameter")
"`zip()` without an explicit `strict=` parameter".to_string()
}
fn fix_title(&self) -> String {

View file

@ -145,7 +145,7 @@ pub struct MissingTrailingComma;
impl AlwaysFixableViolation for MissingTrailingComma {
#[derive_message_formats]
fn message(&self) -> String {
format!("Trailing comma missing")
"Trailing comma missing".to_string()
}
fn fix_title(&self) -> String {
@ -190,7 +190,7 @@ pub struct TrailingCommaOnBareTuple;
impl Violation for TrailingCommaOnBareTuple {
#[derive_message_formats]
fn message(&self) -> String {
format!("Trailing comma on bare tuple prohibited")
"Trailing comma on bare tuple prohibited".to_string()
}
}
@ -216,7 +216,7 @@ pub struct ProhibitedTrailingComma;
impl AlwaysFixableViolation for ProhibitedTrailingComma {
#[derive_message_formats]
fn message(&self) -> String {
format!("Trailing comma prohibited")
"Trailing comma prohibited".to_string()
}
fn fix_title(&self) -> String {

View file

@ -76,8 +76,8 @@ impl Violation for UnnecessaryComprehensionInCall {
#[derive_message_formats]
fn message(&self) -> String {
match self.comprehension_kind {
ComprehensionKind::List => format!("Unnecessary list comprehension"),
ComprehensionKind::Set => format!("Unnecessary set comprehension"),
ComprehensionKind::List => "Unnecessary list comprehension".to_string(),
ComprehensionKind::Set => "Unnecessary set comprehension".to_string(),
}
}

View file

@ -40,7 +40,7 @@ impl Violation for UnnecessaryDictComprehensionForIterable {
#[derive_message_formats]
fn message(&self) -> String {
format!("Unnecessary dict comprehension for iterable; use `dict.fromkeys` instead")
"Unnecessary dict comprehension for iterable; use `dict.fromkeys` instead".to_string()
}
fn fix_title(&self) -> Option<String> {

View file

@ -37,7 +37,7 @@ pub struct UnnecessaryGeneratorDict;
impl AlwaysFixableViolation for UnnecessaryGeneratorDict {
#[derive_message_formats]
fn message(&self) -> String {
format!("Unnecessary generator (rewrite as a `dict` comprehension)")
"Unnecessary generator (rewrite as a `dict` comprehension)".to_string()
}
fn fix_title(&self) -> String {

View file

@ -49,9 +49,9 @@ impl AlwaysFixableViolation for UnnecessaryGeneratorList {
#[derive_message_formats]
fn message(&self) -> String {
if self.short_circuit {
format!("Unnecessary generator (rewrite using `list()`)")
"Unnecessary generator (rewrite using `list()`)".to_string()
} else {
format!("Unnecessary generator (rewrite as a `list` comprehension)")
"Unnecessary generator (rewrite as a `list` comprehension)".to_string()
}
}

View file

@ -47,9 +47,9 @@ impl AlwaysFixableViolation for UnnecessaryGeneratorSet {
#[derive_message_formats]
fn message(&self) -> String {
if self.short_circuit {
format!("Unnecessary generator (rewrite using `set()`)")
"Unnecessary generator (rewrite using `set()`)".to_string()
} else {
format!("Unnecessary generator (rewrite as a `set` comprehension)")
"Unnecessary generator (rewrite as a `set` comprehension)".to_string()
}
}

View file

@ -35,7 +35,7 @@ pub struct UnnecessaryListCall;
impl AlwaysFixableViolation for UnnecessaryListCall {
#[derive_message_formats]
fn message(&self) -> String {
format!("Unnecessary `list` call (remove the outer call to `list()`)")
"Unnecessary `list` call (remove the outer call to `list()`)".to_string()
}
fn fix_title(&self) -> String {

View file

@ -35,7 +35,7 @@ pub struct UnnecessaryListComprehensionDict;
impl AlwaysFixableViolation for UnnecessaryListComprehensionDict {
#[derive_message_formats]
fn message(&self) -> String {
format!("Unnecessary `list` comprehension (rewrite as a `dict` comprehension)")
"Unnecessary `list` comprehension (rewrite as a `dict` comprehension)".to_string()
}
fn fix_title(&self) -> String {

View file

@ -34,7 +34,7 @@ pub struct UnnecessaryListComprehensionSet;
impl AlwaysFixableViolation for UnnecessaryListComprehensionSet {
#[derive_message_formats]
fn message(&self) -> String {
format!("Unnecessary `list` comprehension (rewrite as a `set` comprehension)")
"Unnecessary `list` comprehension (rewrite as a `set` comprehension)".to_string()
}
fn fix_title(&self) -> String {

View file

@ -54,31 +54,26 @@ pub struct UnnecessaryLiteralWithinTupleCall {
impl AlwaysFixableViolation for UnnecessaryLiteralWithinTupleCall {
#[derive_message_formats]
fn message(&self) -> String {
let UnnecessaryLiteralWithinTupleCall { literal_kind } = self;
match literal_kind {
match self.literal_kind {
TupleLiteralKind::List => {
format!(
"Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)"
)
"Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)".to_string()
}
TupleLiteralKind::Tuple => {
format!("Unnecessary `tuple` literal passed to `tuple()` (remove the outer call to `tuple()`)")
"Unnecessary `tuple` literal passed to `tuple()` (remove the outer call to `tuple()`)".to_string()
}
TupleLiteralKind::ListComp => {
format!(
"Unnecessary list comprehension passed to `tuple()` (rewrite as a generator)"
)
"Unnecessary list comprehension passed to `tuple()` (rewrite as a generator)".to_string()
}
}
}
fn fix_title(&self) -> String {
let UnnecessaryLiteralWithinTupleCall { literal_kind } = self;
match literal_kind {
TupleLiteralKind::List => "Rewrite as a `tuple` literal".to_string(),
TupleLiteralKind::Tuple => "Remove the outer call to `tuple()`".to_string(),
TupleLiteralKind::ListComp => "Rewrite as a generator".to_string(),
}
let title = match self.literal_kind {
TupleLiteralKind::List => "Rewrite as a `tuple` literal",
TupleLiteralKind::Tuple => "Remove the outer call to `tuple()`",
TupleLiteralKind::ListComp => "Rewrite as a generator",
};
title.to_string()
}
}

View file

@ -19,7 +19,7 @@ pub struct MissingCopyrightNotice;
impl Violation for MissingCopyrightNotice {
#[derive_message_formats]
fn message(&self) -> String {
format!("Missing copyright notice at top of file")
"Missing copyright notice at top of file".to_string()
}
}

View file

@ -50,7 +50,7 @@ pub struct CallDateFromtimestamp;
impl Violation for CallDateFromtimestamp {
#[derive_message_formats]
fn message(&self) -> String {
format!("`datetime.date.fromtimestamp()` used")
"`datetime.date.fromtimestamp()` used".to_string()
}
fn fix_title(&self) -> Option<String> {

View file

@ -49,7 +49,7 @@ pub struct CallDateToday;
impl Violation for CallDateToday {
#[derive_message_formats]
fn message(&self) -> String {
format!("`datetime.date.today()` used")
"`datetime.date.today()` used".to_string()
}
fn fix_title(&self) -> Option<String> {

View file

@ -56,10 +56,10 @@ impl Violation for CallDatetimeFromtimestamp {
let CallDatetimeFromtimestamp(antipattern) = self;
match antipattern {
DatetimeModuleAntipattern::NoTzArgumentPassed => {
format!("`datetime.datetime.fromtimestamp()` called without a `tz` argument")
"`datetime.datetime.fromtimestamp()` called without a `tz` argument".to_string()
}
DatetimeModuleAntipattern::NonePassedToTzArgument => {
format!("`tz=None` passed to `datetime.datetime.fromtimestamp()`")
"`tz=None` passed to `datetime.datetime.fromtimestamp()`".to_string()
}
}
}

View file

@ -54,10 +54,10 @@ impl Violation for CallDatetimeNowWithoutTzinfo {
let CallDatetimeNowWithoutTzinfo(antipattern) = self;
match antipattern {
DatetimeModuleAntipattern::NoTzArgumentPassed => {
format!("`datetime.datetime.now()` called without a `tz` argument")
"`datetime.datetime.now()` called without a `tz` argument".to_string()
}
DatetimeModuleAntipattern::NonePassedToTzArgument => {
format!("`tz=None` passed to `datetime.datetime.now()`")
"`tz=None` passed to `datetime.datetime.now()`".to_string()
}
}
}

View file

@ -58,27 +58,28 @@ impl Violation for CallDatetimeStrptimeWithoutZone {
fn message(&self) -> String {
let CallDatetimeStrptimeWithoutZone(antipattern) = self;
match antipattern {
DatetimeModuleAntipattern::NoTzArgumentPassed => format!(
DatetimeModuleAntipattern::NoTzArgumentPassed => {
"Naive datetime constructed using `datetime.datetime.strptime()` without %z"
),
.to_string()
}
DatetimeModuleAntipattern::NonePassedToTzArgument => {
format!("`datetime.datetime.strptime(...).replace(tz=None)` used")
"`datetime.datetime.strptime(...).replace(tz=None)` used".to_string()
}
}
}
fn fix_title(&self) -> Option<String> {
let CallDatetimeStrptimeWithoutZone(antipattern) = self;
match antipattern {
DatetimeModuleAntipattern::NoTzArgumentPassed => Some(
let title = match antipattern {
DatetimeModuleAntipattern::NoTzArgumentPassed => {
"Call `.replace(tzinfo=<timezone>)` or `.astimezone()` \
to convert to an aware datetime"
.to_string(),
),
DatetimeModuleAntipattern::NonePassedToTzArgument => {
Some("Pass a `datetime.timezone` object to the `tzinfo` parameter".to_string())
}
}
DatetimeModuleAntipattern::NonePassedToTzArgument => {
"Pass a `datetime.timezone` object to the `tzinfo` parameter"
}
};
Some(title.to_string())
}
}

View file

@ -48,7 +48,7 @@ pub struct CallDatetimeToday;
impl Violation for CallDatetimeToday {
#[derive_message_formats]
fn message(&self) -> String {
format!("`datetime.datetime.today()` used")
"`datetime.datetime.today()` used".to_string()
}
fn fix_title(&self) -> Option<String> {

View file

@ -52,7 +52,7 @@ pub struct CallDatetimeUtcfromtimestamp;
impl Violation for CallDatetimeUtcfromtimestamp {
#[derive_message_formats]
fn message(&self) -> String {
format!("`datetime.datetime.utcfromtimestamp()` used")
"`datetime.datetime.utcfromtimestamp()` used".to_string()
}
fn fix_title(&self) -> Option<String> {

View file

@ -51,7 +51,7 @@ pub struct CallDatetimeUtcnow;
impl Violation for CallDatetimeUtcnow {
#[derive_message_formats]
fn message(&self) -> String {
format!("`datetime.datetime.utcnow()` used")
"`datetime.datetime.utcnow()` used".to_string()
}
fn fix_title(&self) -> Option<String> {

View file

@ -50,10 +50,10 @@ impl Violation for CallDatetimeWithoutTzinfo {
let CallDatetimeWithoutTzinfo(antipattern) = self;
match antipattern {
DatetimeModuleAntipattern::NoTzArgumentPassed => {
format!("`datetime.datetime()` called without a `tzinfo` argument")
"`datetime.datetime()` called without a `tzinfo` argument".to_string()
}
DatetimeModuleAntipattern::NonePassedToTzArgument => {
format!("`tzinfo=None` passed to `datetime.datetime()`")
"`tzinfo=None` passed to `datetime.datetime()`".to_string()
}
}
}

View file

@ -43,7 +43,7 @@ pub struct DjangoAllWithModelForm;
impl Violation for DjangoAllWithModelForm {
#[derive_message_formats]
fn message(&self) -> String {
format!("Do not use `__all__` with `ModelForm`, use `fields` instead")
"Do not use `__all__` with `ModelForm`, use `fields` instead".to_string()
}
}

View file

@ -41,7 +41,7 @@ pub struct DjangoExcludeWithModelForm;
impl Violation for DjangoExcludeWithModelForm {
#[derive_message_formats]
fn message(&self) -> String {
format!("Do not use `exclude` with `ModelForm`, use `fields` instead")
"Do not use `exclude` with `ModelForm`, use `fields` instead".to_string()
}
}

View file

@ -39,7 +39,7 @@ pub struct DjangoLocalsInRenderFunction;
impl Violation for DjangoLocalsInRenderFunction {
#[derive_message_formats]
fn message(&self) -> String {
format!("Avoid passing `locals()` as context to a `render` function")
"Avoid passing `locals()` as context to a `render` function".to_string()
}
}

View file

@ -46,7 +46,7 @@ pub struct DjangoModelWithoutDunderStr;
impl Violation for DjangoModelWithoutDunderStr {
#[derive_message_formats]
fn message(&self) -> String {
format!("Model does not define `__str__` method")
"Model does not define `__str__` method".to_string()
}
}

View file

@ -46,7 +46,7 @@ pub struct DjangoNonLeadingReceiverDecorator;
impl Violation for DjangoNonLeadingReceiverDecorator {
#[derive_message_formats]
fn message(&self) -> String {
format!("`@receiver` decorator must be on top of all the other decorators")
"`@receiver` decorator must be on top of all the other decorators".to_string()
}
}

View file

@ -55,7 +55,7 @@ impl Violation for RawStringInException {
#[derive_message_formats]
fn message(&self) -> String {
format!("Exception must not use a string literal, assign to variable first")
"Exception must not use a string literal, assign to variable first".to_string()
}
fn fix_title(&self) -> Option<String> {
@ -110,7 +110,7 @@ impl Violation for FStringInException {
#[derive_message_formats]
fn message(&self) -> String {
format!("Exception must not use an f-string literal, assign to variable first")
"Exception must not use an f-string literal, assign to variable first".to_string()
}
fn fix_title(&self) -> Option<String> {
@ -166,7 +166,7 @@ impl Violation for DotFormatInException {
#[derive_message_formats]
fn message(&self) -> String {
format!("Exception must not use a `.format()` string directly, assign to variable first")
"Exception must not use a `.format()` string directly, assign to variable first".to_string()
}
fn fix_title(&self) -> Option<String> {

View file

@ -35,7 +35,7 @@ pub struct ShebangLeadingWhitespace;
impl AlwaysFixableViolation for ShebangLeadingWhitespace {
#[derive_message_formats]
fn message(&self) -> String {
format!("Avoid whitespace before shebang")
"Avoid whitespace before shebang".to_string()
}
fn fix_title(&self) -> String {

View file

@ -41,7 +41,7 @@ pub struct ShebangMissingExecutableFile;
impl Violation for ShebangMissingExecutableFile {
#[derive_message_formats]
fn message(&self) -> String {
format!("The file is executable but no shebang is present")
"The file is executable but no shebang is present".to_string()
}
}

View file

@ -36,7 +36,7 @@ pub struct ShebangMissingPython;
impl Violation for ShebangMissingPython {
#[derive_message_formats]
fn message(&self) -> String {
format!("Shebang should contain `python`")
"Shebang should contain `python`".to_string()
}
}

View file

@ -46,7 +46,7 @@ pub struct ShebangNotExecutable;
impl Violation for ShebangNotExecutable {
#[derive_message_formats]
fn message(&self) -> String {
format!("Shebang is present but file is not executable")
"Shebang is present but file is not executable".to_string()
}
}

View file

@ -37,7 +37,7 @@ pub struct ShebangNotFirstLine;
impl Violation for ShebangNotFirstLine {
#[derive_message_formats]
fn message(&self) -> String {
format!("Shebang should be at the beginning of the file")
"Shebang should be at the beginning of the file".to_string()
}
}

View file

@ -26,7 +26,7 @@ pub struct LineContainsTodo;
impl Violation for LineContainsTodo {
#[derive_message_formats]
fn message(&self) -> String {
format!("Line contains TODO, consider resolving the issue")
"Line contains TODO, consider resolving the issue".to_string()
}
}
@ -52,7 +52,7 @@ pub struct LineContainsFixme;
impl Violation for LineContainsFixme {
#[derive_message_formats]
fn message(&self) -> String {
format!("Line contains FIXME, consider resolving the issue")
"Line contains FIXME, consider resolving the issue".to_string()
}
}
@ -75,7 +75,7 @@ pub struct LineContainsXxx;
impl Violation for LineContainsXxx {
#[derive_message_formats]
fn message(&self) -> String {
format!("Line contains XXX, consider resolving the issue")
"Line contains XXX, consider resolving the issue".to_string()
}
}
@ -110,7 +110,7 @@ pub struct LineContainsHack;
impl Violation for LineContainsHack {
#[derive_message_formats]
fn message(&self) -> String {
format!("Line contains HACK, consider resolving the issue")
"Line contains HACK, consider resolving the issue".to_string()
}
}

View file

@ -46,7 +46,7 @@ pub struct FStringInGetTextFuncCall;
impl Violation for FStringInGetTextFuncCall {
#[derive_message_formats]
fn message(&self) -> String {
format!("f-string is resolved before function call; consider `_(\"string %s\") % arg`")
"f-string is resolved before function call; consider `_(\"string %s\") % arg`".to_string()
}
}

View file

@ -46,7 +46,7 @@ pub struct FormatInGetTextFuncCall;
impl Violation for FormatInGetTextFuncCall {
#[derive_message_formats]
fn message(&self) -> String {
format!("`format` method argument is resolved before function call; consider `_(\"string %s\") % arg`")
"`format` method argument is resolved before function call; consider `_(\"string %s\") % arg`".to_string()
}
}

View file

@ -45,7 +45,8 @@ pub struct PrintfInGetTextFuncCall;
impl Violation for PrintfInGetTextFuncCall {
#[derive_message_formats]
fn message(&self) -> String {
format!("printf-style format is resolved before function call; consider `_(\"string %s\") % arg`")
"printf-style format is resolved before function call; consider `_(\"string %s\") % arg`"
.to_string()
}
}

View file

@ -37,7 +37,7 @@ pub struct ExplicitStringConcatenation;
impl Violation for ExplicitStringConcatenation {
#[derive_message_formats]
fn message(&self) -> String {
format!("Explicitly concatenated string should be implicitly concatenated")
"Explicitly concatenated string should be implicitly concatenated".to_string()
}
}

Some files were not shown because too many files have changed in this diff Show more