How to prevent WebStorm from prefixing imports with "#root/src" - webstorm

WebStorm version 2018.3.2
Already played around with these settings
Editor > Code Style > TypeScript
Editor > Code Style > JavaScript
Imports tab - nothing seems to work.

Related

Curly braces to new line - Prettier

So, I'm making a excercise to college in C
I like to use Prettier, and I never know how to
tell Prettier to don't push curly braces to new
line.
I want this
if (x > y) {
// Code
}
Instead
if (x > y)
{
// Code
}
Regarding Prettier:
Prettier doesn't allow you to change that setting. They are an "opinionated" formatting extension, and you subscribe to their opinions when you use it.
I unfortunately don't know C, so I can't tell you how to fix it in your specific case.
However,
For everyone that came to this post looking for the C# answer in VSCode:
Locate your .editorconfig files in your project
Locating .editorconfig files
Add the following line to the config files for both dotnet 5 and 6:
csharp_new_line_before_open_brace = all
File > Preferences > Settings
Enable Editor Config Support
Enabling editor config support
Enable Roslyn Analyzers
Enabling Roslyn Analyzers
Make sure your default formatter in VScode is "C#"
Setting the default formatter
Restart VS Code and the Omnisharp server
Restarting the Omnisharp server
Additionally, see all formatting options which can be added to the .editorconfig file below:
Read the documentation

Emmet not working in WebStorm in .php files

I just started using WebStorm. Emmet is working perfectly with .html files, but not with .php files. Any fix for that?
Problem: writing .container + clicking on Tab should give <div class="container"></div>, but it's not doing that in PHP files. In HTML files it's working perfectly.
In WebStorm, .php files are simple text files highlighted using textmate bundles; HTML language is not injected there, so advanced HTML features do not work.
As a workaround, you can try modifying Zen HTML live templates context in Settings | Editor | Live Templates by appending Other to it, like:
but this has to be done for each template separately

How to make WebStorm format code according to eslint?

I've specified eslint configuration for my WebStorm project. But it does not seem to apply to code reformat feature. For example, it continues to format import { something } from 'somewhere' as import {something} from 'somewhere'.
Is there a way to make WebStorm to format code according to eslint configuration?
(Described steps and screenshots are from IntelliJ IDEA 2017.2)
You can add a keyboard shortcut to action 'Fix ESLint Problem'. Ensure plugin 'JavaScript Support' is installed and enabled.
First got to Preferences | Language & Frameworks | JavaScript | Code Quality Tools | ESLint and enable it. You will need to define your 'Node interpreter', 'ESlint package' and optional 'Configuration file'.
Next go to Preferences | Keymap and search there for 'eslint'. Now you can add for example the shortcut 'control + shift + L'.
If you are using a newer version of WebStorm like me, you can import the ESLint rules into WebStorm by right-clicking on the .eslintrc.js (or other ESLint configuration files) and then click the "Apply ESLint Code Style Rules" option as shown here.
Do note as the time of writing, you will also need to exclude the indentation of <script> tags in the "Settings" or "Preference" Menu. An awesome guy wrote a short write-up on how to do that.
I have just installed WebStorm 2017 and I do not know if this works for WS 2016. Instead of pressing Option + Command + L, to reformat your code, you could press Option + Enter when your cursor is close to an ESLint error. This will open up the context menu, then select the "ESLint: Fix current file"
Solved for me in 2021 :
WebStorm is using Prettier package and there is an option:
Preferences | Languages & Frameworks | JavaScript | Prettier -> On 'Reformat Code' action
Now WebStorm uses eslint rules to reformat the code on Reformat Code hotkey.
Update: the answer is obsolete. The best solution is described in https://stackoverflow.com/a/46099408/1057218
Unfortunately you cannot import eslint code style configuration (WEB-19350) but you can configure the code style manually.
See the settings: "File | Settings | Editor | Code Style | JavaScript"
For import braces:
"Spaces" -> "ES6 import / export braces"
A temporary fix for now that I've been using is to export my ESLint config to JSCS. It works pretty nicely with WebStorm and PHPStorm!
I used this package called Polyjuice, and here is the output from my eslint config.
The best way is to automate it by using a Macro.
1. Go to Edit | Macro | Start Macro Recording
2. Go to File | Save All
3. Press Strg + Shift + A
4. Search for eslint and run it.
5. Go to Edit | Macro | Stop Macro Recording
6. Go to Edit | Macro | Edit Macros and remove everything expect the two Action:...
7. Go to File | Settings | Keymap | Macros and add Strg + S on the Macro
This works great and makes it a lot more easier to work :)
For those still in trouble, I did all the steps of the answers above and it was not working at all.
For me the problem was the Node version I was using in my terminal (12.x) vs the .nvmrc and "engine" in the package.json of the project
After the two changes pointed above my eslint returned to work.
p.s: I'm assuming you have all the dependencies installed as well as a .eslintrc.* in the root of your project

