I've only been using StringTemplate 4 for a week, so it's probably something I'm doing, but I don't seem to be able to make the <if> work.
I'm using 4.02 (since that's the latest in Maven repository). I have a class called Variable. This is a snippet:
class Variable
{
...
public boolean isArray()
{
return _bIsArray;
}
}
I have a template that has a line(delimiter is $, $):
$if(x.isArray)$ $ArrayAdd(x, className)$ $endif$
If I remove the if and simply let it execute $ArrayAdd(...)$ for everything, the ArrayAdd is clearly executed. I then put the $if$ back in. I also put a print statement in isArray() and isArray() is getting executed and returns false most of the time, but does return true once in a while (for exactly the cases I expected). However, $ArrayAdd never gets executed from within the $if$.
I looked at the trace (which I'm not good at reading) and got:
declareSetGet:0227: load_local 0 stack=[ ], calls=ObjectClass _sub1
declareSetGet, sp=-1, nw=0
declareSetGet:0230: load_prop #25:"isArray" stack=[
altLocation<CUSTOM>::Array<1>::Custom<altLocationObj> ], calls=ObjectClass _sub1
declareSetGet, sp=0, nw=0
declareSetGet:0233: brf 254 stack=[ null ], calls=ObjectClass _sub1
declareSetGet, sp=0, nw=0
ObjectClass:0121: newline stack=[ ], calls=ObjectClass, sp=-1, nw=959
ObjectClass:0122: write_str #15:"}" stack=[ ], calls=ObjectClass, sp=-1, nw=0
This is one of the cases where I would expect the ArrayAdd template to be executed. Obviously, it doesn't.
Can anyone tell me what I'm missing?
I'm wondering if you should do this:
$if(x.array)$ $ArrayAdd(x, className)$ $endif$
Specifically, use x.array instead of x.isArray because the name of the property is "array" and the "is" is just a prefix per the Java Beans convention for boolean property accessors.
Related
I need to apologize in advance because I am totally confused at the moment. I've been wrangling with my .eslintrc.json (at the end of my post) for several hours now.
All I want, is to set single quotes. To my understanding single quotes are part of the default settings of "eslint:recommended". But when I execute Prettier, double quotes are being set.
Next thing I tried was setting single quotes in rules for "prettier/prettier". That's not working either. Prettier is still setting double quotes.
Last of my options was setting single quotes directly in rules as "quotes: ["error": "single"].
Strangely enough though, double quotes are being shown as linting errors while editing.
I am running out of options.
Maybe someone can help me.
Here's my .eslintrc.json:
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true,
"node": true
},
"extends": ["eslint:recommended", "prettier"],
"plugins": ["prettier", "#babel", "vue"],
"parserOptions": {
"ecmaVersion": 2022,
"parser": "#babel/eslint-parser",
"sourceType": "module"
},
"rules": {
"no-console": "off",
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"prettier/prettier": [
"error",
{
"singleQuote": true,
"onlyUseLocalVersion": false
}
]
}
}
Finally I tried to set
{
"prettier.singleQuote":true
}
in coc-settings.json (:CocConfig) and now it works.
That shouldn't be necessary if singleQuote is already set in .eslintrc. So I consider setting singelQuote in coc-settings.json rather a workaround than a real solution.
I have a problem with Postman, where I want to use collection variables inside the request body.
According to postman documentation, all variables in postman GUI can be retrieved with double curly braces {{}}.
But it does not work for me. If I move variables from collection to environment, everything is working OK, but as soon as I move the variable from the environment to collection, it starts throwing errors like this:
JSONError: Unexpected token 'U' at 1:1
Unrecognized token 'Backend': was expecting (JSON String, Number, Array, Object
This is my body:
{
"name": {{BackendValidationPSName}},
"groups": {{myBackendValidationRGuuids}}
}
Can anyone point me in the right direction? Tx.
The values have to be in double quotes
{
"name": "{{BackendValidationPSName}}",
"groups": "{{myBackendValidationRGuuids}}"
}
Solved. I was missing the "" in the collection variable value.
Im trying to set up a convention to ignore any test that follows a pattern. The filename would look like this if you wanted jest to ignore it during npm test.
DISABLED.MyComponent.test.js
trying to use testPathIgnorePatterns
testPathIgnorePatterns: ['<rootDir>/src/**/DISABLED.{*}.js'],
The error is either it is still being run, or it throws a error that the regex is invalid.
Jest uses glob patterns to match the test files, so prefixing the default entries in the testMatch configuration with !(DISABLED.) should do the job.
package.json
{
// ... rest of the package
"jest": {
"testMatch": [
"**/__tests__/**/!(DISABLED.)*.[jt]s?(x)",
"**/!(DISABLED.)?(*.)+(spec|test).[tj]s?(x)"
]
}
}
Side note: You can also "disable" the test file by renaming the main describe block to xdescribe or describe.skip, which would give visibility that there are skipped tests instead of completely ignore the file
Test Suites: 1 skipped, 11 passed, 11 of 12 total
Tests: 2 skipped, 112 passed, 114 total
The other answers here are helpful but miss the core fact:
testPathIgnorePatterns can be used to ignore your filenames. The problem is that testPathIgnorePatterns takes a RegExp, not a glob as you've specified.
The default setting for testPathIgnorePatterns is "/node_modules/", so it's probably useful to include it as well.
As an example, to ignore end to end tests that have an "e2e-" prefix, you could use:
"testPathIgnorePatterns": [
"/node_modules/",
"/e2e-"
]
In your specific case, this would be something like the following (note how the . is escaped in /DISABLED\\.):
"testPathIgnorePatterns": [
"/node_modules/",
"/DISABLED\\."
]
testPathIgnorePatterns is an array of regex patterns that ignores any path that matches the listed expressions and should contain the default "/node_modules/" as well. While it is not intended you may as well use testPathIgnorePatterns to exclude specific files:
So, your best bet would be to move the ignored test to s separate folder, e.g.
"jest": {
"testPathIgnorePatterns": [
"/node_modules/",
"<rootDir>/ignore/this/path/"
]
}
So #Teneff 's answer nearly worked for me. I had to move the ! to the front of the statement to get it to work. Hope this helps someone else too! I am using Next.JS 12.
testMatch: [
'**/*.test.{ts,tsx}',
'!**/__tests__/**/(DISABLED.)*.[jt]s?(x)',
'!**/(DISABLED.)?(*.)+(spec|test).[tj]s?(x)',
]
I'm no regex master, and I'm pretty sure a regex is what is needed in this instance.
I currently have a text replacement task like so:
configSeed: {
src: ['src/*/local/app-config.js'],
overwrite: true,
replacements: [
{
from: 'var CONFIG_SEED_STRING = null;',
to: 'var CONFIG_SEED_STRING = "{"some_stringified_dynamic_json":"values"}";'
}
]
}
Which works fine the first time the config file is saved, the above string is replaced.
However, as soon as the string is replaced, further changes to the config don't have a replacement applied because obviously null is no longer to be found.
null is where my wildcard value needs to be, and the value could be either null (initially) or subsequent replacing a valid JSON string instead.
If my assumption about a wildcard being needed is true, would that trigger recursion upon save? Or does Grunt have in-built protection against this situation? [edit: I've tested this by replacing the string with the same value, recursion does not occur.]
So, assuming it is safe to use a wildcard where I want to, could I please get help with a regex value to be replaced?
Alternative solutions also welcome, for example my code base is unchanging enough that I could viably replace a line of code completely, if that's possible.
Thanks for any help provided.
Omg, I actually did it, what a feeling. After some painful reading on regex again:
configSeed: {
src: ['src/*/local/app.js'],
overwrite: true,
replacements: [
{
from: /var CONFIG_SEED_STRING = '[^']*'/g,
to: 'var CONFIG_SEED_STRING = \'{"foo":"bar"}\''
},
{
from: 'var CONFIG_SEED_STRING = null',
to: 'var CONFIG_SEED_STRING = \'{"foo":"bar"}\''
}
]
}
Not perfect, because I have two from/tos, but it catches both null and valid JSON data in between single quoted String value for CONFIG_SEED_STRING.
Instant reward time for writing a regex! I'm allowing myself 15 minutes of Youtube at work.
I have a recursive Json file the format is below; I have two parts condition and action. In condition part there can be n-root and leaves pairs, and inside leaves part there can be
additional values. I have problems about handling this data structure using json-spirit. Can anyone had same issue and solved or anyone have any clue. I would be appreciate.
Thanks
{
"condition": {
"root": "&",
"leaves": [ "A",
{ "root": "|",
"leaves": ["p","r"]
}
]
},
"action": ["a=7","event B"]
}
I dont know json-spirit. Do you absolutlely need to use it ?
If not, you may try this : https://github.com/Rel4X/HandyJson
Really easy to use (and I'd love some tests \o/)
Rel4x