VSCode aggressively deletes all code after unconditional return (no-unreachable) - visual-studio-code

Sometimes I have code like this:
function x() {
func1();
func2();
func3();
}
and when I'm debugging I put a return on the third line if I don't want/care about func2/func3:
function x() {
func1();
return;
func2();
func3();
}
On save, VSCode very rudely deletes func2 and func3!!! Yes I know it is unreachable code, but I am only adding that return there temporarily. A yellow underline would be nice. I can't seem to turn it off. Is there any way to turn it off or am I using it wrong? It seems like a really silly and overzealous feature to me.

Finally fixed the issue.
In settings.json (~/.config/Code/User/settings.json)
I had:
"source.fixAll": true,
changing this to
"source.fixAll.eslint": true,
Stops the editor removing the unreachable code unnecessarily

Related

How do i change the way visual studio code auto corrects curly braces?

I prefer my curly braces looking like this:
function eg()
{
}
But when I try to format my code, vscode auto corrects to this:
function eg() {
}
Is there any plugins that I can download or setting that I can tweak to change this?
Try :
"javascript.format.placeOpenBraceOnNewLineForFunctions": true;
"javascript.format.placeOpenBraceOnNewLineForControlBlocks": true;
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": true;
"typescript.format.placeOpenBraceOnNewLineForFunctions": true;

Prevent VS Code from changing indentation on Enter

Let's assume I have a JavaScript file with the following content and the cursor placed at the pipe symbol (|):
class ItemCtrl {
getPropertiesByItemId(id) {
return this.fetchItem(id)
.then(item => {
return this.getPropertiesOfItem(item);
});
}|
}
If I now hit enter, the code changes in the following way:
class ItemCtrl {
getPropertiesByItemId(id) {
return this.fetchItem(id)
.then(item => {
return this.getPropertiesOfItem(item);
});
}
|
}
It wrongly aligns the closing curly brace with the return statement, when it should be aligned with the method definition. I know that the formatting inside the function is not the best but I still would rather disable that feature to prevent weird things like that from happening.
I already set editor.autoIndent to false but it still keeps happening. Is there any other way, how I can turn this feature off entirely? (or make it work in a smarter way)
In VS Code 1.17, this bug caused "editor.autoIndent": false to not work
This should be fixed in VS Code 1.18

how to get vs code `ENTER` to respect/cleanup whitespace

BTW, this is not asking how to format code in VS, or the keybinding, so please don't mark it duplicate of this. It is specifically about formatting during typing.
Given the following code:
if(true) {
console.log('hello');
console.log('world');
}
If I go to the end of the 'log hello' line, hit DEL to bring 'log world' to the end of the line I will get (with | representing my cursor):
if(true) {
console.log('hello');| console.log('world');
}
Now, if I hit ENTER, I will get:
if(true) {
console.log('hello');
| console.log('world');
}
In other editors I would expect the white space to be 'eaten up' and the line to be reformatted, looking like this again:
if(true) {
console.log('hello');
|console.log('world');
}
Any thoughts on how to change this behavior?
This would also (hopefully) handle the pasting in of code that was not properly formatted, for instance, if I wanted to paste the following in:
console.log('arrrgg');
console.log('matey');
To the end of the if, I would see:
if(true) {
console.log('hello');
console.log('world');
console.log('arrrgg');
console.log('matey');
}
Instead of:
if(true) {
console.log('hello');
console.log('world');
console.log('arrrgg');
console.log('matey');
}
Certainly, I can hit Shift-Alt-F and reformat, but I don't always want to reformat an entire file....
I think I have been spoiled with VS and WebStorm automatically cleaning up and reformatting code quickly. Not sure if that is a valid
Is this even possible in Code?

How can I prevent tinyMCE's paste event?

I need to prevent the paste event of tinyMCE if the length of the current content of editor plus the length of the words to be pasted exceed the specified limit. How can I do it? Thank you.
I was wrong. I dont need to prevent or disable paste in tinyMCE to do this. I used their paste plugin and modified the content before it is pasted.
function(pl, o) {
...
if(len > limit) {
o.content = '';
}
}
I think it's better to use the paste_preprocess function.
It's a old question, but others may stumble on this problem.
Here is the solution:
paste_preprocess: function (plugin, args) {
args.content = ''; // modify or do anything with the clipboard data
},
Do it inside, init

JsTree with dnd plugin, always copy

I have 2 trees using jsTree and dnd plugin.
I want that each drag operation to be a copy instead of a move.
There is a "copy_modifier" which works Ok when pressing a modifier key, but I want copy to be the default behavior without the modifier.
Any ideas?
Thanks,
Adrian
Found a solution on http://groups.google.com/group/jstree
I added the following section when configuring jsTree:
"crrm": {
"move": { "always_copy": "multitree" }
}
Hope this helps,
Adrian
another solution for the new version. it works, but not fully tested.
"core": {
"check_callback": function (operation, node, node_parent, node_position, more) {
if (more) {
if (more.is_multi) {
more.origin.settings.dnd.always_copy = true;
} else {
more.origin.settings.dnd.always_copy = false;
}
}
return true;
}
}
Adrian's solution won't work with the new versions.
There's that dnd plugins always copy flag
dnd.always_copy
Setting this flag will make all drag and drops copy operations instead of move. But if you are looking for a solution where you need internal tree elements to be moved on dnd but inter tree dnds to be copies than here's a hack:
Keep a global variable flag on your page
Handle copy_node.jstree events and update your global flag from
data.is_multi (data is the second arg of the event function)
Implement check_callback function and if operation is delete_node and your flag is set unset your flag and return false, preventing deletion from the dnd.