Skip to content

Conversation

@BirmacherAkos
Copy link
Contributor

XCode: After the user drag and drop the project file to the console, it will trim the project path.

characterSetToRemove {"\n", ', "}

…it will trim the project path.

characterSetToRemove {"\n", `'`, `"`}
cmd/common.go Outdated
return projpth
}
characterSetToRemove := []string{"\n", `'`, `"`}
for {
Copy link
Contributor

Choose a reason for hiding this comment

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

please don't use infinite loop if possible - include the condition directly in the for (CONDITION) part

Choose a reason for hiding this comment

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

for example:

for _, character := range []string{"\n", `'`, `"`} {
...
}

Here you can find more info about range: https://gobyexample.com/range

cmd/common.go Outdated
projpth = strings.Trim(projpth, `"`)
projpth = strings.TrimSpace(projpth)

if !contains(characterSetToRemove, projpth[:1]) && !contains(characterSetToRemove, projpth[len(projpth)-1:]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

additionally, we don't want to remove every occurance of ' and " I believe

the project can include ' or " in the file name, as far as I know

we only want to remove the outmost quotes

so, a single strings.Trim(strings.Trim(...)) would be enough instead of the for, IMO

Choose a reason for hiding this comment

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

beside of that, if you ever will need to use something like your contains function, we have that in a package already:
sliceutil.IsStringInSlice(slice, string)

@viktorbenei viktorbenei requested a review from godrei March 14, 2018 11:53
cmd/xcode.go Outdated
}

projpth = trimProjectpath(projpth)
projectPath = projpth

Choose a reason for hiding this comment

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

projectPath = projpth -> projectPath = trimProjectpath(projpth)

 - trimProjectpath method fix - Infinite loop removed. It will trim every ', ", character
 - contains method removed (Already have one as a util.)

common_test.go: The "Multiple" test case has been removed. (Because we don't use multiple trim)

xcode.go: clean

https://trello.com/c/hgIG0VO9

e90afee commit fix
cmd/xcode.go Outdated
}
projectPath = projpth

projectPath = trimProjectpath(projpth)

Choose a reason for hiding this comment

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

strings.Trim function's second parameter is a cutset, which means all leading and trailing Unicode code points contained in cutset will be removed. There is no need for loop over the items in the cutset.

projectPath = strings.Trim(strings.TrimSpace(projpth), "'\"")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it.
Still, I did not remove the trimProjectpath() because with that method it is easier to make unit tests.

- trimProjectpath method fix - strings.Trim function's second parameter is a cutset -> There is no need for loop over the items in the cutset.

https://trello.com/c/hgIG0VO9

4894265 commit fix
 - cmd/common_test.go: Test_trimProjectpath removed;
@kdobmayer kdobmayer merged commit ce66a50 into bitrise-io:master Mar 20, 2018
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.

4 participants