Skip to content

Commit

Permalink
[FAB-3603] Enable more strict code checking
Browse files Browse the repository at this point in the history
* Update the linter script to checking go vet result when `make linter`;
* Add the new created idemix path to the check list;
* Update source code to pass the more strict checking;
* Fix several wrong usages in Error msg.

Change-Id: I1ed61745079726df00643206069b56b9846fa1c1
Signed-off-by: Baohua Yang <yangbaohua@gmail.com>
  • Loading branch information
yeasy committed Nov 2, 2017
1 parent 75709bc commit dcf36eb
Show file tree
Hide file tree
Showing 74 changed files with 401 additions and 391 deletions.
2 changes: 1 addition & 1 deletion common/cauthdsl/cauthdsl_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func init() {
// Envelope builds an envelope message embedding a SignaturePolicy
func Envelope(policy *cb.SignaturePolicy, identities [][]byte) *cb.SignaturePolicyEnvelope {
ids := make([]*msp.MSPPrincipal, len(identities))
for i, _ := range ids {
for i := range ids {
ids[i] = &msp.MSPPrincipal{PrincipalClassification: msp.MSPPrincipal_IDENTITY, Principal: identities[i]}
}

Expand Down
6 changes: 3 additions & 3 deletions common/cauthdsl/cauthdsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ func TestNilSignaturePolicyEnvelope(t *testing.T) {

func TestDeduplicate(t *testing.T) {
ids := []*cb.SignedData{
&cb.SignedData{
{
Identity: []byte("id1"),
},
&cb.SignedData{
{
Identity: []byte("id2"),
},
&cb.SignedData{
{
Identity: []byte("id3"),
},
}
Expand Down
4 changes: 2 additions & 2 deletions common/cauthdsl/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestAccept(t *testing.T) {
policyID := "policyID"
m, err := policies.NewManagerImpl("test", providerMap(), &cb.ConfigGroup{
Policies: map[string]*cb.ConfigPolicy{
policyID: &cb.ConfigPolicy{Policy: acceptAllPolicy},
policyID: {Policy: acceptAllPolicy},
},
})
assert.NoError(t, err)
Expand All @@ -83,7 +83,7 @@ func TestReject(t *testing.T) {
policyID := "policyID"
m, err := policies.NewManagerImpl("test", providerMap(), &cb.ConfigGroup{
Policies: map[string]*cb.ConfigPolicy{
policyID: &cb.ConfigPolicy{Policy: rejectAllPolicy},
policyID: {Policy: rejectAllPolicy},
},
})
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion common/channelconfig/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestInterface(t *testing.T) {
func TestChannelConfig(t *testing.T) {
cc, err := NewChannelConfig(&cb.ConfigGroup{
Groups: map[string]*cb.ConfigGroup{
"UnknownGroupKey": &cb.ConfigGroup{},
"UnknownGroupKey": {},
},
})
assert.Error(t, err)
Expand Down
2 changes: 1 addition & 1 deletion common/channelconfig/realconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestWithRealConfigtx(t *testing.T) {
},
}
conf.Application.Organizations[0].AnchorPeers = []*genesisconfig.AnchorPeer{
&genesisconfig.AnchorPeer{
{
Host: "foo",
Port: 7,
},
Expand Down
6 changes: 3 additions & 3 deletions common/configtx/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ func recurseConfigMap(path string, configMap map[string]comparable) (*cb.ConfigG
newConfigGroup := cb.NewConfigGroup()
proto.Merge(newConfigGroup, group.ConfigGroup)

for key, _ := range group.Groups {
for key := range group.Groups {
updatedGroup, err := recurseConfigMap(path+PathSeparator+key, configMap)
if err != nil {
return nil, err
}
newConfigGroup.Groups[key] = updatedGroup
}

for key, _ := range group.Values {
for key := range group.Values {
valuePath := ValuePrefix + path + PathSeparator + key
value, ok := configMap[valuePath]
if !ok {
Expand All @@ -153,7 +153,7 @@ func recurseConfigMap(path string, configMap map[string]comparable) (*cb.ConfigG
newConfigGroup.Values[key] = proto.Clone(value.ConfigValue).(*cb.ConfigValue)
}

for key, _ := range group.Policies {
for key := range group.Policies {
policyPath := PolicyPrefix + path + PathSeparator + key
policy, ok := configMap[policyPath]
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions common/configtx/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ var (
configAllowedChars = "[a-zA-Z0-9.-]+"
maxLength = 249
illegalNames = map[string]struct{}{
".": struct{}{},
"..": struct{}{},
".": {},
"..": {},
}
)

Expand Down
2 changes: 1 addition & 1 deletion common/configtx/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (cm *configManager) verifyDeltaSet(deltaSet map[string]comparable, signedDa
}

func verifyFullProposedConfig(writeSet, fullProposedConfig map[string]comparable) error {
for key, _ := range writeSet {
for key := range writeSet {
if _, ok := fullProposedConfig[key]; !ok {
return fmt.Errorf("Writeset contained key %s which did not appear in proposed config", key)
}
Expand Down
2 changes: 1 addition & 1 deletion common/configtx/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestPolicyForItem(t *testing.T) {
PolicyManagerVal: &mockpolicies.Manager{
Policy: rootPolicy,
SubManagersMap: map[string]*mockpolicies.Manager{
"foo": &mockpolicies.Manager{
"foo": {
Policy: fooPolicy,
},
},
Expand Down
36 changes: 18 additions & 18 deletions common/policies/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func defaultProviders() map[int32]Provider {
func TestUnnestedManager(t *testing.T) {
config := &cb.ConfigGroup{
Policies: map[string]*cb.ConfigPolicy{
"1": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}},
"2": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}},
"3": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}},
"1": {Policy: &cb.Policy{Type: mockType}},
"2": {Policy: &cb.Policy{Type: mockType}},
"3": {Policy: &cb.Policy{Type: mockType}},
},
}

Expand All @@ -65,30 +65,30 @@ func TestUnnestedManager(t *testing.T) {
func TestNestedManager(t *testing.T) {
config := &cb.ConfigGroup{
Policies: map[string]*cb.ConfigPolicy{
"n0a": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}},
"n0b": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}},
"n0c": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}},
"n0a": {Policy: &cb.Policy{Type: mockType}},
"n0b": {Policy: &cb.Policy{Type: mockType}},
"n0c": {Policy: &cb.Policy{Type: mockType}},
},
Groups: map[string]*cb.ConfigGroup{
"nest1": &cb.ConfigGroup{
"nest1": {
Policies: map[string]*cb.ConfigPolicy{
"n1a": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}},
"n1b": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}},
"n1c": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}},
"n1a": {Policy: &cb.Policy{Type: mockType}},
"n1b": {Policy: &cb.Policy{Type: mockType}},
"n1c": {Policy: &cb.Policy{Type: mockType}},
},
Groups: map[string]*cb.ConfigGroup{
"nest2a": &cb.ConfigGroup{
"nest2a": {
Policies: map[string]*cb.ConfigPolicy{
"n2a_1": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}},
"n2a_2": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}},
"n2a_3": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}},
"n2a_1": {Policy: &cb.Policy{Type: mockType}},
"n2a_2": {Policy: &cb.Policy{Type: mockType}},
"n2a_3": {Policy: &cb.Policy{Type: mockType}},
},
},
"nest2b": &cb.ConfigGroup{
"nest2b": {
Policies: map[string]*cb.ConfigPolicy{
"n2b_1": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}},
"n2b_2": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}},
"n2b_3": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}},
"n2b_1": {Policy: &cb.Policy{Type: mockType}},
"n2b_2": {Policy: &cb.Policy{Type: mockType}},
"n2b_3": {Policy: &cb.Policy{Type: mockType}},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion common/resourcesconfig/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestBundleBadSubGroup(t *testing.T) {
Groups: map[string]*cb.ConfigGroup{
PeerPoliciesGroupKey: &cb.ConfigGroup{
Values: map[string]*cb.ConfigValue{
"Foo": &cb.ConfigValue{
"Foo": {
Value: utils.MarshalOrPanic(&pb.Resource{
PolicyRef: "foo",
}),
Expand Down
Loading

0 comments on commit dcf36eb

Please sign in to comment.