【问题标题】:How do I disable There should be no space after '{'.eslintobject-curly-spacing in .eslintrc.js如何禁用 '{'.eslint object-curly-spacing in .eslintrc.js 之后应该没有空格
【发布时间】:2021-04-29 20:42:39
【问题描述】:

我正在使用 prettier,并使用带有 eslint 选项的 firebase init 初始化了我的项目。但是当我保存文件时,更漂亮的扩展会在对象花括号中添加间距,如下所示:

export { basicHTTP } from './http';

哪个 eslint 给了我一个错误: 无论如何都可以禁用它?

这是 firebase init 附带的 .eslintrc.js 文件:

module.exports = {
  root: true,
  env: {
    es6: true,
    node: true,
  },
  extends: [
    'eslint:recommended',
    'plugin:import/errors',
    'plugin:import/warnings',
    'plugin:import/typescript',
    'google',
  ],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: ['tsconfig.json', 'tsconfig.dev.json'],
    tsconfigRootDir: __dirname,
    sourceType: 'module',
  },
  ignorePatterns: [
    '/lib/**/*', // Ignore built files.
  ],
  plugins: ['@typescript-eslint', 'import'],
  rules: {
    quotes: ['error'],
  },
};

【问题讨论】:

标签: visual-studio-code eslint vscode-settings prettier eslintrc


【解决方案1】:

您可以在格式化代码时禁用在vscode 中添加空格。

打开settings.json并添加以下行

"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,

这将在 javascript 和 typescript 上修复它

【讨论】:

    【解决方案2】:

    将您的rules 修改为如下所示:

    rules: {
      'object-curly-spacing': ['error', 'always'],
      'quotes': ['error'],
    },
    

    在此更改之后,您可能必须修复所有 js 文件以使用相同的语法,但这只是一个好习惯。

    见:https://eslint.org/docs/rules/quotes

    【讨论】:

      猜你喜欢
      • 2018-09-08
      • 2023-02-22
      • 2020-08-26
      • 2022-11-15
      • 2016-11-06
      • 2020-04-05
      • 2020-04-06
      • 2023-03-26
      • 2019-06-17
      相关资源
      最近更新 更多