Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time.Date versus people miusing octual notation #1581

Open
ccoVeille opened this issue Aug 3, 2024 · 0 comments
Open

time.Date versus people miusing octual notation #1581

ccoVeille opened this issue Aug 3, 2024 · 0 comments

Comments

@ccoVeille
Copy link

ccoVeille commented Aug 3, 2024

I'm often facing the following pattern when using gofumpt

People are using time.Date with leading 0 for days, months, hours, minutes, or seconds …

here is an example

        now := time.Date(2001, 02, 03, 04, 05, 06, 07, time.UTC)

A leading 0 is one of the octal notation

So gofumpt suggests fixing it to use the 0o literal octal notation

So it transforms this piece of code into

        now := time.Date(2001, 0o2, 0o3, 0o4, 0o5, 0o6, 0o7, time.UTC)

This pattern is very frequent.

https://github.com/search?q=+%22time.Date%2820%22+language%3Ago+%22%2C+02%2C+%22++&type=code&p=1

People should use

        now := time.Date(2001, 2, 3, 4, 5, 6, 7, time.UTC)

For records, I found examples of code where I'm sure gofumpt suggestions were applied, and where time.Date is now using the octal notation

https://github.com/search?q=+%22time.Date%2820%22+language%3Ago+%22%2C+0o1%2C+%22++&type=code

https://github.com/search?q=+%22time.Date%2820%22+language%3Ago+%22%2C+0o2%2C+%22++&type=code

https://github.com/search?q=+%22time.Date%2820%22+language%3Ago+%22%2C+0o4%2C+%22++&type=code

So the checker that could be written should look for 00-07 and 0o0-0o7

This would be very similar to https://staticcheck.dev/docs/checks/#SA9002, just in the opposite direction.

Originally posted by @dominikh in mvdan/gofumpt#309 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants