turn off "use spaces, do not use tabs" in a jslint extension for VSCode - visual-studio-code

I got a VSCode JSLint extension and I got its settings pointing to an .eslintrc file where I have the following specified for indentation:
{
...
"indent" : [1, "tab"]
...
}
The problem is, it's still putting the squiggly green lines where I have some tabs and I can't tell where anything's going wrong with any settings.
I have evidence the rc file is actually working because I was successfully able to change it from single to double-quotes. However it appears to completely ignore the indentation setting inside my VSCode.

You could simply disable the use_spaces rule. It's separate from the indent rule you changed. A bit over an oversight from JSLint.
There were quite a few complains about that rule, even here on SO. Quite a few people (not only on SO) suggest switching to JSHint instead. Personally I've only used ESLint and therefore don't know much about the differences, and I'd suggest checking those for yourself anyway.

Related

YAML file formatting in VSCODE

I just started using VSCODE and faced with an annoyance every time I paste in YAML code in an existing YML file.
Basically the editor seems to auto format the document and in doing so messes up the significant spaces in the document. This causes builds in Azure Devops to break.
Although VS code formats the document nicely into collapsible regions, the formatting annoyance makes it hard to use.
Any help would be appreciated.
BEFORE:
AFTER:
I fixed this by changing editor.autoIndent settings for yaml and dockercompose language
"[yaml]": {
"editor.autoIndent": "advanced"
},
"[dockercompose]": {
"editor.autoIndent": "advanced"
}
In VsCode, press ctrl+shift+p (cmd+shift+p in Mac), and search for Preferences: Open User Settings (JSON). There I added this line:
"[yaml]": {
"editor.defaultFormatter": "redhat.vscode-yaml"
},
I picked it because it contains the word yaml, so I figured it must be yaml specific.
Anyhow, it seems to do a pretty good job for me.
Turn off the setting format on paste. This is a global setting, but plugins sometimes have their own, so if you're running a formatter like prettier, you'll need to see whether this is even an option with that plugin.
Looks like the problem is in the first line. Maybe when you copy the code, you're not copying the indentation on the first line.
One trick I use, is copying from the end of the preceding line, so the copied code starts with a newline, and then the paste is perfect.
Or just add the indentation on that first line, after pasting.

'Variable' is declared but its value is never read VScode

I recently switched from Sublime to VScode - one thing that's been bothering me is that when functions and variables are not used, they are grayed out like a comment, with the message on hover,
'myVariable' is declared but its value is never read.
I can't find any setting to disable this syntax behavior in 'user settings', and I don't have an linter installed either. How do I change this?
Setting :
"javascript.showUnused": false,
and
"typescript.showUnused": false,
if you are using those languages will eliminate the gray font and the hover message.
Additionally, for those using esLint you will get the squiggly under unused variables unless you put
"no-unused-vars": 0,
in .eslintrc.json file in your workspace.
This not exactly a problem, after reading here I got to the conclusion this warning is actually usefull.
when it happen you know there is no reference to the variable declared on your code.
it ignore mentions made at other files pulling the script, so you got keep this in mind.

IntelliSense autocomplete "on dot" choosing incorrect symbol

I'm editing a stand-alone JavaScript file in VSCode 1.19.2. I do not have a project set up, and no jsconfig.json to control it.
I enter the following code into an empty editor:
var scene = new THREE
Intellisense starts to kick in and gives an auto-complete list.
When I press "." (expecting my code to become THREE.), IntelliSense takes this as a sign that it gave me the right answer, and changes my code to:
var scene = new HTMLHRElement.
The full string "THREE" wasn't even in the list, but IntelliSense seems to be using some kooky regular expression to predict what the user actually tried to type--the letters are all there in the applied symbol, but they're all split up and in different cases.
For me, this is counter-intuitive (not to mention frustrating beyond words, because I type this string a lot), but everything I've found so far is people asking for this feature. So, I'm looking for a work-around for me.
Is there any way to turn off "complete on dot," or maybe a similar setting to force IntelliSense autocomplete only on tab? Also feel free to correct my terminology, in case that was preventing me from finding the correct answer.
JavaScript and TypeScript treat . as accepting the current suggestion by default. You can disable this by setting:
"editor.acceptSuggestionOnCommitCharacter": false
or, if you only want them disabled in js:
"[javascript]": {
"editor.acceptSuggestionOnCommitCharacter": false
}

