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

Core skeleton #1

Merged
merged 34 commits into from Apr 12, 2019
Merged

Core skeleton #1

merged 34 commits into from Apr 12, 2019

Conversation

mingzhi
Copy link
Contributor

@mingzhi mingzhi commented Apr 3, 2019

This pull request contains the core functionalities of creating and registering a lint rule. Two rule examples are included; however, tests are needed for both rules. The next step will be to add more rules.

@mingzhi mingzhi requested review from jgeewax and robcapo April 3, 2019 19:19
Copy link
Collaborator

@robcapo robcapo left a comment

Choose a reason for hiding this comment

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

I think I need to go through the implementation of the visitor pattern with you, because I'm having trouble following the sequence of calls. Let's discuss it on Monday.

lint/context.go Outdated
}

// DescriptorSource returns a `DescriptorSource` if available; otherwise,
// returns (nil, ErrSourceInfoNotAvailable).
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this comment is out of date.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you update it? Thanks!

lint/lint.go Outdated Show resolved Hide resolved
lint/context.go Outdated

// Context provides additional information for a rule to perform linting.
type Context struct {
context context.Context
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this here? I don't see it being used anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed offline, this should be removed.


type linter struct {
reader io.Reader
writer io.Writer
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like this is never used, but instead the problems are printed via log.Printf. Is this intentional? And if so, let's get rid of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you rewrite this protoc plugin using this helper function? Thanks!

lint/location.go Outdated Show resolved Hide resolved
lint/run_test.go Show resolved Hide resolved
lint/source.go Show resolved Hide resolved
lint/source.go Outdated Show resolved Hide resolved
lint/source.go Outdated Show resolved Hide resolved
problems []lint.Problem
}

func (c *checkers) Lint(rule lint.Rule, req lint.Request) (lint.Response, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rule isn't used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, the rule should be set: c.rule = rule, and we need tests to catch it.

}

// MessageVisitor defines how to travel in a message.
type MessageVisitor interface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The purpose of this interface is still not really clear to me.


// MessageVisiting defines a collection of functions that can be applied to a message and
// its elements.
type MessageVisiting interface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This still looks like a Visitor. That is, it's performing some operation on the underlying struct hierarchy. I think calling it Visiting might be confusing.

lint/request.go Outdated
// ProtoFile returns a `FileDescriptor` when the rule's `FileTypes`
// contains `ProtoFile`.
ProtoFile() protoreflect.FileDescriptor
Context() Context
Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed in person, can we remove the Context struct, as well as the context.Context member, and move the DescriptorSource to this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, please. Thanks!

lint/request.go Outdated Show resolved Hide resolved
lint/request.go Outdated
type Request interface {
// ProtoFile returns a `FileDescriptor` when the rule's `FileTypes`
// contains `ProtoFile`.
ProtoFile() protoreflect.FileDescriptor
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we considering cases where a rule might need visibility into multiple files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean the proto files that it depends, which can be accessed from FileDescriptor.Imports()? Or other types of files, which should have their own getter, like OnePlatformConfigFile()?

lint/context.go Outdated
import "context"

// Context provides additional information for a rule to perform linting.
type Context struct {
Copy link
Collaborator

@robcapo robcapo Apr 11, 2019

Choose a reason for hiding this comment

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

@mingzhi because of the fact that the Request struct is passed to the rules, I think Context is superfluous. Any additional "context" that we want can go directly in the Request struct, grouped into more cohesive structs if it makes sense. In other words, I think our Request struct is equivalent to ESLint's context object.

@robcapo robcapo merged commit 36f7bc6 into master Apr 12, 2019
@mingzhi mingzhi deleted the core-skeleton branch April 16, 2019 22:55
mingzhi pushed a commit that referenced this pull request Feb 13, 2020
* Add =disabled to 0203/immutable.md instructions

* Add =disabled to 0203/input-only.md instructions

* Add =disabled to 0203/optional-conflict.md

* Add =disabled to 0203/optional-consistency.md instructions

* Add =disabled to 0203/optional.md instructions

* Add =disabled to 0203/output-only.md instructions
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