Prettier: Add space between function and parenthesis - prettier

In VSCode, each time I save a JS file, Prettier removes the space between the function keyword and its parenthesis.
It changes this:
function (parameter)
To this:
function(parameter)
But I want to keep the space.
Some people are suggesting adding this rule to VSCode setting:
"prettier.spaceBeforeFunctionParen": true
But apparently this rule doesn't exist any more.
How can I force a space between function and parenthesis in Prettier?

in setting.json add
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
after, when you save your work, eslint fix your error like space before function parenthese.

Interestingly, I get the opposite behavior.
I have VSCode set up to use my .prettierrc config file. But when I set VSCode to "Format on Save", a space gets added before my function parens, even when I have this set to false in .prettierrc: “spaceBeforeFunctionParen": false.
This function signature:
const myFunction = function(datevalue) {
... always changes to:
const myFunction = function (datevalue) {
I can't find a way to avoid this with prettier. So in part because the extraneous space looks a bit peculiar to me, I now pretty much always just use arrow functions instead:
const myFunction = (datevalue) => {

To solve that issue you had to set the config on your settings.js:
{
"editor.formatOnSave": false,
"editor.formatOnType": false
}
or go to the vscode settings "File => Preferences => settings" search for onSave and unchecked the "Format On Save" check box.

Related

When i extract a method in eclipse it changes "and" and "or" to "&&" and "||". Is this changeable?

I strictly use "and", "or" and "xor" instead of "&&", "||" and "^". But when i then use the extract method, functionality in eclipse it doesn't use "and" etc. regardless of it being used in the original method.
void MethodName() {
if (foo and bar) {
// Do stuff
}
}
Turns into:
void NewMethodName() {
if (foo && bar) {
// Do stuff
}
}
I have looked in every c/c++ setting in eclipse and not a single one i have found has had anything relating to this, and when looking online i haven't found anyone else with this problem.
Settings i've looked into:
Code Style
Formatter
Appearance
Autotools
Editor
Code Analysis
Template Default Values
As well as any underlying settings in the before-mentioned ones
Does anyone know of a setting or anything to fix this?

any means of returning bool for yaml variables in yaml-cpp?

I have a config file for disabling specific code paths. I just added a bool option to the yaml file, and am having a hard time figuring out how yaml-cpp handles those. The documentation is a bit lighter than preferred, and I don't see anything for a Node that fits my use case. I could manually parse for the strings returned as true and false, but that seems like something the framework should support, as there are multiple styles of writing trueand false in the spec. Is there any means of getting a bool value out of yaml-cpp?
IsScalarwas the closest I could find.
void LoadConfig(string file)
{
Node config = LoadFile(file);
string targetDirectory;
bool compile;
if (config["TargetDirectory"])
targetDirectory = config["TargetDirectory"].Scalar();
if (config["Compile"])
compile = Config["Compile"].IsScalar();
}
You want the template as() method:
config["Compile"].as<bool>()
Or a neater way to do it all in one line instead of three using a default value (which also addresses your potential uninitialized variable bug):
bool compile = config["Compile"].as<bool>(false);

PyCharm unittest error: Provide a qualified name of function, class or a module

How to get rid of this annoying error? I do not understand what it want me to do.
This happens when I am trying to run a test
Clicking on "Run" follows up with the following
Screen
Clicking on "Continue Anyway" runs the tests normally.
So what should I do in order to stop this window from popping up every time I ran the tests?
Updated:
Here is what I've found myself meanwhile:
From here
if (targetType == PyRunTargetVariant.PYTHON && !isWellFormed()) {
throw RuntimeConfigurationError("Provide a qualified name of function, class or a module")
}
And a function isWellFormed() declaration from here
/**
* Sanity check for "target" value. Does not resolve target, only check its syntax
* CUSTOM type is not checked.
*/
fun TargetWithVariant.isWellFormed() = when (targetVariant) {
PyRunTargetVariant.PYTHON -> Regex("^[a-zA-Z0-9._]+[a-zA-Z0-9_]$").matches(target ?: "")
PyRunTargetVariant.PATH -> !VfsUtil.isBadName(target)
else -> true
}
Everything looks good with a regex of my test class and method names.
Ok, this is really weird.
I took a good look at a regex and found that it doesn't want any '-' in the target path. So renaming a filename from ads_wrapper-tests.py to ads_wrapper_tests.py solves the problem and the window is not popping up any more.
With this issue Error: Provide a qualified name of a function, class or module just got fixed, soon Pycharm would allow using all valid identifier names in target name.

React Native arrow functions and 'if' statements

I have just been schooled on arrow functions, and how they can aid with visibility when you start using sub-functions on React Native and globally accessible objects.
I am not sure if this is different for "if" statements, but I can't get this to work at all. The issue:
myFunction() {
console.log('Welcome Flag: ' + this.props.welcomeFlag);
if (this.props.welcomeFlag == false) {
this.props.dispatch(setWelcomeFlag(true));
showMessage('Welcome back, ' + this.props.userName + '!', { duration: 3000 });
}
}
In this example, the console logs the initial value of welcomeFlag, which is "false". I would then like to, if it is false, display a message to the user and set it to true. Super simple stuff.
It falls over here:
this.props.dispatch(setWelcomeFlag(true));
Because my if statement is not an arrow statement.
Except I can't get the arrow statement to work for if statements. It is working for other kinds of statements, but just not for these.
I have tried the answers listed here:
How to use if-else condition in arrow function in JavaScript?
But none of these work.
How can I fix it?
myFunction() is a class level function. Binding anything to this is referring a class itself, therefore you need to bind it to access this property, otherwise you won't be able to access the class level props.
Although there are many ways to bind this as explained here, but the simplest one would be to use the shorthand arrow syntax as
myFunction = () =>

How to change a variable value on conditional breakpoint in visual studio 2015

Is there any way to change value of variable to on a conditional breakpoint and continue execution.
My code is like this
switch(var){ //conditional breakpoint on this line
case 1:
break;
...
}
I put conditional breakpoint like below
(var == 0 ) || (var ==1) is true
So when this breakpoint hits, I want to change var = 2, and continue execution.
What I found: I found Action also, but it only log messages. Is there any way to executing a statement like var = 2 as Action taken on this conditional breakpoint.
I don't want to change code because building it takes hell lot of time.
Note: I am working C++ on Visual studio 2015
In Log a message to Output Window write {my_variable=12345} the side effect of log output is assigning 12345 to my_variable.
Take into account that Log a message can accept and evaluate complex expressions in curly braces.
You can modify a variable directly in memory to change the execution flow through a quick watch (Shift+F9) or watch window in Visual Studio.
Make sure that in Tools / Options / Debugging you have the "Enable Edit and Continue" Enabled/Checked and then you will be able to edit your code while debugging and continue without the need to rebuild or to stop execution.
More information can be found in How to: Enable and Disable Edit and Continue
This used to work, I can't seem to get it to work now. Worked excellent on loops and also good for altering values without altering the source or the code (and accidently committing it).
Conditional break point, break if true
(url = "http://localhost:1234/") != url
This works thanks to assignment always returns it's assigned value. This will never be true as url becomes localhost