how to freely format comments in cc-mode

I'm quite new to cc-mode and I'd like to configure it to allow me to freely format and use tabs in multiline comments. This is important to me because I want to use cog.py in my source file and need to be able to format the python source in the comment correctly. I'd be ok with comments not beeing autoindented at all, however I'd like to keep auto indenting the rest of the source code.
Example:
...
/*
[[[cog
import cog
for x in ['a','b','c']:
>cog.outl(x)
]]]
*/
...
In the line marked with > I'd like to press TAB to indent the line. cc-mode simply does nothing at all if i do so. I could use spaces there (which is inconvenient) but every (semi-)automatic re-indentation of this block would cause the spaces to vanish and therefore the python code to be incorrectly indented (which is what happens if i happen to press tab somewhere on this line after indenting it with spaces).
I tried to start emacs without my .init to be sure this is default behavior and not modified by my configuration so far. I've done google searches and read the documentation of the cc-mode variables / functions I stumbled upon (cc-mode online docs) while searching for a solution (i.e. c-indent-comments-syntactically-p, c-indent-command, c-tab-always-indent,...) but none of these seemed to solve my question.
EDIT1:
Thanks to abo-abo's idea of a "multi-major-mode" setup i've stumbled upon mmm-mode and have set up automatic switching to python mode for a cog section, which fixes most of my problems.
The only remaining problem is reindenting the whole file or a region containing a cog section. Can I somehow tell cc-mode to not change anything in comments while reindenting the file? mmm-mode + that would be a perfect solution for me.
You can use M-i to force a tab indent on the lines that you want, so you can use it to indent your comments.
You can also change your comments to use // instead. Just select your python code snippet, and do M-x comment-region:
// def foo(x):
// print 'hi'
Then the autoindent won't mess up your indentation.

Unexpected 'INDENT' in CoffeeScript Example Code

As I was playing around for the first time with CoffeeScript, I ran in to a problem. In order to debug my problem, I tried replacing my whole file with one of the example bits of code from the coffee script site:
kids =
brother:
name: "Max"
age: 11
sister:
name: "Ida"
age: 9
However, when I try to compile that code, I get:
Error: In coffee/main.coffee, Parse error on line 3: Unexpected 'INDENT'
at Object.parseError (/usr/lib/coffeescript/parser.js:501:11)
at Object.parse (/usr/lib/coffeescript/parser.js:573:32)
at Object.compile (/usr/lib/coffeescript/coffee-script.js:23:22)
at /usr/lib/coffeescript/command.js:99:27
at /usr/lib/coffeescript/command.js:72:28
at fs:84:13
at node.js:773:9
In coffee/main.coffee, Parse error on line 3: Unexpected 'INDENT'
Since this is code from the CoffeeScript site, I assume the code itself isn't the problem. However, the compiler also seems to be working properly; if I compile:
a = 2
it generates a file with:
(function(){
var a;
a = 2;
})();
as expected. So in other words, the code is good, the compiler is good, and yet somehow I'm getting this Unexpected 'IDENT' error ... can anyone help me understand what is going on?
I am pretty sure this is a tabs-vs-spaces issue. Tell your editor not to convert spaces to tabs if it does that. Also, go through your code with the cursor and make sure it doesn't jump over blank areas.
The issue is that while normal editors see a tab as equivalent to two or four spaces, coffeescript sees it as one space, so the indentation gets messed up.
If this all doesn't help, make sure you have a recent coffeescript version, e.g. 1.1.0 or newer.
If you are using a JetBrains IDE (IntelliJ, PHPStorm, etc) the change of setting that worked for me is:
File > Settings > Project Settings > Code Style > CoffeeScript > Tabs
and Indents
Tick "Use tab character" & "Smart tabs"
Code is fine. Make sure you haven't messed up the whitespace (strange control chars showing as blanks, tabs or similar).
If you have the same problem, but your indentation is okay,
then you must be suffering from bug 2868.
Basically, the error is misleading. Check for indentation
errors in the required files.
When in Atom you can automatically convert tabs to spaces:
Packages > Whitespace > Convert Tabs to Spaces
You can resolve this two ways
1. IF using webstorm File->Default Settings as said above
2. Other workaround, is to use a different editor like Sublime, there u can press enter on earlier line and it will auto tab it for you with spaces