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

Protolint doesn't work with -plugin in windows #144

Open
rost5000 opened this issue Jan 15, 2021 · 2 comments
Open

Protolint doesn't work with -plugin in windows #144

rost5000 opened this issue Jan 15, 2021 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@rost5000
Copy link

rost5000 commented Jan 15, 2021

I have a following proto file:

syntax = "proto3";
// A broken example of the official reference
// See https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#proto_file
package examplePb;

option java_package = "com.example.foo";

import "other.proto";
import public "new.proto";

import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";

import "myproject/other_protos.proto";
import "myproject/main_protos.proto";

enum enumAllowingAlias {
  option allow_alias = true;
  UNKNOWN = 0;
  STARTED = 1;
  RUNNING = 2 [(custom_option) = "hello world"];
}
message outer {
  option (my_option).a = true;
  // inner is an inner message.
  message innerAAA {   // Level 2
    int64 ival = 1;
  }
  repeated inner inner_message = 2;
  EnumAllowingAlias enum_field =3;
  map<int32, string> my_map = 4;
  string reason_for_error = 5;
  string  end_of_support_version= 6;
  message AccountForAdmin {}
  message SpecialEndOfSupport {}
  required inner inner_message = 7;
  group Result = 8 {
    string url = 9;
  }
  repeated group Result = 10 {
  }
  repeated inner paper = 11;
  repeated group Regular = 12 {
  }
}
service SearchApi {
  rpc search (SearchRequest) returns (SearchResponse) {};
};

So I create a custom linter rule custumrule/enumrule.go:

package custumrule

import (
	"github.com/yoheimuta/go-protoparser/v4/parser"
	"github.com/yoheimuta/protolint/linter/report"
	"github.com/yoheimuta/protolint/linter/strs"
	"github.com/yoheimuta/protolint/linter/visitor"
)

// EnumNamesLowerSnakeCaseRule verifies that all enum names are LowerSnakeCase.
type EnumNamesLowerSnakeCaseRule struct{}

// NewEnumNamesLowerSnakeCaseRule creates a new EnumNamesLowerSnakeCaseRule.
func NewEnumNamesLowerSnakeCaseRule() EnumNamesLowerSnakeCaseRule {
	return EnumNamesLowerSnakeCaseRule{}
}

// ID returns the ID of this rule.
func (r EnumNamesLowerSnakeCaseRule) ID() string {
	return "ENUM_NAMES_LOWER_SNAKE_CASE"
}

// Purpose returns the purpose of this rule.
func (r EnumNamesLowerSnakeCaseRule) Purpose() string {
	return "Verifies that all enum names are LowerSnakeCase."
}

// IsOfficial decides whether or not this rule belongs to the official guide.
func (r EnumNamesLowerSnakeCaseRule) IsOfficial() bool {
	return true
}

// Apply applies the rule to the proto.
func (r EnumNamesLowerSnakeCaseRule) Apply(proto *parser.Proto) ([]report.Failure, error) {
	v := &enumNamesLowerSnakeCaseVisitor{
		BaseAddVisitor: visitor.NewBaseAddVisitor(r.ID()),
	}
	return visitor.RunVisitor(v, proto, r.ID())
}

type enumNamesLowerSnakeCaseVisitor struct {
	*visitor.BaseAddVisitor
}

// VisitEnum checks the enum field.
func (v *enumNamesLowerSnakeCaseVisitor) VisitEnum(e *parser.Enum) bool {
	if !strs.IsLowerSnakeCase(e.EnumName) {
		v.AddFailuref(e.Meta.Pos, "Enum name %q must be underscore_separated_names", e.EnumName)
	}
	return false
}

and main.go:

package main

import (
	"example.com/m/custumrule"
	"github.com/yoheimuta/protolint/plugin"
)

func main() {
	plugin.RegisterCustomRules(
		custumrule.NewEnumNamesLowerSnakeCaseRule(),
	)
}

I build project on windows and Linux subsystem by go buil main.go and try to run the command: protolint -plugin ./main.exe .. However, I receive failed client.Client(), err=exec: "sh": executable file not found in %PATH%

@rost5000 rost5000 changed the title Protolint doesn't work -plugin in windows Protolint doesn't work with -plugin in windows Jan 15, 2021
@yoheimuta
Copy link
Owner

yoheimuta commented Jan 16, 2021

@rost5000 Thank you for your information.
It happens because the plugin depends on sh.

Cmd: exec.Command("sh", "-c", value),

I'm going to remove this dependency.

@yoheimuta yoheimuta added the bug Something isn't working label Jan 16, 2021
@yoheimuta
Copy link
Owner

@rost5000 Can you try adding sh in your PATH?
Because simply giving up sh -c seems to be not a solution. See #145 (comment).

Ref:

@yoheimuta yoheimuta self-assigned this Jan 17, 2021
@yoheimuta yoheimuta removed the bug Something isn't working label Jan 23, 2021
@yoheimuta yoheimuta added the question Further information is requested label Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants