WebStorm 2016 auto format code based on custom requirements - formatting

I am trying to auto format my code to pass JSLint violations. I know I can press Ctrl + Alt + L, but that doesn't format the code in the way I want.
For example, JSLint complains about variables not all being defined on top of the function. I would want my code formatter to move those variables to the top of the function (or having the linter not complain about that would be better). Another example would be the linter complaining about unused variables. In this instance, I would want the formatter to remove the unused variables. Of course, spacing issues should also be fixed as the default formatter does.
If this is not possible within WebStorm, can I edit a JSLint config file to turn off some warnings (like defining all variables on top of the function).
I am using grunt-jslint.

Unfortunately WebStorm doesn't support importing code style preferences from JSLint (WEB-2227). Neither it supports auto-fixing JSlint errors. And most JSLint rules are hardcoded and thus can't be disabled (see http://www.jslint.com/help.html for available options; they can be setup right in your Gruntfile - see http://derpturkey.com/jslint-with-grunt/)
I'd say that JSLint is a bit out of date, and it's unlikely that more support for it will be added to WebStorm. Try using ESLint instead - it's much more flexible, and is deeply integrated in webstorm - https://blog.jetbrains.com/webstorm/2017/06/webstorm-2017-2-eap-172-3198/, https://blog.jetbrains.com/webstorm/2016/09/webstorm-2016-3-eap-163-3983/. And it can be set up as a part of Grunt build process - https://www.npmjs.com/package/grunt-eslint

Related

Where is the setting for highlighting unused variables and constants in Visual Studio 2022?

I am working in a C# project where this has been turned off.
I can't find out how to turn it on again.
It's pretty hard to google as it's default behavior, and no sane person would turn it off...
Did you perhaps change your compiler warning level?
Unused variables should have the warning of CS0168. If you look at that page, the title is "Compiler Warning (level 3) CS0168".
In solution explorer, right click your project and go to Build and check your Warning Level:
If you set it to anything lower than three, then the CS0168 warnings will never be shown. Also, just below the drop down is a suppress warnings text box. Make sure you don't have CS0168 in that text box.
Are you using an .editorconfig file?
If you are using an .editorconfig file, you may have suppressed this particular warning. Removing that suppression should resolve this as well. It would look something like this in your .editorconfig file:
[*.cs]
# CS0168: Variable is declared but never used
dotnet_diagnostic.CS0168.severity = none

IntelliJ Code Style Indentation Options seem to be ignored [duplicate]

I've been attempting to get my Intellij IDEA to confirm to a google-like Java standard - however both imports and manual settings seem to be ignored.
Here's how my indentations are currently set:
However my code still formats at 4 spaces, and when I reformat it goes to 4 spaces as well.
Thanks in advance!
This is the setting for your GoogleStyle scheme. But your project most likely doesn't use it. It's not enough to just select it in the combobox. You need to import this scheme into your project.
Click Manage... and Copy to Project, and it should work as expected.
Also, make sure you're setting language-spefic settings, so instead Code Style select Code Style > Java.

Disable reporting erros for path checking in IntelliJ

IntelliJ show the squiggly red underline under require paths (node.js) that it can't find. In my case, I have a file that is copied to a particular place on installation. Their location in the source has nothing to do with their location in the installation. Its especially annoying because intelij shows that red underline for all folders in its file browser.
var x = require('./some/invalid/path')
I like that it has this check, but I want to disable it for this file since it doesn't make sense for that case. How can I do this, ideally in intelliJ 12?
That's how you suppress an inspection for a class, method or statement:
Place your cursor inside the warning statement, press Alt + Enter, choose the entry that describes your warning, and from the sub-menu select Suppress for class or statement.
You will find more info on the IDEA webhelp.
I found a dumb way to do it - make the require path an expression rather than a simple string literal like this:
var x = require('./some/invalid/path'+'')
I guess it confounds intellij enough that it just says "screw it its probably fine".

Intellij exclude file from being compiled

I am trying to exclude a particular file in my project from being compiled.
According to the Intellij IDEA documentation you do this by "marking the file as plain text".
However, the context menu in the project view where this functionality is supposedly located has no such action. I am using version 13.02 of Intellij. Here is what my context menu looks like:
Under File > Settings > Build, Execution, Deployment > Compiler > Excludes, add an entry.
Any attempts to run a path specified here will result in a ClassNotFoundException, and a very important class indicator as well.
Just to compound on Makoto's answer (would comment but don't have reputation), it looks like this feature does not apply to classes (.java) or assets (images)...for these types of files, it looks like you will need to actually go to the compiler and explicitly state that the file(s) should be excluded.
However, for .htm, .xml, or really anything that isn't a class or asset you will find and can use the 'Mark as plain text' option.
Edit: It looks like you can also go to the 'Messages Make' error / warnings view and Exclude from there, a little less work IMHO.
The answer that #Makoto has given is pretty much the way to go, but in case that you are like me and you get easily both distracted and frustrated looking for that menu, you could use this shortcut:
press ctrl + shift + a , and in the input box that appears type excludes, and select the first item that appears.

intellij shortcut for creating method stub

I've recently switched over to intellij for scala development.
I'm having trouble finding the following shortcut:
In eclipse, I could type a method call e.g.
method("hello", 1)
and press <command>1 to have eclipse popup a suggestion to let me create a method stub.
Is there such a shortcut in intellij?
Use Alt+Enter (Show Intention Actions in Settings | Keymap).
Verified, works fine in IDEA 11.0.1 with the current Scala plug-in:
Activate Type aware highlighting (See the [T] symbol in the image) and
Set Highlighting level to Inspections
Then it is possible to use alt + enter (similar to Ctrl+1 in Eclipse) to show menu, which has create method option.
Why isn't it enabled by default?
The feature is in beta (or maybe in alpha) and sometimes may report "false errors" in regular code. Usually, such "errors" "found" only in a truly complex code, and, normally, everything works just fine.
Scala plugin doesn't rely on compiler to analyze code. We're implementing our own model of the language, and sometimes it's challenging, especially when it comes to Scala's type system and type inference (to size up the problem, you may try to formally "infer" a type of "foo".map(_ + 1) expression by hand).