How to change the EOL for all files from CRLF to LF - visual-studio-code

In Visual Studio Code, I have changed the default EOL (end-of-line token) from CRLF to LF, but this only applies to new files.
I would like to know how to change the EOL for all files at once as I have more than a hundred files and it will be hard to do it manually.

Run these. It works for me. Customize it with your requirements
git config core.autocrlf false
git rm --cached -r .
git reset --hard

To solve the problem in my project I used a Visual Studio Code extension called "Change All End Of Line Sequence", follow the process of the extension and then save all your files.
And that's it, hope it helps somebody still looking for a quick fix.

If you have a Node.js development environment and prettier installed, one way of replacing all CRLF for LF is by running prettier --end-of-line lf --write in the command line.
Another way is to set the endOfLine option to lf in the .prettierrc configuration file and place a script in your package.json like so:
...
"scripts": {
...
"format": "prettier --write"
...
}
...
Then, you just need to execute npm run format in your terminal and all files targeted by prettier in your project will be automatically changed and saved.

Related

Hiding the .gitignore using VSCode's Files:Exclude

I am trying to hide my .gitignore file in the VSCode project file explorer.
If I use this expression:
**/.*
Then .git, among a few others, will become hidden.
But when I try this:
**/.gitignore
I am still unable to hide it. I also tried a few other things, like these:
**/.git*
**/*.git*
**/*.gitignore
I feel a little silly, sorry! Thanks for your time, I sincerely appreciate it. It seems like a little silly thing, but I want to know!
The format in Visual Studio should be
**/.git
You could also make a global git ignore on your computer like this:
Make a hidden file in terminal called “.gitignore_global”
$ open ~/.gitignore_global
$ git config --global core.excludesfile ~/.gitignore_global
You can then edit this file by using vim or nano. Dealer's choice :)
vim ~/.gitignore_global
or
nano ~/.gitignore_global
and add your gitignore stuff like this:
.gitignore
*.gitignore
**/.gitignore*
The pros of making a global file is you will only need to do it once. Here is some info I found on it: https://medium.com/self-modifying-code/create-a-global-gitignore-step-by-step-for-macos-and-windows-31a765291409
I hope this helps!

How to block certain files from opening/previewing in vscode?

Im working on a large front end project in vscode. Whenever I have to discard/delete/move/... the output build.js files, it tries opening these files in the editor which takes ages to load and freezes vscode (more than 5k lines each).
The only work-around I currently have to delete these files, is to cd to their directory and run rm -rf ./*. But even then, I'm looking for a more convenient way of deleting these files without vscode trying to open them.
So my question: Is there a way, by editing the settings maybe, of telling vscode to ignore and never preview files that are of a certain type or filename like "*build.js" (I have multiple of these big files called a.build.js, b.build.js, ...
running git bash terminal on windows 10, vscode verson: 1.25.1
Edit
adding the following to User Settings
"files.exclude": {
...,
"**/*.build.js": true
},
Will not really help as it will not hide the files from my git changes. Right-clicking the files to discard, will still take ages to
complete.
Adding /public/dist* to .gitignore will also not work as
sometimes these files need to be pushed to the server, and sometimes
they just need to be discarded.
Because the vscode doesn't support this, for the "discard changes" scenario, you can use e.g. npm script, a gulp task, etc. and run it via vscode.
Example - npm script:
"scripts": {
"discard-build-files": "git checkout -- ./src/config/env/*.js"
}
Enable NPM Script Explorer:
In vscode preferences, set up this option
"npm.enableScriptExplorer": true
You should then get a new section inside your Explorer view.
Vscode currently doesn't support pattern filtering for previews.
The best I can think of:
Exclude your desired pattern altogether from the file explorer
Disable the single-click preview, and make it a more explicit action
via double-click
Ad 1.
Go to vscode's preferences and search for files.exclude.
Then edit the patterns to your liking.
Ad 2.
Go to vscode's preferences and search for workbench.list.openMode.
Then change the value from singleClick to doubleClick.

Managing End of Line in Visual Studio Code ESLint extension across multiple OS

I'm working on a React + Express + MongoDB project with repository on Github.
I'm using Windows as my main working station. However, I often commit some files with my macbook. Both using Visual Studio Code with same settings BTW.
I use auto formatting, format on save, and ESLint to keep a clean look before commit.
ESLint plugin highlights every end of line character everytime I pull from git.
In my .eslintrc.json file:
"rules": {
"linebreak-style": [
"error",
"windows"
]
}
I tried to remove "windows" or change it to "unix", but still have same issues.
When commit to git, it says:
warning: LF will be replaced by CRLF in .eslintrc.json.
Is it a way to make the end of line LF/CRLF consistent across multiple platform inside Visual Studio Code environment?
I noticed the end-of-line can be switched by clicking the CRLF words, and this is a global setting.

VS Code Error: spawn git ENOENT

