VScode format as save not work for Golang - go

I'm using vscode and developing a go project via remote-ssh. However, the format on save does not work. I found it works on the normal project without git. If I remove the .git, it will work as expected. Does anyone have some advice for me?
The version of the environment is as follows:
vscode 1.63.2
go 1.17.6
remote machine Ubuntu 20.04
go extension v0.30.0

I had the same issue recently, auto format would only work on projects without a .git directory. What solved the issue for me was to change Format On Save Mode from modificationsIfAvailable to file. Since I prefer modificationsIfAvailable over file for everything, I changed to have formatOnSaveMode to file only for go source files with:
"[go]": {
"editor.formatOnSaveMode": "file"
}

Try to format your code manually by pressing Ctrl + Shift + P to open Command Palette and select Format Document. If your file is being properly formatted without any issues, it means there is something wrong in formatOnSave settings.
Choose a default formatter instead of null. like this :
"editor.defaultFormatter": "esbenp.prettier-vscode"
Uninstall other formatters one by one to see if anything causes the conflict.
Try to make it Language specific.
For better understanding refer this link : https://github.com/microsoft/vscode/issues/108447
About Git Specific:
It may be the case that you are running Git Atom. Atom is a desktop application, so may be causing problems in accessing the remote installation path.Try installing Git Repo.
Also make sure Go: Install/Update Tools are up-to-date.

Related

How to use git commands in Visual Studio 2019 Integrated Terminal [duplicate]