How to import code formatting settings from tslint.json in webstorm?

Is it possible to import formatting settings (Settings => Editor => Code Style => Typescript) from my tslint.json file in webstorm? I use rules directory "node_modules/codelyzer" in my tslint.json file
Since 2017 WebStorm version, it's possible to Apply code style.
Just open tslint.json and WebStorm will ask if it can import it.
Read it about it in WebStorm 2017.1 EAP, 171.2455: improved integration with TSLint
It's not possible at the moment. You can vote for and follow the updates on this feature request: https://youtrack.jetbrains.com/issue/WEB-19481
As of 2018, you can manually apply TsLint settings:
Find your tslint.json file in the Editor or File tree (can also be a tslint.yaml)
Right click the file (again, this can be the Editor pane or the file in the tree)
Select Apply TSLint Code Style Rules. (should be the last option)
The Event Log should be updated with:
TSLint: The project code style and editor settings were updated based on 'tslint.json'.
More from JetBrains (with pictures):
WebStorm Help | Importing code style from a TSLint configuration file

Eclipse spelling engine does not exist

I'm using Eclipse 3.4 (Ganymede) with CDT 5 on Windows.
When the integrated spell checker doesn't know some word, it proposes (among others) the option to add the word to a user dictionary.
If the user dictionary doesn't exist yet, the spell checker offers then to help configuring it and shows the "General/Editors/Text Editors/Spelling" preference pane. This preference pane however states that "The selected spelling engine does not exist", but has no control to add or install an engine.
How can I put a spelling engine in existence?
Update: What solved my problem was to install also the JDT. This solution was brought up on 2008-09-07 and was accepted, but is now missing.
The CDT version of Ganymede apparently shipped improperly configured. After playing around for a while, I have come up with the following steps that fix the problem.
Export your Eclipse preferences (File > Export > General > Preferences).
Open the exported file in a text editor.
Find the line that says
/instance/org.eclipse.ui.editors/spellingEngine=org.eclipse.jdt.internal.ui.text.spelling.DefaultSpellingEngine
Change it to
/instance/org.eclipse.ui.editors/spellingEngine=org.eclipse.cdt.internal.ui.text.spelling.CSpellingEngine
Save the preferences file.
Import the preferences back into Eclipse (File > Import > General > Preferences).
You should now be able to access the Spelling configuration page as seen above.
Note: if you want to add a custom dictionary, Eclipse must be able to access and open the file (i.e. it must exist - an empty file will work)
Are you using the C/C++ Development Tools exclusively?The Spellcheck functionality is dependent upon the Java Development Tools being installed also.The spelling engine is scheduled to be pushed down from JDT to the Platform,so you can get rid of the Java related bloat soon enough. :)
Just a word of warning: If you follow the advice to replace the preference as above, it will affect spell checking if you also use Java. I think all I needed to do was change the "Select spelling engine to use" to the C++ engine (near the top of the preference setting on the preference page General->Editors->Text Editors->Spelling).