在vs代码编辑器中使用prettier plugin在typescript文件的类中方法声明之前和之后添加新行需要配置哪些设置?
我们如何通过在.prettierrc
或tslint.json
文件中编写任何规则来实现?
目前的行为是
function one(){
// some code
}
function two(){
// some code
}
预期结果
function one(){
// some code
}
function two(){
// some code
}
我在tslint.json中尝试过以下行
"lines-between-class-methods": "true"
但没有用
@lakshan提到的是ESLint rule。有一个TSLint规则可以完成您正在寻找的内容,但是就类方法而言。
https://github.com/chinchiheather/tslint-lines-between-class-members
跑
npm install --save-dev tslint-lines-between-class-members
加
tslint.json
{
"rulesDirectory": [
"node_modules/tslint-lines-between-class-members"
],
"rules": {
"lines-between-class-members": true,
}
}
在你的es-lint规则中尝试这个,
"lines-between-class-members" : ["error", "always"]
如果你违反了这个条件,它会给你一个错误。我认为你必须在一个类中声明你的函数才能工作。
除此之外,你可能没有更漂亮的自动修复,因为事实证明空行很难自动生成。 Prettier采用的方法是保留空行,就像它们在原始源代码中一样。