Visual Studio Code reports "It look like git is not installed on your system." when I try to switch to the git view. I know I have git installed and used by other Git clients. I guess if I reinstall Git following Visual Studio Code's instruction ("install it with Chocolatey or download it from git-scm.com"), it probably can fix the problem, but I don't want to mess up the existing Git clients on my system. Is there a reliable way to configure Visual Studio Code so it can find existing git installation?
Now you can configure Visual Studio Code (version 0.10.2, check for older versions) to use an existing Git installation.
Just add the path to the Git executable in your Visual Studio Code settings (menu File → Preferences → Settings) like this:
{
// Is Git enabled
"git.enabled": true,
// Path to the Git executable
"git.path": "C:\\path\\to\\git.exe"
// Other settings
}
Update 2020 (Mac)
I went through this $h!† again after updating to macOS v10.15 (Catalina), which requires an Xcode update.
And to clarify, while this post is about Visual Studio Code, this issue, is system wide. Your Git install is affected/hosed. You can try to run git in your terminal, Bash, Z shell (zsh), or whatever. It is now and it just won't.
It is the same fix. Just update Xcode. Start it up and agree to the license. That's it.
I hit this on Mac/OS X.
Symptoms:
You've been using Visual Studio Code for some time and have don’t have any issues with Git
You install Xcode (for whatever reason - OS update, etc.)
After installing Xcode, Visual Studio Code suddenly "can't find Git and asks you to either install or set the Path in settings"
Quick fix:
Run Xcode (for the first time, after installing) and agree to license. That's it.
How I stumbled upon this "fix":
After going through numerous tips about checking git, e.g., which git and git --version, the latter actually offered clues with this Terminal message:
Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” and then retry this command.
As to why Xcode would even wrap it's hands on git, WAT.
Visual Studio Code simply looks in your PATH for git. Many UI clients ship with a "Portable Git" for simplicity, and do not add git to the path.
If you add your existing git client to your PATH (so that it can find git.exe), Visual Studio Code should enable Git source control management.
This can happen after upgrading macOS. Try running Git from a terminal and see if the error message begins with:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) ...
If so, the fix is to run:
xcode-select --install
from the terminal. See this answer for more details.
I had this problem after upgrading to macOS v10.15 (Catalina).
The issue is resolved as follows:
1.
Find the Git location from the terminal:
which git
2.
Add the location of Git in settings file with your location:
settings.json
"git.path": "/usr/local/bin/git",
Depending on your platform, the user settings file (settings.json) is located here:
Windows %APPDATA%\Code\User\settings.json
macOS $HOME/Library/Application Support/Code/User/settings.json
Linux $HOME/.config/Code/User/settings.json
In Visual Studio Code, open 'User Settings': Ctrl + P and type >sett. Press Enter.
This will open the default settings on the left side and User Settings on the right side.
Just add the path to git.exe in user settings:
"git.path": "C:\\Users\\[WINDOWS_USER]\\AppData\\Local\\Programs\\Git\\bin\\git.exe"
Replace [WINDOWS_USER] with your user name.
Restart Visual Studio Code.
First check if Git* is installed or not in your system by typing the command in cmd /command prompt (in Windows):
where git
If you get an output like this,
λ where git
C:\cmder\vendor\git-for-windows\cmd\git.exe
Then Go to Settings → Preferences → Settings and put the bellow code** right part.
{
// If git enabled?
"git.enabled": true,
// Path to the Git executable
"git.path": "C:\\cmder\\vendor\\git-for-windows\\cmd\\git.exe"
}
If you don't have Git installed, install Git from https://git-scm.com/
** Just add a double slash (\\), just like the above code.
UPGRADE TO MacOS Ventura < 13.0
As of November 2022
Upgrading to MacOS Ventura does not seem to affect your coding environments too much.
After upgrading to macOS Ventura your Terminal and VScode will give off a few errors. Such as:
It look like git is not installed on your system ..
or
can't find Git and asks you to either install or set the Path in settings
some errors depend on your zsh setup or other customizations.
These common problems can be resolved by simply by reinstalling xcode command line tools and updating Homebrew - since your terminal might be affected reinstall from apples executable https://developer.apple.com/download/all/
developer.apple.com you will need to log in with your apple id.
Once installed, update Homebrew
brew upgrade
Mac M1 - M2 machines likely have some native and ARM applications so run:
arch -arm64 brew upgrade
Close all terminals and Vscode to restart!
reopen Vscode, errors should be gone.
If Vscode is still looking for Git path you will need to add it manually.
Find git location and copy from the terminal:
which git
and add the path to the git executable in your Visual Studio Code JSON settings file (File -> Preferences -> Settings) find and update the line - should look similar:
"git.path": "/usr/local/bin/git",
After an OS X update, I had to run xcode-select --install for GitLens to work.
Ran into the same problem after!
how I fixed it?
Step 1: Go to the Settings in vscode.
Step 2: Open settings.json.
Step 3: You need to find something like "git.path" in settings.json
Step 4: just add the directory path where git is installed in your system.
example : "git.path": "D:/Git/bin/git.exe"
Step 5: Restart your vscode.
Hope this helps.
Run
xcode-select --install it'll prompt you to install command line developer tools. Install the tools and installation restart your VScode.
You'll see git working once again in VScode
I ran into this problem after upgrading my macOS to Monterey.
It turned out that the xcode has been removed in the new update from my mac. Just tried the following suggested solution:
https://stackoverflow.com/a/52522566/11207358
VSCode 1.50 (Sept 2020) adds an interesting alternative with issue 85734:
Support multiple values for the git.path setting
I use VSCode in three different places; my home computer, my work computer, and as a portable version I carry on a drive when I need to use a machine that doesn't have it.
I use an extension to keep my settings synced up between editors, and the only issue I've encountered so far is that the git path doesn't match between any of them.
On my home machine I have it installed to C of course,
work likes to be funny and install it on A,
and for the one on my drive I have a relative path set so that no matter what letter my drive gets, that VSCode can always find git.
I already attempted to use an array myself just to see if it'd work:
"git.path": ["C:\\Program Files\\Git\\bin\\git.exe", "A:\\Git\\bin\\git.exe", "..\\..\\Git\\bin\\git.exe"],
But VSCode reads it as one entire value.
What I'd like is for it to recognize it as an array and then try each path in order until it finds Git or runs out of paths.
This is addressed with PR 85954 and commit c334da1.
with VSCode 1.60+
"git.enabled": true
git.path
I faced this problem on macOS v10.13.5 (High Sierra) after upgrading Xcode.
When I run the git command, I received the below message:
Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” and then retry this command.
After running the sudo xcodebuild -license command, the below message appears:
You have not agreed to the Xcode license agreements. You must agree to both license agreements below in order to use Xcode.
Hit the Enter key to view the license agreements at '/Applications/Xcode.app/Contents/Resources/English.lproj/License.rtf'
Typing the Enter key to open the license agreements and typing the space key to review details of it, until the below message appears:
By typing 'agree' you are agreeing to the terms of the software license agreements. Type 'print' to print them or anything else to cancel, [agree, print, cancel]
The final step is simply typing agree to sign with the license agreement.
After typing the git command, we can check that Visual Studio Code detected Git again.
I have recently started with Visual Studio Code. I have this issue and just writing the exact path of the Git executable solves
the issue. Here is the code:
"git.path": "C:\Program Files\Git\bin\git.exe",
If you have multiple environments. You could include Git Path in the Visual Studio Code Workspace Setting. For Windows, depending on your setting, you could hit Ctrl + P, search for "settings". Open settings.json (or menu File → Preferences → Settings). Navigate to Workspace Settings. Find "Path" and add paths to Git bin and cmd folders.
Environments can have their own paths. I discovered this when I echoed my PC %PATH% on cmd. Git bin and cmd path where available, but when I was working on my project, echoed %PATH% did not have git and cmd folder. Adding them, as shown above, solved the issue.
Extra Notes:
On cmd, you can echo "%PATH%" and see if git bin and cmd folders are included. If not, you could concatenate using SETX PATH on, for example,
SETX PATH "%PATH%;Path_to_Git_bin;Path_to_Gt_cmd;"
This will make git available on local, root but not in some environments which comes with their own paths (SETX /M PATH "%PATH%;Path_to_Git_bin;Path_to_Gt_cmd;" would have though).
In case you have a long Path that is chopped off due to Path length (getting "Error: Truncated at X characters." message), you can increase the path length in RegEdit.
In "Search Windows", search for "regedit". Right-click to open as Administrator.
Go to Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
Right-click and modify. Change value data from 0 to 1
This will increase your path length. If it is already one, then I am not sure how to proceed from there :).
[9
The only way I could get to work in my Windows 8.1 is the following:
Add to system environment variables (not user variables):
c:\Users\USERNAME\AppData\Local\GitHub\PortableGit_YOURVERSION\bin\;c:\Users\USERNAME\AppData\Local\GitHub\PortableGit_YOURVERSION\libexec\git-core\;c:\Users\USERNAME\AppData\Local\GitHub\PortableGit_YOURVERSION\cmd\
This fixed the "it looks like git is not installed on your system" error on my Visual Studio Code.
Make sure git is enabled (File --> Preferences --> Git Enabled) as other have mentioned.
Make sure Gits installed and in the PATH (with the correct location, by default: C:\Program Files\Git\cmd) - PATH on system variables btw
Change default terminal, Powershell can be a bit funny, I recommend Git BASH but cmd is fine, this can be done by selecting the terminal dropdown and selecting 'set default shell' then creating a new terminal with the + button.
Restarting VS Code, sometimes Reboot if that fails.
Hope that helped, and last but not least, it's 'git' not 'Git'/'gat'. :)
In my case GIT was installed on my WIndows 10 OS and there was an entry in PATH variable. But VS CODE 1.52.1 still unable to detect it from terminal window but it was available in CMD console.
Problem was solved by switching terminal from PowerShell to CMD or Shell + VsCode restart.
I solved the same problem on MacOS with m1 pro processor by installing Git Lens Visual Code extension. The changed files were displayed after enabling the extension. Then I turned reloaded the VSCode and there was no changes, but once I run
git status
in terminal, it shows all the files, and all changes are tracked.
Faced this issue after updating macOS!
Installed git again using homebrew and it worked!
brew install git
FOR MAC
First, type
git
in the terminal and see what error you are getting.
Then:
If the error is related to Command Line tool!
Run:
xcode-select --install
And
Just go ahead and go through this answer, For Mac especially. Worked very easily for me.
https://apple.stackexchange.com/a/254381
Three years later, I ran into the same issue. Setting the path in user settings & PATH environment variable didn't help. I updated Visual Studio Code and that solved it.
First install Git onto your desktop, and then add the encircled extension in Visual Studio Code, as seen in the picture.
That helped me fix the same issue you have.
Open
C:\Users\nassim\AppData\Roaming\Code\User\settings.json
Comment any Git line there:
// ...
// "git-graph.integratedTerminalShell": "E:\\Apps\\Git\\bin\\bash.exe",
// "git.path": ""
//...
And add git.exe to the OS path.
Note for me: Fixing this Git error also fixed the npm error too. Since they are both defined in the path, if one fail, the remaining will fail as well.
Follow this :
1. File > Preferences > setting
2. In search type -> git path
3. Now scroll down a little > you will see "Git:path" section.
4. Click "Edit in settings.json".
5. Now just paste this path there "C:\\Program Files\\Git\\mingw64\\libexec\\git-core\\git.exe"
Restart VSCode and open new terminal in VSCode and try "git version"
In case still problem exists :
1. Inside terminal click on terminal options (1:Poweshell)
2. Select default shell
3. Select bash
open new terminal and change terminal option to 2:Bash
Again try "git version" - this should work :)
What worked for me was manually adding the path variable in my system.
I followed the instructions from Method 3 in this post:
https://appuals.com/fix-git-is-not-recognized-as-an-internal-or-external-command/
If git is missing after the OS update, in my case Big Sur, just literally: brew install git
I edited Path into System Environment and add "C:\Program Files\Git\bin" then restart Vscode. It's worked for me. I don't understand why I am using it normally then I have this problem. Maybe during the installation of something it causes that problem.
It worked for me just by installing git for windows, from this link https://git-scm.com/download/win
There was no need of setting environment variable or path.
Context:
I had installed VS Code, and github desktop, I cloned the repo using Github desktop.
When I opened repo, using VS Code, I saw this error.
I resolved by installing git for windows.

