简体   繁体   English

如何在VSCode中覆盖react-beautify设置?

[英]How can I override a react-beautify setting in VSCode?

I have a React Native project. 我有一个React Native项目。 In Visual Studio Code, I use the react-beautify add-in to beautify my code on the fly. 在Visual Studio Code中,我使用react-beautify加载项来动态地美化我的代码。 The add-in uses a tool named prettydiff internally. 该加载项在内部使用名为prettydiff的工具。

The only thing it does that I don't like is that it condenses 它唯一让我不喜欢的是凝聚

import { Componentname } from packagename

to

import {Componentname} from packagename

The correct prettydiff setting to change this behaviour is to set brace_style to collapse-preserve-inline . 更改此行为的正确prettydiff设置是将brace_style设置为collapse-preserve-inline

However, I can't get prettydiff to accept the change. 但是,我不能让prettydiff接受这个改变。

I tried creating a .jsbeautifyrc file in my project's root directory, and added: 我尝试在项目的根目录中创建一个.jsbeautifyrc文件,并添加:

{
    "brace_style": "collapse-preserve-inline"
}

but this doesn't seem to work: the behaviour I don't want is still happening. 但这似乎不起作用:我不想要的行为仍在发生。

How do I do this correctly? 我该怎么做呢?

I have VS Code in Mac v1.8.1 and if you open a Folder with a .jsbeautifyrc you could override the properties, in your example if you create a folder with 2 files: 我在Mac v1.8.1中有VS Code,如果你用.jsbeautifyrc打开一个文件夹,你可以覆盖属性,在你的例子中,如果你创建一个包含2个文件的文件夹:

index.js index.js

import {code} from 'source';
import {otherCode} from 'source';

.jsbeautifyrc .jsbeautifyrc

{
  "bracepadding": true
}

you will get the next result after run the beautifier: 运行美化器后你会得到下一个结果:

import { code } from 'source';
import { otherCode } from 'source';

Yes there is a bug,the .jsbeautifyrc file doesn't seem to be read in the react-beautify add-in. 是的,有一个错误,似乎没有在react-beautify加载项中读取.jsbeautifyrc文件。

The settings mentioned during the setup of the addon don't seem to work and also I have tried installing prettydiff in my system and also the esformatter-jsx and changed the configuration but it doesn't read the files settings 插件时提到的设置似乎不起作用,我也尝试在我的系统中安装prettydiff以及esformatter-jsx并更改配置但它不读取文件

Workaround 解决方法

You can try the beautify add-in with the following repo here . 您可以在这里尝试使用以下repo美化加载项

and add the file .jsbeautifyrc to your file tree structure ,and the options mentioned in the settings page work in it. 并将文件.jsbeautifyrc添加到您的文件树结构中,并在设置页面中提到的选项。

The project has been updated to the latest js-beautify code version 1.6.8 with the support of the jsx support as mentioned in the screen shot 该项目已更新至最新的js-beautify代码version 1.6.8 ,并支持屏幕截图中提到的jsx support 在此输入图像描述

and also the working example 还有工作实例 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM