Github Code displaying wrong indentation issue - github

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.

Related

Issue with VSCode vs Github code indentation

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.

Problems with indentations on Github

I have some issues with my indentations on GitHub: It shows that I have an indent size of 8 on GitHub even after I changed it to indent size 2 and pushed it.
I have changed the settings on prettier so the code has a indent size 2, and look as it should in my VSCode, but when I commit it is still has a indent size 8.
Attached some photos below and a link to my repo: https://github.com/MT-dotse/project-mongo-api/blob/master/server.js
Code on VSCode:
Code on GitHub:
I do see your code on GitHub with the expected tab size of 2, not 8.
But that is only because I have set my GitHub account setting "Tab Size" to 2.
Which means any tab is displayed (in my GitHub session on a browser page) as 2 spaces, not 8.
As the OP Madelene adds in the comments, as an alternative solution:
I needed to uncheck the "use tabs", and change the tab width to 2 in the prettier extension.

Code pushed or uploaded to GitHub shows extra whitespace

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.

Indentation issue after pushing code from Brackets Editor to Github

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.

Github and sublimetext tab spacing

After upgrading to the new iOS and getting a ton of Java exceptions from WebStorm, I've switched to Sublimetext. I've changed my tab settings to 2 spaces (I've tried toggling between both true/false for translate tabs to spaces.
"tab_size": 2,
"translate_tabs_to_spaces": false,
This seems fine in the editor, however now on new files whenever I push to github, it's showing a full tab or 4 spaces. For those that use GitHub/Sublime, any idea how to fix this so github recognizing the tab settings also?
Thank you!
EDIT:
It turns out the following settings in sublime will do as expected:
"tab_size": 2,
"translate_tabs_to_spaces": true,
"detect_indentation" : false
It's not something you can control. Github represents tabs as 4 spaces. The actual file still consist of tabs, so will appear correctly in your text editor (assuming it is configured to 2 spaces per tab).