首页 > 解决方案 > ESlint javascript config - 删除数组中第一个对象之前的新行

问题描述

我正在使用 VS Code 和它的格式化选项。启用后,它始终会删除数组中第一个对象上的空行。

格式化前的示例:

  var arr = [
    {
      id: 1
    },
    {
      id: 2
    }
  ]

变成:

  var arr = [{
      id: 1
    },
    {
      id: 2
    }
  ]

格式化后。这弄乱了我的代码折叠。ESlint 中的配置是什么?

截至目前的 Eslint 配置:

module.exports = {
  root: true,

  extends: ['eslint:recommended', 'plugin:vue/essential'],

  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-undef': 'off',
    'no-unused-vars': 'off',
  },

  parserOptions: {
    parser: 'babel-eslint',
  },

  overrides: [
    {
      files: [
        '**/__tests__/*.{j,t}s?(x)',
        '**/tests/unit/**/*.spec.{j,t}s?(x)',
      ],
      env: {
        mocha: true,
      },
    },
    {
      files: [
        '**/__tests__/*.{j,t}s?(x)',
        '**/tests/unit/**/*.spec.{j,t}s?(x)',
      ],
      env: {
        mocha: true,
      },
    },
  ],

  env: {
    node: true,
  },
}

标签: javascriptvisual-studio-codeeslintprettiereslintrc

解决方案


这弄乱了我的代码折叠。ESlint 中的配置是什么?

强制将对象属性放置在单独的行上(object-property-newline)。


推荐阅读