Can somebody help me explain the order/priority of indentationRules and onEnterRules in language-configuration for vscode?
What is happening: in the extension for the Godot game engine, the code blocks after the lines that match the regexp for increaseIndentPattern received additional indentation after the code block is moved down or pasted. See issue: https://github.com/godotengine/godot-vscode-plugin/issues/337
When I added a simple rule in onEnterRules it solved the issue. The problem is that the order/priority of these rules is not defined anywhere in the documentation and I can't understand why it solved the issue.
The rule that I added:
"onEnterRules": [
{
"beforeText": "^\\s*$",
"action": {
"indent": "none"
}
}
]
PR: https://github.com/godotengine/godot-vscode-plugin/pull/344
I need to understand what is going on here and why it worked. Thank you!
Related
Lots of logging is very helpful to me.
However, sometimes I would like to temporarily reduce the clutter of code that I'm editing in VSC by hiding, collapsing, or reducing the opacity of the font of console.log, console.warn, and console.error lines in javascript, Vue, React, etc.
How could I accomplish my goal?
I'd love if there were some way to easily toggle the feature on/off.
Thank you so much to #rioV8, who pointed me to the answer.
This seems to work for me when using extension Highlight:
"highlight.regexes": {
"(console\\.(log|warn|error)\\(.+\\)[;]?)": {
"regexFlags": "g",
"decorations": [
{ "opacity": "0.1" }
]
}
}
To determine what regular expression I wanted to use, I wrote these test cases in https://www.regexpal.com:
console.log('asdfdsf')
console.log({some})
console.log({some});
console.error('error', msg);
console.warn('careful', thing)
And (console\.(log|warn|error)\(.+\)[;]?) worked. Then I needed to add an extra \ before each \ to satisfy the VSC settings JSON file.
Now my VSC looks like this:
I'm working with VSCode, Prettier and TSLint.
When I do have chained functions call with more than 2 calls like
let m = moment().startOf("day").subtract(30, "days");
Prettier breaks into
let m = moment()
.startOf("day")
.subtract(30, "days")
I already set the TSLint rule
{
"defaultSeverity": "warning",
"extends": ["tslint:recommended"],
"linterOptions": {
"exclude": ["node_modules/**"]
},
"rules": {
// ...
"newline-per-chained-call": false
}
}
and the fallowing settings
"prettier.tslintIntegration": true
But the chained functions still breking into new lines.
What can I do to avoid the line breaking but still using the TSLint?
[EDIT] In Prettier v2.0.4 this issue is fixed. Update to latest version
This is an issue in prettier. The PR's to add this feature has not yet been merged from what i understand.
Currently to get what you want, what i can suggest is to ignore the next node in the abstract syntax tree from formatting using the // prettier-ignore comments.
// prettier-ignore
let m = moment().startOf("day").subtract(30, "days");
There are variations of these ignore statements, like one could ignore within a ranger or one could even ignore a particular file too. Do check out the official prettier documentations to know more of it's implementation.
Note that in Prettier v2.0.4 this issue is fixed. Now, as long as your line of code is within the length specified in your config or the default 80, it will be left in one line. Otherwise, it will be wrapped to multiple lines.
I had to upgrade my prettier in order for these changes to be put into affect.
$ yarn upgrade -g prettier --latest
Thanks. What are the default formatting rules being used for TypeScript?
I'm working from a template setup with TSLint.
VSC inserts a space before : on variable type declarations.
My TSLint complains that I have a space a before : and I don't want the space there.
(snapshot : any) => { ... }
My TSLint config (and I) want it to be the following form
(snapshot : any) => { ... }
How can I make VSC behave on auto-save adhering to my TSLint formatting rules? I've also tried using the Prettier extension, but now have it disabled as I tried to figure out what was going on. Any suggestions greatly appreciated. Thanks.
I'm using VSCode with prettier plugin and typescript and also tslint.
Leaving aside the convenience to use this configuration, I get a
[tslint] Exceeds maximum line length of 120 (max-line-length)
For a line like this:
import { MyComponent } from "../../some_very_long_path";
I've prettier configured with a print-width of 100, so I was expecting that on Format Document this line would be refactored into something like this:
import { MyComponent }
from "../../some_very_long_path";
or like this:
import {
MyComponent
} from "../../some_very_long_path";
But it is not. Any ideas why?
The documentation says printWidth. The documentation link is here
printWidth: 120
Probably this should solve the problem.
You can add exception for specific regex.
Prettier will have the lead for managing imports and exports, since it has a special way to deal with them.
// edit your tslint.json
"max-line-length": [
true,
{
"limit": 140,
"ignore-pattern": "^import |^export {(.*?)}"
}
],
Prettier is not breaking down imports and the best thing you can do is to remove all the stylistic errors (including the max-line-length) from tslint rules and let Prettier to handle those and tslint the code related ones.
I'm trying to convert an existing project to use the aurelia cli and I've encountered an old problem. I'm getting a regeneratorRuntime is not defined error. I fixed this a while back in a previous version but either my memory is hazy or that knowledge doesn't apply to this version. Can anyone point me to a source or give me some advice on how to fix this with this version?
Thanks,
Ross
The solution that worked for me was to add the babel-polyfill to the vendor-bundle section of aurelia-project/aurelia.json, like this:
"name": "vendor-bundle.js",
"prepend": [
"node_modules/babel-polyfill/dist/polyfill.js",
"node_modules/bluebird/js/browser/bluebird.core.js",
"scripts/require.js"
]
I was able to get it. Once you get how the aurelia.json file works, it's not to difficult. Add this to aurelia.json:
{
"name": "regenerator-runtime",
"path": "../node_modules/regenerator-runtime",
"main": "runtime-module"
}
Then add this to main.js:
```
import regeneratorRuntime from 'regenerator-runtime';
window.regeneratorRuntime = regeneratorRuntime;
```
Thanks for everyone's suggestions.
A hackish solution for now (thanks to Roland Quast #rquast from https://gitter.im/aurelia):
You need to install and require babel-polyfill in your main.js file explicitly:
require('node_modules/babel-polyfill/dist/polyfill.js')