How to configure Github in VSCode?

VSCode has Github built in itself but I am not able to configure it. I tried it’s documentation but didn’t found anything helpful.
Do I need to install any extension to do so?
Here is the useful extension for VSCode, which I using now. It is simple to install & use, also has a good documentation.
LINK
UPDATE
Also, there by the link is the setup guide.
Just clone your repo and open the directory in VS Code, the editor will take care of the rest.
Else you could run the git init command in the directory you'd like to use (on the command line/terminal) and open the directory in VS Code.

Git: fatal: fsync error on 'sha1 file': Bad file descriptor

I'm using VS Code with Git - it's in portable location C:\_DEV\bin\git and is also added to Windows PATH so it works just fine with no remotes.
I have a OneDrive _GIT folder where I have some of my "remote" repositories, that sync between 2 devices (sometimes, I have it there mainly for backup purposes).
The error appears when I want to commit changes, only way to "fix" this issue is to restart the computer, so I'd like to find a way how to fix it properly. The problem is, it doesn't appear always and not for all repositories, it's pretty random.
I think it's because of sync from/to OneDrive. Is there a command I can run to fix the file descriptor? Or other way to prevent it?
git remote --verbose
git ls-tree -l HEAD -- a:\new\theme\assets\sass\main.scss
git show 97a333c5e7fce816dbb46a5c1235d69e61836726
git show HEAD:theme/assets/sass/main.scss
git add -A -- a:\new\theme\assets\sass\main.scss
fatal: fsync error on 'sha1 file': Bad file descriptor
Thanks to #edward-thomson.
I had same problem on my PC, where i mapped a folder under my homedrive to E:
C:\Users\myuserid\E-Folder\SomeGitProject
by sharing the folder, so i could shortcut it to
E:\SomeGitProject
Solution was to use the full path in CMD or use the shortcut to homedrive from git bash:
~/E-Folder/SomeGitProject
I guess your A: likewise is a share, that you can access with a full path probably also located somewhere under your homedrive.
I am posting late to help others get to the solution faster than I did. The actual culprit was elusive, and I tried everything from re-installing GIT to creating new repositories.
This happened to me in windows and it was due to a change in permissions in a parent folder somewhere.
The solution was to simply disconnect and remap the folder.
I have had this error a lot recently, and the above answers helped, but another thing that also seems to cause it is VS itself running.
Try closing VS, then doing a "Git Bash Here" from Explorer and using the command line only.
Once done you can then reopen VS.
I also have mapped my root webspace as a drive.
This is no problem until files are watched (like with npm run watch).
I faced same issue. I just resolved this issue with the following steps:
1- Close Visual Code
2- Open project on git bash command line
3- Commit the code again
I had the same problem with visual studio 2017. My solution was to close visual studio, then open Visual studio CODE and merge the files there.
Restarting VS Code works. A bit easier than disconnecting and re-mapping the folder (which also works).
I just had the same problem. In my case the problem was low disk space. Hope this helps someone.

