space after function in visual studio ide - javascript

How can I set up the designed in visual studio to put a space after my javascript functions?
At present when I press the return key I get this
var myfunc = function() { .... };
When I want this
var myfunc = function () { .... };
Know its a setting somewhere but cant find it - will help with my JSlinting!

In VS 2010 you can't.
The options you have are found at "Options-> Text Editor -> JScript -> Formatting", but that is not one of the options available.
Here's the options you have:
Automatic Formatting
Format completed line on Enter
Format completed statement on ;
Format completed block on }
Format on paste
New lines
Place open brace on new line for functions
Place open brace on new line for control blocks
Spacing - section that would have what you're after
Insert space after comma delimiter
Insert space after semicolon in 'for' statement
Insert space before and after binary operators
Insert space after keywords in control flow statements

You can't do it with VS. I am using VS 2010 and it permit you to write formatting rules going on Tools -> Options and then select Text Editor in the list on the left.
You can define rules like the one you want for languages like C# but not for javascript.

Related

How to turn off VSCode formatting for certain sections of a file

I have the following JS in vscode:
let page = document.getElementById("page");
$$$$<h1 style="text-align:center">[this.courseNum] : [this.name]</h1>
let hr = document.createElement("hr");
/// more Vanilla JS code...
I'd like to be able to turn off the formatting for that weird JS/HTML mixture above; the line preceded by $$$$. Is there anyway to turn off formatting for a line preceded by a series of characters (such as the #formatter: off tag that Eclipse uses?). Or, more generally, is there a way to turn off the formatter for certain regions in a file?

Changing indentation style in atom editor (javascript code)

I've used microsoft's vscode for some months, but since 2 updates the indentation is broken for me, without a way to fix it. I therefore consider switching to atom. I was working with atom before, and never had this problem, but now it seems to have the same (wrong for me) behaviour as vscode:
if (xxx) // press enter here and type 'something();'
should result in
if (xxx)
something();
but it results in
if (xxx)
something();
It will work completely finde if you add { }, but without them its like the above.
How can I fix this in atom? The basic identation settings don't seem to cover this.
My way of doing this si to always use {} (also because I'm using linter-standard-js) That way, you type
if (myCondition) {}
When you return between the accolades, you get the following
if (myCondition) {
// indented and here you go
}
You can add extra conditions for Atom to change the indent level in your config.cson file, following the lead of the packages that define those conditions in the first place. Add the following to the top level of config.cson and Atom will automatically add a level of indentation after a line that matches the regular expression if\s*\(.*\)$. If you already have a .source.js entry, make sure to change that instead of just pasting this bit in.
'.source.js':
editor:
increaseIndentPattern: '(?x)
\\{ [^}"\']* $
| \\[ [^\\]"\']* $
| \\( [^)"\']* $
| if\\s*\\(.*\\)$
'

Set the beginning of a curly brace to a new line in Visual Studio 2015?

I am writing/debugging Javascript code in Visual Studio 2015 and hate to have the curly braces of a function starting at the end of an expression (btw: why is it like this as it is way less clearly arranged?) like:
$scope.adjusted = function () {
console.log(adjustedYesNo);
}
Instead I want to have it started by default (and after each change) in the beginning of a line like:
$scope.adjusted = function ()
{
console.log(adjustedYesNo);
}
Where to set such a setting in Visual Studio 2015?
In the menu go to...
Tools > Options > Text Editor > JavaScript > Formatting > New Lines
Set the options as required in there. You can do this individually for each of the supported languages.
Go to:
Options -> Text Editor -> Javascript -> Formatting - > New Lines ->
Braces
and there are two checkmarks about braces on new line

Replace / restrict non-standard characters in CKEDITOR

I have a CKEDITOR instance (version 4.5.7) into which users input content. This content posts to a database field with the collation SQL_Latin1_General_CP1_CI_AS.
The problem comes when a user pastes text from Word or a similar rich-text editor. Two characters in particular get malformed when they hit the database: ” (”) and – (–).
I have already set config.entities to false to prevent the characters from being converted into their HTML equivalents. Now I'm looking for a place where I can intercept the process to find/replace any offending characters. Although the javascript for this sort of thing is easy enough ( text = text.replace('”', '"') ), I'm not sure where to put it in order to make this happen. I've tried placing it in various places within the CKEDITOR.htmlParser.basicWriter function, but nothing so far has worked.
This seems like it would be a fairly common problem - is there perhaps a way to set collation on the editor so it matches the database?
Thank you for any advice.
I kept plunking away in the basicWriter function until eventually I was surprised to find one place that actually does work. Basically, this is the process I used to solve this problem without editing ckeditor.js
Download and open an uncompressed version of the ckeditor.js file.
Locate and copy the entire CKEDITOR.htmlParser.basicWriter function into the bottom of your config.js file. This basically redefines the function, overriding the real one but allowing us to make customizations to it without necessarily breaking future updates.
In the copied function within config.js, locate the getHtml section and customize the html variable before it gets returned. Below is a template to help you locate this section
getHtml: function( reset ) {
var html = this._.output.join( '' );
// this is where we can replace individual characters or make other
// customizations
html = html.replace('”', '"');
html = html.replace('–', '-');
if ( reset )
this.reset();
return html;
}

textmate reformat with 2 spaces

I've set textmate to use softtabs 2 spaces on my file. But when I try to reformat the entire document, it uses 2 hard tabs as the indents.
Regular indents work as I want it to, just the document format doesn't. Anyway to get textmate to be obedient?
Thanks.
The JavaScript bundle's "Reformat Document / Selection" command is passing the document's text to the js_beautify function in the bundle's beautify.php file (found on my system and probably by default at /Applications/TextMate.app/Contents/SharedSupport/Bundles/JavaScript.tmbundle/Support/lib/beautify.php). If you take a look at the function definition you'll see that there's a second parameter, $tab_size, with a default value of 4. There's a line in the bundle that reads print js_beautify($input);. Change this to print js_beautify($input, 2); and you should, I expect, get tab stops with two spaces.
To make it a bit more flexible, use the TextMate environment variable TM_TAB_SIZE, as in print js_beautify( $input, getenv('TM_TAB_SIZE' ) );, which should update how the command operates if you ever change your tab size.
Note, I've tested none of this. :) Just took a look at the bundle and tracked down what seems to be necessary.
So, I tried chuck's suggestion and it gave me an error. I did this to "fix it". I'm sure it could be done more elegantly, but this worked for me.
Open up the same file Chuck says to open up, line 50 (or so) should look like this:
function js_beautify($js_source_text, $tab_size = 4)
change $tab_size to 1
function js_beautify($js_source_text, $tab_size = 1)
Now, around line 56 where it says:
$tab_string = str_repeat(' ', $tab_size);
change the space to a tab like so:
$tab_string = str_repeat("\t", $tab_size);
That worked for me.

Categories