How to disable Rule: one-line in TSLint - tslint

clearFile()
{
(<HTMLInputElement>document.getElementById('uploadFile')).value = "";
}
Gives
[tslint] misplaced opening brace
.
And if I use the opening braces in same line of function, it doesn't give me warning like
clearFile(){
(<HTMLInputElement>document.getElementById('uploadFile')).value = "";
}
This rule is called "one-line" rule
And how to configure it in TSLint to handle first type of braces style
Thanks in advance

If you want to globally turn of Goto {ProjectDirectoty}/tslint.json and add "one-line" : false in rules
One-line has 5 sub rules as "check-catch", "check-finally", "check-else", "check-open-brace", "check-whitespace". You can understand it from name, like for catch you should or not write opening braces in same or next line.
{
"extends": "../tslint.json",
"rules": {
"one-line" : false,
"directive-selector": [
true,
"attribute",
"app",
"camelCase"
],
"component-selector": [
true,
"element",
"app",
"kebab-case"
]
}
}
If you want to turn off only specific subrule, use something like this
"one-line": [true, "check-catch", "check-finally", "check-else"]
It will turn on for these 3 rules and off for other 2 rules
And if you want to disable in a particular file
/* tslint:disable:rule1 rule2 rule3... */ in that file

Related

How can we make multiple Boiler plate for c++ in Visusal Studio Code

i have made a boiler plate for cpp like
{
// Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"template": {
"prefix": "template",
"body": [
"#include <bits/stdc++.h>",
"using namespace std;",
"int main()",
"{",
" $1",
"return 0;",
"}"
],
"description": "Log output to console"
}
}
but i want to make more snippets like for gcd, function, modulus and many more . When ever i clicked on user snippet cpp then this appear. How can i make more snippets.
Here is the sample code that I figured out after much experimentation,
{
// Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"cpp snippets":
{
"prefix" : "cpp boilerplate",
"body" : [
"#include<iostream>",
"using namespace std;",
"int main()",
"{",
" $0",
" return 0;",
"}"
],
"description" : "to produce the main snippet for cpp"
},
"ccsnippets":{
"prefix" : "ccc boilerplate",
"body" : [
"#include<iostream>",
"using namespace std;",
"int main()",
"{",
"ios_base::sync_with_stdio(false);"
" $0",
" return 0;",
"}"
],
"description" : "snippet for competetive coding"
}
}
Basically, you have to put a comma ',' outside of the bracket of the first snippet, create a new title(in my case "ccsnippets":), place a curly bracket '{', and put in your code with new prefix and body.
Hope this helps!!

Specify severity error for tslint rule import-blacklist

How do I specify severity = error for rule import-blacklist of tslint (i.e red squiggly line) ?
I'd like to disallow import that starts with "packages".
I know tslint is going to be obsolete soon but for now we still use tslint.
I tried the following:
"import-blacklist": [
true,
[
"^packages.*$"
],
{
"severity": [
"error"
]
}
]
But it still show yellow squiggly line as warning.
If i use an object as config like:
"import-blacklist": {
"severity": "error",
"options": [
// what should i put here ?
]
}
Where should I put the pattern to ?
Stumbled upon this. So this is what I found working
"import-blacklist": {
"options": ["true", ["#material-ui/core$"]],
"severity": "error"
}

TextMate scope for triple quoted Python docstrings