How can I test my vim plugin?

Hi guys : I recently (accidentally) removed all folders/files from my .vim folder in mac os x (home directory).
I am trying to add in the Clojure Vim plugin (VimClojure) - its simply a folder which you are supposed to "drop into .vim/plugins".
I have added it, but I don't see any changes to the syntax highlighting when I launch vim. I'm not sure wether vim "sees" the plugin or not.
I'm on OS X .
Any ideas on how to debug the plugin ? In particular
1) How does VIM look for plugins ?
2) Are there files which need to be in $HOME/.vim/ ?
3) Is it sufficient to simply dump the unzip a new plugin file into $HOME/.vim/plugins when installing a standard vim plugin ?
Thanks
About debugging: in order to see whether vim has loaded your plugin you can use :scriptnames and also breakadd file /path/to/your/plugin (or breakadd file *your_plugin_name.vim: I never used absolute paths so I do not know what breakadd will do in this case). Other questions:
Described in :h initialization, precisely :h load-plugins.
Vim does not need any files at all (except vim executable, used shared libraries, dynamic linker and the kernel of course).
Follow installation instructions. Normally plugins are either extracted to ~/.vim or distributed as a singe file that should go to either ~/.vim/plugin (no s!), ~/.vim/colors, ~/.vim/ftplugin or such. I guess you should try to extract it to ~/.vim/plugin, but if archive contains some special directories like plugin/, ftplugin/, colors/, after/ (see /usr/share/vim/vim73 for a list) it is likely that it should go to ~/.vim. Also consider using vim-addon-manager, if plugin was posted on vim.org VAM is likely to be able to install it.
A few points.
How does vim look for plugins? See :help startup so see where and when vim looks for files to load.
Not really. Anything there is just personal customization. Vim will run fine without a .vim folder.
That all depends on the plugin. It sounds to me like the VimClojure plugin may be a little misleading. Do you have a link to the source you are using?
In any case, the first step I always take when attempting to debug a script is check the output of :scriptnames. This command will show you what scripts vim has loaded for the current session. If you see none of the files shipped with VimClojure, you probably made a mistake during the installation.
Another tip is that you really should look in to using a plugin manager such as vundle or vim-addon-manager, or at least the runtimepath manager pathogen. This seems to be the way of the future for vim configuration these days and it makes installing and managing plugins much easier. They also help to keep your .vim folder clean and organized.
The VimClojure directory should either be extraction on top of your .vim folder, or in a bundle folder if your using something like pathogen (which you should!). If you're starting from scratch, consider starting with vimclojure-easy (not to toot my own horn) which is a basic, full install of VimClojure with instructions.

