Skip to content

Commit

Permalink
Don't suggest invalid syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Mar 27, 2024
1 parent 7beb878 commit 5f5f523
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::checkers::ast::Checker;
/// always use timezone-aware objects.
///
/// `datetime.date.fromtimestamp(ts)` returns a naive datetime object.
/// Instead, use `datetime.datetime.fromtimestamp(ts, tz=)` to return a
/// Instead, use `datetime.datetime.fromtimestamp(ts, tz=...)` to return a
/// timezone-aware object.
///
/// ## Example
Expand Down Expand Up @@ -54,7 +54,7 @@ impl Violation for CallDateFromtimestamp {
}

fn fix_title(&self) -> Option<String> {
Some("Use `datetime.datetime.fromtimestamp(ts, tz=).date()` instead".to_string())
Some("Use `datetime.datetime.fromtimestamp(ts, tz=...).date()` instead".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::checkers::ast::Checker;
/// always use timezone-aware objects.
///
/// `datetime.date.today` returns a naive datetime object. Instead, use
/// `datetime.datetime.now(tz=).date()` to return a timezone-aware object.
/// `datetime.datetime.now(tz=...).date()` to return a timezone-aware object.
///
/// ## Example
/// ```python
Expand Down Expand Up @@ -53,7 +53,7 @@ impl Violation for CallDateToday {
}

fn fix_title(&self) -> Option<String> {
Some("Use `datetime.datetime.now(tz=).date()` instead".to_string())
Some("Use `datetime.datetime.now(tz=...).date()` instead".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use super::helpers::{self, DatetimeModuleAntipattern};
///
/// `datetime.datetime.fromtimestamp(ts)` or
/// `datetime.datetime.fromtimestampe(ts, tz=None)` returns a naive datetime
/// object. Instead, use `datetime.datetime.fromtimestamp(ts, tz=)` to return a
/// object. Instead, use `datetime.datetime.fromtimestamp(ts, tz=...)` to return a
/// timezone-aware object.
///
/// ## Example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::helpers::{self, DatetimeModuleAntipattern};
/// always use timezone-aware objects.
///
/// `datetime.datetime.now()` or `datetime.datetime.now(tz=None)` returns a naive
/// datetime object. Instead, use `datetime.datetime.now(tz=)` to return a
/// datetime object. Instead, use `datetime.datetime.now(tz=<timezone>)` to return a
/// timezone-aware object.
///
/// ## Example
Expand Down Expand Up @@ -54,7 +54,7 @@ impl Violation for CallDatetimeNowWithoutTzinfo {
let CallDatetimeNowWithoutTzinfo(antipattern) = self;
match antipattern {
DatetimeModuleAntipattern::NoTzArgumentPassed => {
format!("`datetime.datetime.now()` called without a `tz=` argument")
format!("`datetime.datetime.now()` called without a `tz` argument")
}
DatetimeModuleAntipattern::NonePassedToTzArgument => {
format!("`tz=None` passed to `datetime.datetime.now()`")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::helpers::DatetimeModuleAntipattern;
/// always use timezone-aware objects.
///
/// `datetime.datetime.strptime()` without `%z` returns a naive datetime
/// object. Follow it with `.replace(tzinfo=)` or `.astimezone()`.
/// object. Follow it with `.replace(tzinfo=<timezone>)` or `.astimezone()`.
///
/// ## Example
/// ```python
Expand All @@ -28,7 +28,7 @@ use super::helpers::DatetimeModuleAntipattern;
/// datetime.datetime.strptime("2022/01/31", "%Y/%m/%d")
/// ```
///
/// Instead, use `.replace(tzinfo=)`:
/// Instead, use `.replace(tzinfo=<timezone>)`:
/// ```python
/// import datetime
///
Expand Down Expand Up @@ -71,11 +71,12 @@ impl Violation for CallDatetimeStrptimeWithoutZone {
let CallDatetimeStrptimeWithoutZone(antipattern) = self;
match antipattern {
DatetimeModuleAntipattern::NoTzArgumentPassed => Some(
"Call `.replace(tzinfo=)` or `.astimezone()` to convert to an aware datetime"
"Call `.replace(tzinfo=<timezone>)` or `.astimezone()` \
to convert to an aware datetime"
.to_string(),
),
DatetimeModuleAntipattern::NonePassedToTzArgument => {
Some("Pass a `datetime.timezone` object to `tzinfo=`".to_string())
Some("Pass a `datetime.timezone` object to `tzinfo`".to_string())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use super::helpers;
/// time, unlike "naive" objects.
///
/// `datetime.datetime.today()` creates a "naive" object; instead, use
/// `datetime.datetime.now(tz=)` to create a timezone-aware object.
/// `datetime.datetime.now(tz=...)` to create a timezone-aware object.
///
/// ## Example
/// ```python
Expand Down Expand Up @@ -52,7 +52,7 @@ impl Violation for CallDatetimeToday {
}

fn fix_title(&self) -> Option<String> {
Some("Use `datetime.datetime.now(tz=)` instead".to_string())
Some("Use `datetime.datetime.now(tz=...)` instead".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ use super::helpers;
/// datetime objects. Since this can lead to errors, it is recommended to
/// always use timezone-aware objects.
///
/// `datetime.datetime.utcfromtimestamp()` or
/// `datetime.datetime.utcfromtimestamp(tz=None)` returns a naive datetime
/// object; instead, use `datetime.datetime.fromtimestamp(ts, tz=)` to return a
/// timezone-aware object.
/// `datetime.datetime.utcfromtimestamp()` returns a naive datetime
/// object; instead, use `datetime.datetime.fromtimestamp(ts, tz=...)`
/// to return a timezone-aware object.
///
/// ## Example
/// ```python
Expand Down Expand Up @@ -57,7 +56,7 @@ impl Violation for CallDatetimeUtcfromtimestamp {
}

fn fix_title(&self) -> Option<String> {
Some("Use `datetime.datetime.fromtimestamp(ts, tz=)` instead".to_string())
Some("Use `datetime.datetime.fromtimestamp(ts, tz=...)` instead".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use super::helpers;
/// always use timezone-aware objects.
///
/// `datetime.datetime.utcnow()` returns a naive datetime object; instead, use
/// `datetime.datetime.now(tz=)` to return a timezone-aware object.
/// `datetime.datetime.now(tz=...)` to return a timezone-aware object.
///
/// ## Example
/// ```python
Expand Down Expand Up @@ -55,7 +55,7 @@ impl Violation for CallDatetimeUtcnow {
}

fn fix_title(&self) -> Option<String> {
Some("Use `datetime.datetime.now(tz=)` instead".to_string())
Some("Use `datetime.datetime.now(tz=...)` instead".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DTZ002.py:4:1: DTZ002 `datetime.datetime.today()` used
5 |
6 | from datetime import datetime
|
= help: Use `datetime.datetime.now(tz=)` instead
= help: Use `datetime.datetime.now(tz=...)` instead

DTZ002.py:9:1: DTZ002 `datetime.datetime.today()` used
|
Expand All @@ -19,4 +19,4 @@ DTZ002.py:9:1: DTZ002 `datetime.datetime.today()` used
10 |
11 | # uses `astimezone` method
|
= help: Use `datetime.datetime.now(tz=)` instead
= help: Use `datetime.datetime.now(tz=...)` instead
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DTZ003.py:4:1: DTZ003 `datetime.datetime.utcnow()` used
5 |
6 | from datetime import datetime
|
= help: Use `datetime.datetime.now(tz=)` instead
= help: Use `datetime.datetime.now(tz=...)` instead

DTZ003.py:9:1: DTZ003 `datetime.datetime.utcnow()` used
|
Expand All @@ -19,4 +19,4 @@ DTZ003.py:9:1: DTZ003 `datetime.datetime.utcnow()` used
10 |
11 | # uses `astimezone` method
|
= help: Use `datetime.datetime.now(tz=)` instead
= help: Use `datetime.datetime.now(tz=...)` instead
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DTZ004.py:4:1: DTZ004 `datetime.datetime.utcfromtimestamp()` used
5 |
6 | from datetime import datetime
|
= help: Use `datetime.datetime.fromtimestamp(ts, tz=)` instead
= help: Use `datetime.datetime.fromtimestamp(ts, tz=...)` instead

DTZ004.py:9:1: DTZ004 `datetime.datetime.utcfromtimestamp()` used
|
Expand All @@ -19,4 +19,4 @@ DTZ004.py:9:1: DTZ004 `datetime.datetime.utcfromtimestamp()` used
10 |
11 | # uses `astimezone` method
|
= help: Use `datetime.datetime.fromtimestamp(ts, tz=)` instead
= help: Use `datetime.datetime.fromtimestamp(ts, tz=...)` instead
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_datetimez/mod.rs
---
DTZ005.py:4:1: DTZ005 `datetime.datetime.now()` called without a `tz=` argument
DTZ005.py:4:1: DTZ005 `datetime.datetime.now()` called without a `tz` argument
|
3 | # no args
4 | datetime.datetime.now()
Expand All @@ -11,7 +11,7 @@ DTZ005.py:4:1: DTZ005 `datetime.datetime.now()` called without a `tz=` argument
|
= help: Pass a `datetime.timezone` object to the `tz` parameter

DTZ005.py:7:1: DTZ005 `datetime.datetime.now()` called without a `tz=` argument
DTZ005.py:7:1: DTZ005 `datetime.datetime.now()` called without a `tz` argument
|
6 | # wrong keywords
7 | datetime.datetime.now(bad=datetime.timezone.utc)
Expand Down Expand Up @@ -41,7 +41,7 @@ DTZ005.py:13:1: DTZ005 `tz=None` passed to `datetime.datetime.now()`
|
= help: Pass a `datetime.timezone` object to the `tz` parameter

DTZ005.py:18:1: DTZ005 `datetime.datetime.now()` called without a `tz=` argument
DTZ005.py:18:1: DTZ005 `datetime.datetime.now()` called without a `tz` argument
|
17 | # no args unqualified
18 | datetime.now()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DTZ007.py:4:1: DTZ007 Naive datetime constructed using `datetime.datetime.strpti
5 |
6 | # no replace or astimezone
|
= help: Call `.replace(tzinfo=)` or `.astimezone()` to convert to an aware datetime
= help: Call `.replace(tzinfo=<timezone>)` or `.astimezone()` to convert to an aware datetime
DTZ007.py:7:1: DTZ007 Naive datetime constructed using `datetime.datetime.strptime()` without %z
|
Expand All @@ -19,7 +19,7 @@ DTZ007.py:7:1: DTZ007 Naive datetime constructed using `datetime.datetime.strpti
8 |
9 | # wrong replace
|
= help: Call `.replace(tzinfo=)` or `.astimezone()` to convert to an aware datetime
= help: Call `.replace(tzinfo=<timezone>)` or `.astimezone()` to convert to an aware datetime
DTZ007.py:10:1: DTZ007 Naive datetime constructed using `datetime.datetime.strptime()` without %z
|
Expand All @@ -29,7 +29,7 @@ DTZ007.py:10:1: DTZ007 Naive datetime constructed using `datetime.datetime.strpt
11 |
12 | # none replace
|
= help: Call `.replace(tzinfo=)` or `.astimezone()` to convert to an aware datetime
= help: Call `.replace(tzinfo=<timezone>)` or `.astimezone()` to convert to an aware datetime
DTZ007.py:13:1: DTZ007 `datetime.datetime.strptime(...).replace(tz=None)` used
|
Expand All @@ -39,12 +39,12 @@ DTZ007.py:13:1: DTZ007 `datetime.datetime.strptime(...).replace(tz=None)` used
14 |
15 | # OK
|
= help: Pass a `datetime.timezone` object to `tzinfo=`
= help: Pass a `datetime.timezone` object to `tzinfo`
DTZ007.py:35:1: DTZ007 Naive datetime constructed using `datetime.datetime.strptime()` without %z
|
34 | # no replace orastimezone unqualified
35 | datetime.strptime("something", "something")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ007
|
= help: Call `.replace(tzinfo=)` or `.astimezone()` to convert to an aware datetime
= help: Call `.replace(tzinfo=<timezone>)` or `.astimezone()` to convert to an aware datetime
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ DTZ011.py:4:1: DTZ011 `datetime.date.today()` used
5 |
6 | from datetime import date
|
= help: Use `datetime.datetime.now(tz=).date()` instead
= help: Use `datetime.datetime.now(tz=...).date()` instead

DTZ011.py:9:1: DTZ011 `datetime.date.today()` used
|
8 | # unqualified
9 | date.today()
| ^^^^^^^^^^^^ DTZ011
|
= help: Use `datetime.datetime.now(tz=).date()` instead
= help: Use `datetime.datetime.now(tz=...).date()` instead
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ DTZ012.py:4:1: DTZ012 `datetime.date.fromtimestamp()` used
5 |
6 | from datetime import date
|
= help: Use `datetime.datetime.fromtimestamp(ts, tz=).date()` instead
= help: Use `datetime.datetime.fromtimestamp(ts, tz=...).date()` instead

DTZ012.py:9:1: DTZ012 `datetime.date.fromtimestamp()` used
|
8 | # unqualified
9 | date.fromtimestamp(1234)
| ^^^^^^^^^^^^^^^^^^^^^^^^ DTZ012
|
= help: Use `datetime.datetime.fromtimestamp(ts, tz=).date()` instead
= help: Use `datetime.datetime.fromtimestamp(ts, tz=...).date()` instead

0 comments on commit 5f5f523

Please sign in to comment.