简体   繁体   English

“修复所有可自动修复的问题”并没有修复尽可能多的问题 vscode-eslint

[英]'Fix all auto-fixable problems' doesn't fix as many issues as possible vscode-eslint

Often times, when I try to run the , Fix all auto-fixable issues command on my Javascript files, the app goes into a never-ending loop of moving the tabs/spaces around, but never really getting satisfied:很多时候,当我尝试在我的 Javascript 文件上运行, Fix all auto-fixable issues命令时,该应用程序会进入一个永无止境的移动制表符/空格的循环,但从未真正感到满意:

自动修复

My .eslintrc.js is as follows:我的.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',
      },
    },
  },
};

Could anyone help me with resolving this issue?谁能帮我解决这个问题?

UPD:更新:

Now you can just choose vscode-eslint / prettier as your default formatter and it should format file in one pass:现在,你可以选择vscode-eslint / prettier为默认格式,它应该在一个通格式文件:

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

OLD:老的:

This is old issue in vscode-eslint extention due to limitation of vscode formatting API.由于 vscode 格式化 API 的限制,这是vscode-eslint扩展中的老问题。 One possible solution is to fix code via cli:一种可能的解决方案是通过 cli 修复代码:

eslint --fix

Install extension Toggle Format on Save, And press CMD+SHIFT+P type Toggle Format on Save > Enter.在 Save 上安装扩展 Toggle Format,然后按 CMD+SHIFT+P 在 Save > Enter 上输入 Toggle Format。

Hope to help.希望有所帮助。

Try adding following configs to vscode settings.json尝试将以下配置添加到 vscode settings.json

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

Simple fix: In VS Code open setting.json file and put "editor.formatOnSave": true, .简单修复:在 VS Code 中打开setting.json文件并将"editor.formatOnSave": true, . This will autofix on save.这将在保存时自动修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM