我正在 React 的一个项目中使用 Atom 文本编辑器,使用 es6 import 语句,并尝试使用 Atom-beautify (0.33.4) 格式化我的代码。我的一个文件的开头如下:
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import axios from 'axios';
import { updateUser, updateUserLocation } from '../redux/reducers/user';
class Form extends Component {
constructor(props) {
super(props)
this.state = {
submitEnabled: false,
lat: '',
long: '',
zip: '',
city: '',
state: '',
}
}
validateName = (e) => {
e.preventDefault();
const { name, value } = e.target;
const nameRegExp = /^[A-Za-zÀ-ÿ ,.'-]+$/;
if (nameRegExp.test(value)) this.validInput(e)
else this.invalidInput(name);
}
目前,如果我使用键盘映射或以其他方式自动格式化我的代码,则会产生:
1 import React, {
2 Component
3 } from 'react';
4 import {
5 connect
6 } from 'react-redux';
7 import {
8 Link
9 } from 'react-router-dom';
10 import axios from 'axios';
11
12 import {
13 updateUser,
14 updateUserLocation
15 } from '../redux/reducers/user';
16
17 class Form extends Component {
18 constructor(props) {
19 super(props)
20 this.state = {
21 submitEnabled: false,
22 lat: '',
23 long: '',
24 zip: '',
25 city: '',
26 state: '',
27 }
28 }
29
30 validateName = (e) => {
31 e.preventDefault();
32 const {
33 name,
34 value
35 } = e.target;
36 const nameRegExp = /^[A-Za-zÀ-ÿ ,.'-]+$/;
37 if (nameRegExp.test(value)) this.validInput(e)
38 else this.invalidInput(name);
39 }
有没有办法可以禁用 es6 import 语句(预格式化片段第 1-4 行)和 es6 对象解构(预格式化片段第 23 行)的自动格式化的atom-beautify。
预先感谢您的任何回复。
最佳答案
如果您使用 js-beautify
作为底层引擎,请将 brace-style
设置为 collapse,preserve-inline
。这是 Atom UI 的等效项:
您可以在beautifier.io上尝试一下通过使用以下 UI 设置:
您还可以通过使用“其他设置”中的以下内容覆盖 UI 设置来实现此目的:
{
"brace_style": "collapse,preserve-inline"
}
关于javascript - 防止 Atom Beautify 自动格式化 es6 导入/对象解构 (React),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53354632/