Skip to content

Commit

Permalink
chore: fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught committed Jan 10, 2024
1 parent b43d112 commit e48222d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,10 @@ linters-settings:

goimports:
local-prefixes: "github.com/openfga/cli"

issues:
exclude-use-default: true
exclude-rules:
- path: "cmd/tuple/write(.*).go"
linters:
- lll
11 changes: 6 additions & 5 deletions cmd/tuple/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func parseTuplesFileData(fileName string) ([]client.ClientTupleKey, error) {
func parseTuplesFromCSV(data []byte, tuples *[]client.ClientTupleKey) error {
reader := csv.NewReader(bytes.NewReader(data))

for i := 0; true; i++ {
if i == 0 {
for index := 0; true; index++ {
if index == 0 {
if err := guardAgainstInvalidHeaderWithinCSV(reader); err != nil {
return err
}
Expand Down Expand Up @@ -213,11 +213,12 @@ func parseTuplesFromCSV(data []byte, tuples *[]client.ClientTupleKey) error {
tupleUserKey += "#" + tuple[UserRelation]
}

var condition *openfga.RelationshipCondition = nil
var condition *openfga.RelationshipCondition

if tuple[ConditionName] != "" {
conditionContext, err := cmdutils.ParseQueryContextInner(tuple[ConditionContext])
if err != nil {
return fmt.Errorf("failed to read condition context on line %d: %w", i, err)
return fmt.Errorf("failed to read condition context on line %d: %w", index, err)
}

condition = &openfga.RelationshipCondition{
Expand Down Expand Up @@ -283,5 +284,5 @@ func init() {
writeCmd.Flags().String("condition-name", "", "Condition Name")
writeCmd.Flags().String("condition-context", "", "Condition Context (as a JSON string)")
writeCmd.Flags().Int("max-tuples-per-write", MaxTuplesPerWrite, "Max tuples per write chunk.")
writeCmd.Flags().Int("max-parallel-requests", MaxParallelRequests, "Max number of requests to issue to the server in parallel.") //nolint:lll
writeCmd.Flags().Int("max-parallel-requests", MaxParallelRequests, "Max number of requests to issue to the server in parallel.")
}
8 changes: 4 additions & 4 deletions cmd/tuple/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestParseTuplesFileData(t *testing.T) {
func TestParseTuplesFileData(t *testing.T) { //nolint:funlen
t.Parallel()

tests := []struct {
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestParseTuplesFileData(t *testing.T) {
{
name: "it fails to parse a non-existent file",
file: "testdata/tuples.bad",
expectedError: "failed to read file \"testdata/tuples.bad\": open testdata/tuples.bad: no such file or directory", //nolint:lll
expectedError: "failed to read file \"testdata/tuples.bad\": open testdata/tuples.bad: no such file or directory",
},
{
name: "it fails to parse a non-supported file format",
Expand All @@ -104,7 +104,7 @@ func TestParseTuplesFileData(t *testing.T) {
{
name: "it fails to parse a csv file with wrong headers",
file: "testdata/tuples_wrong_headers.csv",
expectedError: "failed to parse input tuples: csv file must have exactly these headers in order: \"user_type,user_id,user_relation,relation,object_type,object_id,condition_name,condition_context\"", //nolint:lll
expectedError: "failed to parse input tuples: csv file must have exactly these headers in order: \"user_type,user_id,user_relation,relation,object_type,object_id,condition_name,condition_context\"",
},
{
name: "it fails to parse a csv file with missing required headers",
Expand All @@ -119,7 +119,7 @@ func TestParseTuplesFileData(t *testing.T) {
{
name: "it fails to parse a csv file with invalid rows",
file: "testdata/tuples_with_invalid_rows.csv",
expectedError: "failed to parse input tuples: failed to read tuple from csv file: record on line 2: wrong number of fields", //nolint:lll
expectedError: "failed to parse input tuples: failed to read tuple from csv file: record on line 2: wrong number of fields",
},
}

Expand Down

0 comments on commit e48222d

Please sign in to comment.