Skip to content

Conversation

smacker
Copy link
Contributor

@smacker smacker commented Mar 12, 2018

Fixes: #176

screen shot 2018-03-12 at 12 23 45

@smacker smacker requested a review from bzz March 12, 2018 11:25
@ricardobaeta
Copy link
Contributor

Awesome @smacker !

Copy link
Contributor

@dpordomingo dpordomingo left a comment

Choose a reason for hiding this comment

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

thanks!
storing the user preference in the local storage was a great idea, and it works like a charm!

I'd only require some cosmetic and organizational changes.

filePair.Right.Content,
preprocessors...,
)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

contentB = p(contentB)
}

diffString, err := d.generate(nameA, nameB, contentA, contentB)
Copy link
Contributor

Choose a reason for hiding this comment

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

this line could be replaced by

retun d.generate(nameA, nameB, contentA, contentB)

And then the code below that would be unnecessary


// DiffReplaceInvisible preprocessor function that replace invisible character with visible onces
func DiffReplaceInvisible(content string) string {
lines := strings.Split(content, "\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to split → replace → join?

Could we replace it by...

func ReplaceInvisible(content string) string {
	line := strings.Replace(content, " ", "·", -1)
	line = strings.Replace(line, "\t", "→", -1)
	line = strings.Replace(line, "\r", "^M", -1)
	line = strings.Replace(line, "\n", "↵\n", -1)
	return line	
}

}

// DiffReplaceInvisible preprocessor function that replace invisible character with visible onces
func DiffReplaceInvisible(content string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Diff should not be part of the function name


assert.Equal(
service.DiffReplaceInvisible(diffStr),
"---·a.txt^M↵\n+++·b.txt^M↵\nline^M↵\n····tabbed·line^M↵\n····spaced·line^M↵\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

since Diff should not be part of the ReplaceInvisible function name, it should be applied everywhere, what means that the test data should not be a diff file (because then, it looks a different thing)


assert.Equal(
service.DiffReplaceInvisible(diffStr),
"---·a.txt^M↵\n+++·b.txt^M↵\nline^M↵\n····tabbed·line^M↵\n····spaced·line^M↵\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

If the test input data is loaded from a file, the expected data should be also loaded from a file.

imo, both: input and expected should be defined inside of the test case function instead of inside an external file (they're too simple to be hidden inside a file), what is also more explicit and clear.

input := "line\r\n".
  "\ttabbed line\n".
  "    spaced line\n"
expected := "line^M↵\n".
    "→tabbed·line↵\n".
    "····spaced·line↵\n"
assert := suite.Assert().Equal(input, expected)

@@ -0,0 +1,5 @@
--- a.txt
Copy link
Contributor

Choose a reason for hiding this comment

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

if input/expected is inside of the test case, this should be not necessary.


var preprocessors []service.DiffPreprocessorFunc

if r.URL.Query().Get("showInvisible") != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

for consistency with front api call, it should be:

		if r.URL.Query().Get("showInvisible") == "1" {

// ReplaceInvisible preprocessor function that replace invisible character with visible onces
func ReplaceInvisible(content string) string {
content = strings.Replace(content, " ", "·", -1)
content = strings.Replace(content, "\t", "→", -1)
Copy link
Contributor

@carlosms carlosms Mar 13, 2018

Choose a reason for hiding this comment

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

How about replacing tab with '→ ' to try to keep indentation? I think a single char indentation may make code less readable.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm used to seeing only one → symbol.
If you want more space, we could use ⟶ (⟶ or ⟶).
but whatever you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's odd, I kind of expect any editor to show the symbol and indent. Like VS Code for example:
tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I definitely saw only → many times.

Copy link
Contributor

@carlosms carlosms left a comment

Choose a reason for hiding this comment

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

Looks good to me, I just left a suggestion for the tab character.


if r.URL.Query().Get("showInvisible") != "" {
preprocessors = append(preprocessors, service.DiffReplaceInvisible)
if r.URL.Query().Get("showInvisible") != "1" {
Copy link
Contributor

@dpordomingo dpordomingo Mar 13, 2018

Choose a reason for hiding this comment

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

ups! it should be ==
😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahahahaha. 🤦‍♂️

fixed.

Copy link
Contributor

@dpordomingo dpordomingo left a comment

Choose a reason for hiding this comment

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

LGTM
If @carlosms has not an strong opinión about indentation chars, please squash and merge

Signed-off-by: Maxim Sukharev <maxim@sourced.tech>
@smacker smacker force-pushed the show_spaces_tab_new_lines branch from a278354 to ceba33c Compare March 14, 2018 10:58
@smacker smacker merged commit 5c4a418 into src-d:master Mar 14, 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.

5 participants