v icon indicating copy to clipboard operation
v copied to clipboard

tools.vet: add notice for empty strings conditions

Open ttytm opened this issue 1 year ago • 1 comments

After getting a response from Alex that it's fine to add the suggestion made in https://github.com/vlang/v/pull/21300 this should be the frist extension after #21417.

~~Currently, it includes the PR. It is planned to rebase it after it is resolved, this will reduce the diff greatly and to relevant changes.~~ Rebased.

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`

ttytm avatar May 04 '24 15:05 ttytm

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

spytheman avatar May 07 '24 10:05 spytheman