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

tools.vet: add notice for empty strings conditions #21421

Merged
merged 5 commits into from May 19, 2024

Conversation

ttytm
Copy link
Member

@ttytm ttytm commented May 4, 2024

After getting a response from Alex that it's fine to add the suggestion made in #21300 this should be the frist extension after #21417.

fn main() {
	foo := 'foo'
	foo.len == 0
	foo.len != 0
	foo.len < 1
	foo.len > 0
}

will result in:

cmd/tools/vvet/tests/empty_string.vv:3: notice: Use `foo == ''` instead of `foo.len == 0`
cmd/tools/vvet/tests/empty_string.vv:4: notice: Use `foo != ''` instead of `foo.len != 0`
cmd/tools/vvet/tests/empty_string.vv:5: notice: Use `foo == ''` instead of `foo.len < 1`
cmd/tools/vvet/tests/empty_string.vv:6: notice: Use `foo != ''` instead of `foo.len > 0`

To keep this as a ref.: as mentioned here(#21523 (comment)), adding this check for globally scoped symbols is still a TODO.

@ttytm ttytm force-pushed the tools/vet/empty-string-cond-notice branch 2 times, most recently from 64ef421 to c705dd8 Compare May 4, 2024 21:32
@ttytm ttytm marked this pull request as ready for review May 4, 2024 21:33
@ttytm ttytm marked this pull request as draft May 5, 2024 14:02
@ttytm ttytm force-pushed the tools/vet/empty-string-cond-notice branch 2 times, most recently from 1d1a4d0 to 0bad041 Compare May 7, 2024 10:01
@ttytm ttytm marked this pull request as ready for review May 7, 2024 10:02
@spytheman
Copy link
Member

The Vinix failure is not related, and already fixed on master.

cmd/tools/vvet/vvet.v Outdated Show resolved Hide resolved
@ttytm ttytm marked this pull request as draft May 7, 2024 11:03
@ttytm ttytm force-pushed the tools/vet/empty-string-cond-notice branch 2 times, most recently from 35ca147 to 08f7335 Compare May 19, 2024 10:58
@ttytm ttytm marked this pull request as ready for review May 19, 2024 11:22
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit f56b2b6 into vlang:master May 19, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants