【问题标题】:'Fix all auto-fixable problems' doesn't fix as many issues as possible vscode-eslint'修复所有可自动修复的问题'并没有解决尽可能多的问题 vscode-eslint
【发布时间】:2019-02-18 17:32:37
【问题描述】:

通常,当我尝试在我的 Javascript 文件上运行 , Fix all auto-fixable issues 命令时,应用程序会进入一个不断移动制表符/空格的循环,但是永远不会真正满足:

我的.eslintrc.js如下:

const fs = require('fs');

const prettierOptions = JSON.parse(fs.readFileSync('./.prettierrc', 'utf8'));

module.exports = {
  parser: 'babel-eslint',
  extends: ['airbnb', 'prettier', 'prettier/react'],
  plugins: ['prettier', 'redux-saga', 'react', 'jsx-a11y'],
  env: {
    browser: true,
    node: true,
    jest: true,
    es6: true,
  },
  parserOptions: {
    ecmaVersion: 6,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true,
    },
  },
  rules: {
    'prettier/prettier': ['error', prettierOptions],
    'arrow-body-style': [2, 'as-needed'],
    'class-methods-use-this': 0,
    'comma-dangle': [2, 'always-multiline'],
    'import/imports-first': 0,
    'import/newline-after-import': 0,
    'import/no-dynamic-require': 0,
    'import/no-extraneous-dependencies': 0,
    'import/no-named-as-default': 0,
    'import/no-unresolved': 2,
    'import/no-webpack-loader-syntax': 0,
    'import/prefer-default-export': 0,
    indent: [
      2,
      2,
      {
        SwitchCase: 1,
      },
    ],
    "jsx-a11y/anchor-is-valid": 0,
    'jsx-a11y/aria-props': 2,
    'jsx-a11y/heading-has-content': 0,
    'jsx-a11y/label-has-for': 2,
    'jsx-a11y/mouse-events-have-key-events': 2,
    'jsx-a11y/role-has-required-aria-props': 2,
    'jsx-a11y/role-supports-aria-props': 2,
    'max-len': 0,
    'newline-per-chained-call': 0,
    'no-confusing-arrow': 0,
    'no-console': 1,
    'no-use-before-define': 0,
    'prefer-template': 2,
    'react/jsx-closing-tag-location': 0,
    'react/forbid-prop-types': 0,
    'react/jsx-first-prop-new-line': [2, 'multiline'],
    'react/jsx-filename-extension': 0,
    'react/jsx-no-target-blank': 0,
    'react/require-default-props': 0,
    'react/require-extension': 0,
    'react/self-closing-comp': 0,
    'react/sort-comp': 0,
    'redux-saga/no-yield-in-race': 2,
    'redux-saga/yield-effects': 2,
    'require-yield': 0,
  },
  settings: {
    'import/resolver': {
      webpack: {
        config: './internals/webpack/webpack.prod.babel.js',
      },
    },
  },
};

谁能帮我解决这个问题?

【问题讨论】:

    标签: javascript visual-studio-code eslint vscode-extensions vscode-eslint


    【解决方案1】:

    UPD:

    现在您可以选择vscode-eslint / prettier 作为您的默认格式化程序,它应该一次性格式化文件:

    1. ctrl + shift + p
    2. 选择Format document with...
    3. 选择Configure default foramtter
    4. 选择您喜欢的格式化程序

    旧:

    由于 vscode 格式化 API 的限制,这是 vscode-eslint 扩展中的老问题。一种可能的解决方案是通过 cli 修复代码:

    eslint --fix
    

    【讨论】:

      【解决方案2】:

      尝试将以下配置添加到 vscode settings.json

      "editor.codeActionsOnSave": {
          // For ESLint
          "source.fixAll.eslint": true,
          // For TSLint
          "source.fixAll.tslint": true,
          // For Stylelint
          "source.fixAll.stylelint": true
        },
      

      【讨论】:

        【解决方案3】:

        安装扩展在保存时切换格式, 然后按 CMD+SHIFT+P 键入 Toggle Format on Save > Enter。

        希望能提供帮助。

        【讨论】:

          猜你喜欢
          • 2020-11-08
          • 1970-01-01
          • 2020-08-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-04-06
          • 1970-01-01
          • 2022-07-26
          相关资源
          最近更新 更多