javascript - 防止 Atom Beautify 自动格式化 es6 导入/对象解构 (React)

标签 javascript ecmascript-6 atom-editor js-beautify atom-beautify

我正在 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 的等效项:

Brace style: collapse-preserve-inline

您可以在beautifier.io上尝试一下通过使用以下 UI 设置:

Brace style: keep with control statement, Preserve inline braces

您还可以通过使用“其他设置”中的以下内容覆盖 UI 设置来实现此目的:

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

关于javascript - 防止 Atom Beautify 自动格式化 es6 导入/对象解构 (React),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53354632/

相关文章:

php - docker + xdebug + 原子 : Breakpoints won't fire

javascript - 如何在放大时显示全文并在缩小时 chop 它

javascript - JavaScript 中的元组集?

javascript - 在 ES6 中导入常量的正确语法

javascript - 为什么以 ES6 方式定义 React 组件构造函数行不通?

python - 如何在编辑器中显示或打印大型 python 列表的所有元素

javascript - slider 未正确渲染

javascript - 如何在自定义元素中动态呈现 VueJS 模板

javascript - 基于索引对 json 嵌套数组进行排序未按预期工作

c++ - Atom Editor 中是否支持 C/C++ 语言的多行注释?