Xcode source automatic formatting

As a C# developer, I have become highly dependent on the automatic formatting in Visual Studio 2008. Specifically, I will use the CTRL + K , D keyboard shortcut to force things back into shape after my sloppy implementation.
I am now trying to learn Objective-C and am missing certain features in Xcode, but probably none are quite as painful as the formatting shortcut. My Google searches have yielded nothing built in, though it seems there are some hacks. Am I missing something or does this feature not exist natively in Xcode?
That's Ctrl + i.
Or for low-tech, cut and then paste. It'll reformat on paste.
Unfortunately, Xcode doesn't have anything nearly as extensive as VS or Jalopy for Eclipse available. There are SOME disparate features, such as Structure > Re-Indent as well as the auto-formatting used when you paste code into your source file. I am totally with you, though; there definitely should be something in there to help with formatting issues.
I'd like to recommend two options worth considering. Both quite new and evolving.
ClangFormat-Xcode (free) - on each cmd+s file is reformatted to specific style and saved, easy to deploy within team
An Xcode plug-in to format your code using Clang's format tools, by
#travisjeffery.
With clang-format you can use Clang to format your code to styles such
as LLVM, Google, Chromium, Mozilla, WebKit, or your own configuration.
Objective-Clean (paid, didn't try it yet) - app raising build errors if predefined style rules are violated - possibly quite hard to use within the team, so I didn't try it out.
With very minimal setup, you can get Xcode to use our App to enforce
your rules. If you are ever caught violating one of your rules, Xcode
will throw a build error and take you right to the offending line.
In xcode, you can use this shortcut to Re-indent your source code
Go to file, which has indent issues, and follow this :
Cmd + A to select all source codes
Ctrl + I to re-indent
Hope this helps.
My personal fav PrettyC wantabe is uncrustify: http://uncrustify.sourceforge.net/. It's got a few billion options however so I also suggest you download UniversalIndentGUI_macx, (also on sourceforge) a GUI someone wrote to help set the options the way you like them.
You can then add this custom user script to uncrustify the selected text:
#! /bin/sh
#
# uncrustify!
echo -n "%%%{PBXSelection}%%%"
/usr/local/bin/uncrustify -q -c /usr/local/share/uncrustify/geo_uncrustify.cfg -l oc+ <&0
echo -n "%%%{PBXSelection}%%%"
You can use Command + A to select all content and next Ctrl + I to format the selected content.
I also feel xcode should have this function.
So I made an extension to do it: Swimat
Simple install by brew cask install swimat
You can give it a try, see https://github.com/Jintin/Swimat for more information.
Cmd A + Ctrl I
Or Cmd A And then Right Click. Goto Structure -> Re-Indent
Consider buying yourself a license for AppCode, an intelligent Objective-C IDE that helps iOS/OS X developers. AppCode is fully compatible with Xcode, but goes beyond Xcode in adding powerful features.
AppCode an Objective-C variant of the Intellij IDEA IDE from JetBrains. They are also authors of popular ReSharper extension to Visual Studio, which main purpose from here seems like a desperate attempt to bring a touch of IDEA experience to a Microsoft product.
AppCode is using its own code analyser which gives close-to-perfect refactoring and code navigation support. There is an ability to re-indent and completely reformat code also (although I still keep missing a couple of formatting settings in hard cases, but mostly it works well).
You might try the trial version, of course.
Swift - https://github.com/nicklockwood/SwiftFormat
It provides Xcode Extension as well as CLI option.
CTRL + i
that's it.
(no COMMAND + i)
You can also have a look at https://github.com/octo-online/Xcode-formatter which is a formatter based on Uncrustify and integrated into Xcode. Works like a charm.
You could try that XCode plugin https://github.com/benoitsan/BBUncrustifyPlugin-Xcode
Just clone github repository, open plugin project in XCode and run it. It will be installed automatically. Restart Xode before using formatter plugin.
Don't forget to install uncrustify util before. Homebrew, for exmaple
brew install uncrustify
P.S. You can turn on "after save formatting" feature at Edit > Format Code > BBUncrustifyPlugin Preferences > Format On Save
Hope this will be useful for u ;-)
I suggest using ClangFormat. In order to install, please follow these steps:
Install Alcatraz package manager for XCode
Supports Xcode 5+ & OS X 10.9+
After installation restart XCode.
Open XCode -> Window Menu -> Package Manager
Search (find) ClangFormat and install it. After installation again restart XCode.
Now at XCode menu you can use Edit -> Clang Format submenu for formatting.
You can choose different types of formatting. Also by enabling Format On Save you can gain auto-format capability.
If your Xcode version 3.x , you should use "User Script" With Uncrustify , here this a Example:
#!/bin/sh
echo -n "%%%{PBXSelection}%%%"
$YOURPATH_TO_UNCRUSTIFY/uncrustify -q -c $YOURPATH_TO_UNCRUSTIFY_CONFIG/CodeFormatConfig.cfg -l OC+
echo -n "%%%{PBXSelection}%%%"
add above to your Xcode "User Script".
if Xcode version 4.x , I think you should read this blog : Code Formatting in Xcode 4,
In this way , used the "Apple Services" , but it's not good enough , cause too slow experience, does anyone has the same thing ?
why apple drop "user script" .... xD
First, Examine XCode Preferences "Indentation" section. You can customize things quite a bit there...
For more fine grained control, refer to the XCode User Defaults document from apple. (May require a developer login to view). For example, I was able to disable the "indent on paste" by entering the following in terminal:
defaults write com.apple.XCODE PBXIndentOnPaste No
to read back your setting:
defaults read com.apple.XCODE PBXIndentOnPaste
This only works for languages with are not whitespace delineated, but my solution is to remove all whitespace except for spaces, then add a newline after characters that usually delineate EOL (e.g. replace ';' with ';\n') then do the ubiquitous ^+i solution.
I use Python.
Example code, just replace the filenames:
python -c "import re; open(outfile,'w').write(re.sub('[\t\n\r]','',open(infile).read()).replace(';',';\n').replace('{','{\n').replace('}','}\n'))"
It 's not perfect (Example: for loops), but I like it.
We can use Xcode Formatter which uses uncrustify to easily format your source code as your team exactly wants to be!.
Installation
The recommended way is to clone GitHub project or download it from https://github.com/octo-online/Xcode-formatter and add the CodeFormatter directory in your Xcode project to get :
Xcode shortcut-based code formatting: a shortcut to format modified sources in the current workspace
automatic code formatting: add a build phase to your project to format current sources when application builds
all sources formatting: format all your code with one command line
your formatting rules shared by project: edit and use a same configuration file with your project dev team
1) How to setup the code formatter for your project
Install uncrustify
The simplest way is to use brew:
$ brew install uncrustify
To install brew:
$ ruby –e “$(curl –fsSkl raw.github.com/mxcl/homebrew/go)”
Check that uncrustify is located in /usr/local/bin
$ which uncrustify
If your uncrustify version is lower than 0.60, you might have to install it manually since modern Objective-C syntax has been added recently.
Add CodeFormatter directory beside your .xcodeproj file
Check that your Xcode application is named "Xcode" (default name)
You can see this name in the Applications/ directory (or your custom Xcode installation directory). Be carefull if you have multiple instances of Xcode on your mac: ensure that project's one is actually named "Xcode"!
(Why this ? This name is used to find currently opened Xcode files. See CodeFormatter/Uncrustify_opened_Xcode_sources.workflow appleScript).
Install the automator service Uncrustify_opened_Xcode_sources.workflow
Copy this file to your ~/Library/Services/ folder (create this folder if needed).Be careful : by double-clicking the .workflow file, you will install it but the file will be removed! Be sure to leave a copy of it for other users.
How to format opened files when building the project
Add a build phase "run script" containing the following line:
sh CodeFormatter/scripts/formatOpendSources.sh
How to format files in command line
To format currently opened files, use formatOpenedSources.sh:
$sh CodeFormatter/scripts/formatOpendSources.sh
To format all files, use formatAllSources.sh:
$sh CodeFormatter/scripts/formatAllSources.sh PATH
PATH must be replaced by your sources path.
E:g; if project name is TestApp then the command will be
$sh CodeFormatter/scripts/formatAllSources.sh TestApp
it will look for all files in the project and will format all the files as configured in uncrustify_objective_c.cfg file.
How to change formatter’s rules
Edit CodeFormatter/uncrustify_objective_c.cfg open with TextEdit
Well I was searching for an easy way. And find out on medium.
First to copy the json text and validate it on jsonlint or something similar. Then to copy from jsonlint, already the json is formatted. And paste the code on Xcode with preserving the format, shortcut shift + option + command + v

Resources