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

ruleguard,analyzer: implement rules debugging #104

Merged
merged 1 commit into from
Oct 30, 2020

Conversation

quasilyte
Copy link
Owner

@quasilyte quasilyte commented Oct 30, 2020

When ruleguard is called with -debug-group= arg,
it'll print rejected matches explanations to the stderr
for the specified rules group.

By default, this argument is an empty string that means "no debug".

Explanation includes:

* Submatch nodes (with types)
* Rejection reason (sometimes approx)
* Rejected node location

Here is an example of how explanations can look like:

example.go:4: rejected by rules.go:6 ($s type filter)
  $s [10]int: a

example2.go:9: rejected by rules.go:8 ($s2 is const)
  $s1 string: v1
  $s2 string: ""

example2.go:7: rejected by rules.go:8 ($s1 is not const)
  $s1 string: v1
  $s2 string: v2

The debug output format is experimental and can change over time.
Any feedback is appreciated.

This change also adds Line:int and Group:string fields to the rules info.

Line is a rules file line that declared this rule
Group is a containing function name

The debug output format is experimental and can change over time.
Any feedback is appreciated.

Refs #98

Signed-off-by: Iskander Sharipov quasilyte@gmail.com

@quasilyte quasilyte force-pushed the quasilyte/feature/add_debugging_mode branch 3 times, most recently from acf031a to be591d4 Compare October 30, 2020 04:38
When ruleguard is called with -debug-group=<string> arg,
it'll print rejected matches explanations to the stderr
for the specified rules group.

By default, this argument is an empty string that means "no debug".

Explanation includes:

	* Submatch nodes (with types)
	* Rejection reason (sometimes approx)
	* Rejected node location

Here is an example of how explanations can look like:

	example.go:4: rejected by rules.go:6 ($s type filter)
	  $s [10]int: a

	example2.go:9: rejected rules2.go:8 ($s2 is const)
	  $s1 string: v1
	  $s2 string: ""

	example2.go:7: rejected rules2.go:8 ($s1 is not const)
	  $s1 string: v1
	  $s2 string: v2

The debug output format is experimental and can change over time.
Any feedback is appreciated.

This change also adds Line:int and Group:string fields to the rules info.

	Line is a rules file line that declared this rule
	Group is a containing function name

Refs #98

Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
@quasilyte quasilyte force-pushed the quasilyte/feature/add_debugging_mode branch from be591d4 to 6d996d5 Compare October 30, 2020 04:41
@quasilyte quasilyte merged commit 408e967 into master Oct 30, 2020
@quasilyte quasilyte deleted the quasilyte/feature/add_debugging_mode branch October 30, 2020 09:33
quasilyte added a commit to go-critic/go-critic that referenced this pull request Oct 30, 2020
See quasilyte/go-ruleguard#104 for more
detailed explanation of what "rules debugging" means.

The ruleguard dependency was updated.

When golangci-lint will be updated, it should be possible
to debug rules from it as well (albeit it's less convenient).

Here is a minimal example:

	linters:
	  enable:
	    - gocritic
	linters-settings:
	  gocritic:
	    enabled-checks:
	      - ruleguard
	    settings:
	      ruleguard:
	        rules: "rules.go"
	        debug: <name>

Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
quasilyte added a commit to go-critic/go-critic that referenced this pull request Nov 7, 2020
See quasilyte/go-ruleguard#104 for more
detailed explanation of what "rules debugging" means.

The ruleguard dependency was updated.

When golangci-lint will be updated, it should be possible
to debug rules from it as well (albeit it's less convenient).

Here is a minimal example:

	linters:
	  enable:
	    - gocritic
	linters-settings:
	  gocritic:
	    enabled-checks:
	      - ruleguard
	    settings:
	      ruleguard:
	        rules: "rules.go"
	        debug: <name>

Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
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.

2 participants