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

--lineseparator option to use whatever separator the file is already using #209

Closed
DetachHead opened this issue Sep 24, 2021 · 5 comments · Fixed by #215
Closed

--lineseparator option to use whatever separator the file is already using #209

DetachHead opened this issue Sep 24, 2021 · 5 comments · Fixed by #215
Assignees

Comments

@DetachHead
Copy link
Contributor

in my team, some people use git core.autocrlf=true and others use input, which means robotidy will change the line endings unnecessarily. it would be nice if there was an option to make it use whatever line endings the file already has

@bhirsz
Copy link
Member

bhirsz commented Sep 24, 2021

Currently we have three (fixed) options: native, windows and linux. To implement your idea we would need to implement some sort of checker for separator type before running transformations (and we could call --lineseparator detect or --lineseparator keep). Is it what you have in mind?

What if line separator are not consistent? Easiest would be just use the first line separator. We could also try to count and pick most popular one (with small hit to performance but nothing noticeable).

@DetachHead
Copy link
Contributor Author

i'm not sure what the best way is, maybe see how other formatters handle this issue? for example prettier: https://prettier.io/docs/en/options.html#end-of-line

"auto" - Maintain existing line endings (mixed values within one file are normalised by looking at what’s used after the first line)

@bhirsz
Copy link
Member

bhirsz commented Sep 24, 2021

"The other are doing this" is deciding factor ;) We can go with 'auto' and just check for first line ending. Basically if linesep is set to auto and we're saving the model to disk here:

ModelWriter(output=output, newline=self.formatting_config.line_sep).write(model)

then we could check the source for line endinds and use it instead. Here usage of 'newlines' attribute:
https://stackoverflow.com/questions/2798627/how-can-i-detect-dos-line-breaks-in-a-file

@bhirsz
Copy link
Member

bhirsz commented Sep 24, 2021

I can do it - or leave if for you if you want to create PR.

@DetachHead
Copy link
Contributor Author

thanks! sorry i didn't see your comment

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 a pull request may close this issue.

2 participants