I'm currently setting up VS Code for Python development. I'd like to have triple-quoted docstrings highlighted as comments, not as strings, i.e. grey instead of light green in this picture:
I know that I can adjust this in the TextMate rules for this theme, but I can't figure out the right scope for Python docstrings. I thought I would be something like this:
"editor.tokenColorCustomizations": {
"[Predawn]": {
"comments": "#777777",
"textMateRules": [
{
"scope": "string.quoted.triple",
"settings": {
"foreground": "#777777"
}
}
]
},
}
but that does not have the desired effect, even after restarting the editor. Does anyone know what the right scope is?
Just to expand on the comments above, the scopes are:
For docstrings: string.quoted.docstring.multi.python for """ ''' (or .single for ' ")
For triple quote strings that are not docstrings: string.quoted.multi.python
The scope string.quoted.triple is not used, even though it appears in settings.json autocomplete.
Try using this one
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": [
"string.quoted.multi.python",
"string.quoted.double.block.python",
"string.quoted.triple",
"string.quoted.docstring.multi.python",
"string.quoted.docstring.multi.python punctuation.definition.string.begin.python",
"string.quoted.docstring.multi.python punctuation.definition.string.end.python",
"string.quoted.docstring.multi.python constant.character.escape.python"
],
"settings": {
"foreground": "#777777" //change to your preference
}
}
]

Passing parameters to Azure ARM templates

I have a template I'm using to deploy to a resource group which takes this parameter:
"envPrefixName": {
"type": "string",
"metadata": {
"description": "Prefix for the environment (2-5 characters)"
},
"defaultValue": "cust1",
"minLength": 2,
"maxLength": 5
},
I would like to make this parameter a value that can be overriden when the cdmlet is called like such:
$AzureParams = #{
ResourceGroupName = $ResourceGroup
TemplateUri = $TemplateUri
TemplateParameterUri = $TemplateParamUri
Mode = "Complete"
envPrefixName = "sunlb" #Override default parameter value
Force = $true
}
New-AzureRmResourceGroupDeployment #AzureParams
I've tried this approach but the solution continues to try to use the value set in the template and not the one passed through as a parameter in my call.
EDIT: It is possible that the TemplateParameterUri file is causing and issue?
If you supply the TemplateParameterUri it will use the parameters file to deploy the template (and take the value from the file) and your envPrefixName would get "lost" because it wont evaluate the parameters in the template.
Drop the TemplateParameterUri and it will work as you expect it (but you have to supply all the parameters in this case, unless they have default values)

How to customize the color of custom syntax tokens in VSCode extension

TLDR; How can I have an extension colorize the syntax the extension is defining without it actually being a color theme the user has to enable?
I'm attempting to port this Sublime Text plugin (ToDone) to VSCode.
It creates a grammar for todo lists and then uses syntax highlighting to emphasize important tasks, mute completed tasks, etc.
I found "editor.tokenColorCustomizations", via Customize a Color Theme. It works with the new syntax when I use it in my user settings, but fails when I use it in the package.json#contributes portion of the extension manifest.
{
"contributes": {
"languages": [
{
"id": "todone",
"aliases": [
"ToDone",
"To-Done"
],
"extensions": [
".todone",
".todo"
]
}
],
"grammars": [
{
"language": "todone",
"scopeName": "text.todone",
"path": "./todone.tmLanguage"
}
],
"configurationDefaults": {
"[todone]": {
"editor.insertSpaces": false,
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "symbol.definition.task-heading.todone",
"settings": {
"foreground": "#ff8800"
}
}
]
}
}
}
}
}
So far, the syntax seems ok — it's exactly what is being used by the Sublime plugin and the colors from the user-settings are applied correctly. Also, the format of the settings seems ok because "editor.insertSpaces" is being applied and the colors are working when present in the user-settings.
Lastly, I get a very disappointing 'Warning' 'Unknown editor configuration setting' message on the "editor.tokenColorCustomizations" setting in the extension package.json.
So, sounds like this setting is not enabled for extensions?
Another possible route I saw was to use decorators. But, I didn't see anything on inspecting the syntax tokens associated with a portion of text in the docs, e.g. some way to iterate through the syntax tokens of the document to apply decorators. So, the decorator route sounds like the hard-way compared to "editor.tokenColorCustomizations".
Any suggestions on how to make this work would be greatly appreciated.
Edit: The code, so far, is on GitHub: tiffon/vscode-todone
It only fails if you specify a specific language. It is working for me if I do not specify the todone extension.
"configurationDefaults": {
"editor.insertSpaces": false,
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "symbol.definition.task-heading.todone",
"settings": {
"foreground": "#ff8800"
}
}
]
}
}

Resources