I get the error Error: spawn git ENOENT when I try to view git history using https://github.com/DonJayamanne/gitHistoryVSCode on VS Code.. I'm very new to VS Code and github. I tried googling for solutions but I only found links about node.js which I don't understand at all..
We need to install Git to use the Git History (git log) extension in VS Code.
Otherwise we will see this when running git log.
If you have already installed Git, then make sure that it is available from the shell, for example by typing git --version.
Once you have Git installed properly, you will see this when running git log.
That means you need to set environment variable in system for git. After you set it well, the issue will disapper.
If your OS is Windows:
Try typing "git --version" in the system command line (do not use git bash by mistake). If you cannot see the version, it indicates that git is not added to the environment variables.
For example, my Git is installed on the disk "C:\", I need to add "C:\Program Files\Git" to the path of the environment variables.
Method 1:
Steps:
Edit environment variables -> System Variables
Edit Path,
add
;C:\Program Files\Git\bin\git.exe;C:\Program Files\Git\cmd;
to current value of Path (remove the beginning ; if redundant).
You need to adjust this file path according to your actual directory where git is installed.
Then restart your command line, and then try typing "git --version" again. If you can see python version now, try your vs code again, the issue you metioned will disappear.
Another method:
Reinstall your visual studio code with checking "Add to PATH (available after restart)".
I had the same issue on MacOS (running VS Cod 1.26.1). With difference to other info that I had found, I worked only after setting:
"git.path": "/usr/local/bin/git"
No success setting the path to null or any other.
I just got this error while trying to use the Worktrees tab from the GitLens extension. With git worktree list I found out I had some prunable worktrees, so it worked again after I ran this:
git worktree prune
In Mac OS you have to modify your settings.json. For me currently located in Users//Library/Application Support/Code/user/settings.json
or what it is the same ~/Library/Application Support/Code/user/settings.json
There set "git.path": "/usr/local/bin/git",
You can achieve the same inside Visual Studio Code going to the "Settings" Gear Icon > Settings Then search for git. Under Extensions go to Git and look for Path Click on Edit in settings.json
It will open the same file inside the editor
See the image for VSCODE
install git, and run git init
If you are getting this error from a React app created using Create React App, i.g. create-react-app nameOfYourApp, you need to setup CircleCI environment. More info here https://facebook.github.io/create-react-app/docs/running-tests
On your own environment
Windows (cmd.exe)
set CI=true&&npm test
set CI=true&&npm run build
(Note: the lack of whitespace is intentional.)
Windows (Powershell)
($env:CI = "true") -and (npm test)
($env:CI = "true") -and (npm run build)
Linux, macOS (Bash)
CI=true npm test
CI=true npm run build

Mercurial Eclipse Error

I am trying to use mercurial in eclipse. I downloaded mercurial eclipse plugin for this.
But, despite I had reinstalled it many times, it gives the same error, I put the screenshot below.
Checking encoding (cp1254)...
Checking extensions...
Checking templates...
Checking patch...
Checking commit editor...
Can't find editor 'notepad' in PATH
(specify a commit editor in your configuration file)
Checking username...
1 problems detected, please check your install!. Command line: hg -y debuginstall
I do not know how to handle this. Any help will be appreciated very much, thank you.
I encountered the same problem when I tried to run Eclipse x64 on Win 7 x64. The MercurialEclipse seems not able to access C:\windows\system32\ folder, although it has been specified in system PATH.
You need to specify the location of editor in the Mercurial.ini file. This file is located at c:\Users\<your_username>\mercurial.ini.
Under the username = ... line, add a line to specify the editor (see following). Remember not to put quotes around the path.
[ui]
username = <username>
editor = c:\Windows\System32\notepad.exe
(Note: similar to bug 13505 in Mercurial Eclipse project)
The Eclipse inherits the path from your current session.
Open a DOS session, and check if said session does have notepad in its path (which it should considering notepad is in C:\Windows\system32\notepad.exe). Make sure C:\Windows\system32 (or %SystemRoot%\system32) is in first position in your PATH (in case of side effect with other paths with spaces or special characters in it).
If the path is correct, then launch the eclipse from that command-line DOS windows, and see if the problem persists.
The OP emre reports its %PATH% being:
C:\Program Files\NVIDIA Corporation\PhysX\Common;
C:\Program Files\Java\jdk1.6.0_20\bin;
D:\eclipse-java-helios-sr1-win32\eclipse\android-2.2_r0-windows\android-2.2_r0-windows\tools;
C:\Program Files\Java\jdk1.6.0_20\bin
In other word, no %SystemRoot%\system32.
You need to edit the System variables in the Environment variable settings of Windows, and add in the first place in the PATH variable:
%SystemRoot%\system32
Then you can open a new DOS session, launch eclipse from there and ot should work fine.
i had the same problem and searched for hours till i tried to escape the backslash in the path for the editor.
so i edited the mercurial.ini (on my win7) like this:
[ui]
username = <username>
editor = c:\\Windows\\System32\\notepad.exe
and it worked.
Three additions:
It seems that Tortoise HG 3.3 configuration utility added my editor
setting to [tortoisehg] section rather than the [ui] section of
mercurial.ini For Eclipse Mercurial to work, the editor path must also be in
the [ui] section. Otherwise, eclipse will have this error.
using forward slash suitably substitutes for the escaped backslash
On Windows 8.1, notepad easily starts from the command prompt (on
system path) and yet the error above still occurs. In my hands the
general system path advice given above seems off target
One other thing to look at is the HGEDITOR environment variable, which overrides the editor setting in mercurial.ini. I had HGEDITOR set to C:\Windows\System32\notepad.exe, which didn't work (due to the unescaped backslashes), and all my changes to mercurial.ini were ignored. Changing HGEDITOR to C:\\Windows\\System32\\notepad.exe finally got rid of the Mercurial Eclipse errors.