Skip to content

Commit

Permalink
Derive message formats macro support to string (#14093)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrugman authored Nov 4, 2024
1 parent bc0586d commit fb94b71
Show file tree
Hide file tree
Showing 382 changed files with 842 additions and 853 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 7 additions & 9 deletions crates/ruff_linter/src/rules/flake8_2020/rules/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/ruff_linter/src/rules/flake8_2020/rules/subscript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
28 changes: 12 additions & 16 deletions crates/ruff_linter/src/rules/flake8_bandit/rules/shell_injection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
}
Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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()
}
}
}
Expand Down Expand Up @@ -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(),
}
}
}
Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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()
}
}

Expand Down
Loading

0 comments on commit fb94b71

Please sign in to comment.