I am currently having an issue with the automatic indentation when pushing my code to Github.
I currently have my tab settings to be using spaces on VS Code (tabs set to 2 spaces), yet Github is displaying a massive jump in the organization of the code.
Below are examples of what I am experiencing:
My code looks on VS Code:
My code in Github:
Settings that I have manipulated (tabs to spaces setup on VS Code):
At this point, I don't even know if my settings are set up properly.
You need to set your preferred tab size in github as well.
Go to your Settings (under your icon in the upper right of any repository page),
Appearance/Tab size preferences <== set to 2.
So it is a guthub issue, I think github interprets a tab as 8 spaces by default for some reason.
Related
I realized that when I push my code to my GitHub repo, the indentation is being displayed as 8..? but In my VSCODE, I have set my indentation as 2.
Is there a permanent fix to this issue? I am aware that I can go into my code and press the pen icon and view my code in 2 spaces, 4 spaces or 8 spaces using the options but this doesn't change my code being displayed in 2 spaces permanently.
Below is the image comparison
Double-check first your GitHub account settings "Tab Size Preference" (new since Sept. 2021)
Those should apply to all of your repositories.
Whenever I push or manually upload code to github extra whitespace will appear in the committed code. I'm using prettier and eslint, I've tried pushing with both enabled and disabled, and with prettier only enabled.
Code as shown on GitHub:
User Settings:
Workspace Settings:
Do you use tabs instead of spaces? Most editors allow you (like you’ve shown) to customize what a tab character shows as (e.g. 8 spaces). My assumption is that your setting is smaller than what GitHub uses for its display. GitHub doesn’t modify your code.
so setting "prettier.useTabs" to false resolves the issue, you would think that the code being pushed and code being displayed would be the same perhaps this is an issue to push to prettier's git repo but i digress, thanks for the feedback.
For my code I'm using Brackets. In editor, code looks proper but after pushing it to github repository, indentations are messed up.
I'm using tab key to make indentation but in preferences there is set "use 2 spaces" after pressing tab key.
I've find out that Github is using 8 spaces for recognised tab keys. But still, it does not give me anything.
The biggest problem is when I use "one var statement".
I've also used jsbeautifier and it doesn't help me at all.
Here you can find an example: My Github code example
Does anybody had such a problem with brackets and github indentations?
Yes I had such problems.
These problems did not reappear when we moved to eslint inside of our IDE. The setup varies for each IDE. You can refer https://eslint.org/docs/rules/indent
If setting eslint is hard for you. Try bracket extensions like https://github.com/brackets-beautify/brackets-beautify . When used correctly it will beautify on save. Caution: Dont beautify code written by others or a team.
I am writing blog using Jekyll on github page.
Instead of using offline editors, I use github online editor which supports markdown very well.
But I when I edit posts, github editor set the default indent size to 8. I tried to change it to 4, but after I save it and reedit this post, github editor reset the indent size to 8.
I am wondering why this happens. How can I set the default indent size to 4 for every file?
Thanks!
It's not a permanent setting. You can change it for the edit mode with the dropdown you mention and for blob mode by appending ?ts=4 to the URL on a per-file basis.
If you're using chrome, you could use Sindre Sorhus' tab-size-on-github extension that does exactly what you want: Force all tabs to represent 4 spaces always.
Everything is good in Eclipse, indenting is fine. Then I put my code on github
and for some reason the indenting was a mess. I am not sure what is going on?
Thanks
If those indentation issues are reflected back in your code after a git push to GitHub, you either have:
a hook removing spaces before tab (as in "Make git automatically remove trailing whitespace before committing")
or a filter content driver declared ina .gitattributes file (as in "Can git automatically switch between spaces and tabs?")
Those are the two automatic mechanisms that could explain a change during the git commit.
But if your code looks fine locally after the git push, but looks not fine on GitHub, then you must have a combination of space and tabs correctly rendered locally, and rendered differently on GitHub.
As mentioned in "Indentation issue using sublime text 2":
The problem is not hard tabs, the problem is mixing spaces and tabs for indentation.
I got this working in eclipse:
Eclipse Settings:
Preferences : Java -> Code Style -> Formatter
Create new profile
Update profile indent settings:
Update Existing Java Source:
(Toolbar) Source : Correct Indentation
Check file, you should see all indentations use spaces, not tabs