nvim coc-eslint .eslintrc with prettier/prettier sets double quotes instead of single quotes - prettier

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.

Related

How can I find and replace values bracket by bracket?

I'm trying to find every "color" value and replace it with a specific string, but only the "color" value of every "name" that has Bismuthinite" in it.
[
{
"name": "Poor Gneiss Bismuthinite",
"blockName": "tfc:ore/poor_bismuthinite/gneiss",
"order": 789,
"color": 5015620,
"drawing": false
},
{
"name": "Slate Halite",
"blockName": "tfc:ore/halite/slate",
"order": 1046,
"color": 7153517,
"drawing": false
},
The information wthin the next brackets (block? im not sure what the terminology is, i'm very new to coding in general) should not be selected or altered in any way. Only the information that matches "name" includes Bismuthinite" .
I've tried using a multiline find and replace using the ToolBucket plugin for Notepad++, but either it won't accomplish what I want it to do, or I just don't know how.

Set/use a keyboard shortcut to replace a character in Visual Studio Code

What I want to know
How to set a keyboard shortcut to replace "" with ''.
Or is there a default shortcut to replace "" with ''?
Purpose
I use Visual Studio Code on a Mac. I often replace "" with ''.
For example,
const foo = "foo";
const bar = "bar";
⬇️
const foo = 'foo';
const bar = 'bar';
I usually use Visual Studio Code's replace function with a regular expression like this.
I want to register a keyboard shortcut for this operation because I do it frequently.
What I tried / Issue
I opened keybindings.json and tried to set a keyboard shortcut in it. But I have no idea what to write.
[
{
"key": "shift+cmd+'",
"command": "actions.find" // ?????????
}
]
What should I write in there? Or is there a default shortcut to replace "" with ''?
Edit:
According to Jeff Brower's answer (thank you!), "args" can be helpful for my purpose. I'm trying to change his/her code.
I wrote in keybindings.json like this but it doesn't work:
{
"key": "shift+cmd+'",
"command": "editor.action.startFindReplaceAction",
"args": {
"query": "\"(.+)\"",
"replace": "'$1'",
"triggerSearch": true,
"isRegex": true,
"matchWholeWord": true,
"isCaseSensitive": false
}
}
According to the answers of this question, there is no built-in way to do this. However, I did get a similar keybinding to work. This searches all files in the workbench:
{
"key": "ctrl+shift+'",
"command": "workbench.action.findInFiles",
"args": {
"query": "\"((?:\\\\[\"'\\\\bfnrt]|[^\\\\\"'\\n\\r])*)\"",
"replace": "'$1'",
"triggerSearch": true,
"isRegex": true,
"matchWholeWord": true,
"isCaseSensitive": true
}
}
The main caveat is that it doesn't automatically perform the replacement, but it does fill in the fields of the find and replace.
I also improved the regular expression a bit to handle javascript-style escaping, and allow empty strings (unit tests). To use your original regular expression, replace the whole string with:
"\"(.+)\""
It can be done with an extension, I'll show the code for that. An extension allows you to set a keybinding if that is what you want.
But it is easy to accomplish what you want with these steps.
Select any ".
Cmd+Shift+L to select all occurrences of ".
Type '.
The working part of the extension code:
let disposable = vscode.commands.registerCommand('yourExtensionName.someCommandName', async function () {
const fileName = vscode.workspace.asRelativePath(vscode.window.activeTextEditor.document.uri);
vscode.commands.executeCommand('workbench.action.findInFiles',
{
query: "\"(.+)\"",
replace: "'$1'",
triggerSearch: true,
isRegex: true,
filesToInclude: fileName
// preserveCase: true,
// useExcludeSettingsAndIgnoreFiles: true,
// isCaseSensitive: true,
// matchWholeWord: true,
// filesToExclude: "./*.css"
}).then(() => {
setTimeout(() => {
vscode.commands.executeCommand('search.action.replaceAll');
}, 1000);
});
});
context.subscriptions.push(disposable);
Demo:
The extension works with the findInFiles command, since actions.find will not take arguments. But it is restricted to the current file. It finds the current fileName:
const fileName = vscode.workspace.asRelativePath(vscode.window.activeTextEditor.document.uri);
and uses that in the filesToInclude argument.

How to change the experiment file path generated when running Ray's run_experiments()?

I'm using the following spec on my code to generate experiments:
experiment_spec = {
"test_experiment": {
"run": "PPO",
"env": "MultiTradingEnv-v1",
"stop": {
"timesteps_total": 1e6
},
"checkpoint_freq": 100,
"checkpoint_at_end": True,
"local_dir": '~/Documents/experiment/',
"config": {
"lr_schedule": grid_search(LEARNING_RATE_SCHEDULE),
"num_workers": 3,
'observation_filter': 'MeanStdFilter',
'vf_share_layers': True,
"env_config": {
},
}
}
}
ray.init()
run_experiments(experiments=experiment_spec)
Note that I use grid_search to try various learning rates. The problem is "lr_schedule" is defined as:
LEARNING_RATE_SCHEDULE = [
[
[0, 7e-5], # [timestep, lr]
[1e6, 7e-6],
],
[
[0, 6e-5],
[1e6, 6e-6],
]
]
So when the experiment checkpoint is generated it has a lot of [ in it's path name, making the path unreadable to the interpreter. Like this:
~/Documents/experiment/PPO_MultiTradingEnv-v1_0_lr_schedule=[[0, 7e-05], [3500000.0, 7e-06]]_2019-08-14_20-10-100qrtxrjm/checkpoint_40
The logic solution is to manually rename it but I discovered that its name is referenced in other files like experiment_state.json, so the best solution is to set a custom experiment path and name.
I didn't find anything in documentation.
This is my project if it helps
Can someone help?
Thanks in advance
You can set custom trial names - https://ray.readthedocs.io/en/latest/tune-usage.html#custom-trial-names. Let me know if that works for you.

Visual Studio Code: How to automate a simple regex-find and replace?

I try to create a simple regex-find and replace task in Visual Studio Code.
Currently I copy from the AD some Users to a temporary file in Visual Studio code and remove the "CN=" at the beginning of the line and all the aditional informations after the first "," (regex: ,.*$). This works fine with Find&Replace in VSCode but I have manually to type it in every time I want to remove this.
So the question is, is it possible to automate this kind of task? I know there are some external tools (https://code.visualstudio.com/docs/editor/tasks) but I'm struggling to get it working...
Edit: Example requested (my regex is working, that's not the problem:/. I need an example how to automate this task... )
EXAMPLE
CN=Test User,OU=Benutzer,OU=TEST1,OU=Vert,OU=ES1,OU=HEADQUARTERS,DC=esg,DC=corp
Expected Output
Test User
This extension does the job:
https://marketplace.visualstudio.com/items?itemName=joekon.ssmacro#overview
It seems like the regex adheres to:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
Example
Create a file regex.json:
[{
"command": "ssmacro.replace",
"args": {
"info": "strip out EOL whitespace",
"find": "\\s+$",
"replace": "",
"all": true,
"reg": true,
"flag": "gm"
}
}]
"info" is just a reminder, doesn't do anything.
Set a shortcut in keybindings.json:
"key": "ctrl+9",
"command": "ssmacro.macro", "args": {"path": "C:\\...\\regex.json"}
You can batch multiple commands together [{...},{...}] which is useful for applying a whole set of regex operations in one go.
As of today, it seems it's still not possible without an extension. Here are 2 other extensions than the one proposed in the accepted answer (both are also open-source):
● Batch Replacer (but it doesn't work on the documents open in the editor : "you must have a folder open for editing and all files in it will be updated."*)
● Replace Rules: you simply add some rules in your settings.json (open the palette with F1 or ctrl+shift+p and select Preferences: open settings (JSON)).
"replacerules.rules": {
"Remove trailing and leading whitespace": {
"find": "^\\s*(.*)\\s*$",
"replace": "$1"
},
"Remove blank lines": {
"find": "^\\n",
"replace": "",
"languages": [
"typescript"
]
}
}
Extensions folder is : %USERPROFILE%\.vscode\extensions
And here is an extension I wrote that allows you to save find/replaces in a file or searches across files as a named command and/or as a keybinding: Find and Transform. Using the OP's original question, make this setting (in settings.json):
"findInCurrentFile": { // in settings.json
"reduceUserEntry": {
"title": "Reduce User to ...", // will appear in the Command Palette
"find": "CN=([^,]+).*",
"replace": "$1",
"isRegex": true,
// "restrictFind": "selections", // default is entire document
}
},
You could also make that for searches across files with this setting:
"runInSearchPanel": {
"reduceUserEntry": {
"title": "Reduce User to ...", // will appear in the Command Palette
"find": "CN=([^,]+).*",
"replace": "$1",
"isRegex": true
// "filesToInclude": "${fileDirname}"
// "onlyOpenEditors": true
// and more options
}
}
As a standalone keybinding:
{
"key": "alt+r", // whatever keybinding you want
"command": "findInCurrentFile", // or runInSearchPanel
"args": {
"find": "CN=([^,]+).*",
"replace": "$1",
"isRegex": true
The extension can also run multiple finds/replaces - just put them into an array:
"find": ["<some find term 1>", "<some find term 2>", etc.
and the same with replacements, make an array of them.

Find pattern with regex in Sublime text 2.02

I would like to create a new Syntax Rule in Sublime in order to search a string pattern so that that pattern is highlighted. The parttern I am looking for is IPC or TST, therefore I was making use of the following Sublime Syntax rule
{ "name": "a3",
"scopeName": "source.a3",
"fileTypes": ["a3"],
"patterns": [
{ "name": "IPC",
"match": "\\b\\w(IPC|TST)\\w\\b "
}
],
"uuid": "c76f733d-879c-4c1d-a1a2-101dfaa11ed8"
}
But for some reason or another, it doesn't work at all.
Could someone point me out in the right direction?
Thanks in advance
After looking around and testing a lot, I have found the issue, apparently apart from identifying the patter, I should invoke the colour, for doing it I have to make use of "capture", being the command as follows:
{ "name": "IPC colour",
"match": "\\b(IPC|TST)\\b",
"captures": {
"1": { "name": "meta.preprocessor.diagnostic" }
}
},
Where "name": "meta.preprocessor.diagnostic" will indicate the sort of colour assign to the found pattern.
regards!