Skip to content

Conversation

@orsinium
Copy link
Contributor

This is a copy of #94 that doesn't depend on (but conflicts with) #93

Copy link
Collaborator

@cristaloleg cristaloleg left a comment

Choose a reason for hiding this comment

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

sgtm

// The special case is zero. Zero does nothing, so it's a bug, so we replace it too.
// Everything else is for consistency.
m.Match(`strings.Replace($s, $d, $w, $n)`).
Where(m["n"].Const && m["n"].Text.Matches(`(\-[0-9]+|0)`)).
Copy link
Owner

@quasilyte quasilyte Oct 30, 2020

Choose a reason for hiding this comment

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

It looks like if we had a way to const-fold expressions into int we could just check it like:

m["n"].ConstValue.Int() <= 0

It's not hard to implement, actually.
What do you think?

Copy link
Owner

Choose a reason for hiding this comment

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

- Where(m["n"].Const && m["n"].Text.Matches(`(\-[0-9]+|0)`))
+ Where(m["n"].Value.Int() <= 0)

@quasilyte
Copy link
Owner

I like the idea of testing with local rules.go file.
I would probably look for a small-sized real-world Go project that can be vendored into testdata and used as a linting target for these rules. We might build a good benchmarking on top of it (#105).

quasilyte added a commit that referenced this pull request Oct 31, 2020
Added Value expression field that can be used to check the submatch value.
Since `go/types` has some const-folding out-of-the-box, we get it too.

Right now only `int` value types are supported, but we could extend the
set of types later.

This is a proof-of-concept that can be useful in #96.

Signed-off-by: Iskander Sharipov <[email protected]>
quasilyte added a commit that referenced this pull request Oct 31, 2020
Added Value expression field that can be used to check the submatch value.
Since `go/types` has some const-folding out-of-the-box, we get it too.

Right now only `int` value types are supported, but we could extend the
set of types later.

This is a proof-of-concept that can be useful in #96.

Signed-off-by: Iskander Sharipov <[email protected]>
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.

3 participants