eslint 阻止强制将多行转换为单行

发布于 2022-09-13 00:33:51 字数 1628 浏览 19 评论 0

现在遇到的问题是如图的代码,我想保留这个格式,但是vs强制让我换成一行,
求教在不改单行长度限制和使用 <Component // 这样的hack怎么解决这个问题?
image.png

eslintrc

module.exports = {
  env: {
    browser: true,
    node: true,
  },
  root: true,
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint'],
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:react/recommended',
    'plugin:prettier/recommended',
  ],
  settings: {
    react: {
      pragma: 'React',
      version: 'detect',
    },
  },
  rules: {
    'max-len': [
      2,
      120,
      {
        ignoreStrings: true,
        ignoreTemplateLiterals: true,
        ignoreComments: true,
      },
    ],
    'no-var': 2,
    'one-var': [2, 'never'],
    'no-unexpected-multiline': 0,
    'react/react-in-jsx-scope': 0,
    'comma-spacing': [1, { before: false, after: true }],
    '@typescript-eslint/explicit-function-return-type': 0,
    '@typescript-eslint/explicit-module-boundary-types': 0,
    'react/jsx-first-prop-new-line': [2, 'multiline'],
    'react/jsx-max-props-per-line': [1, { maximum: 1 }],
  },
  parserOptions: {
    ecmaVersion: 10,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true,
    },
  },
}

prettierrc.js

module.exports = {
  semi: false,
  trailingComma: 'all',
  singleQuote: true,
  tabWidth: 2,
  endOfLine: 'lf',
  bracketSpacing: true,
  jsxBracketSameLine: true,
  arrowParens: "avoid",
  // printWidth: 80,
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谢绝鈎搭 2022-09-20 00:33:51

把鼠标移到红线上,看看提示里说的是触发了那条eslint规则?

飘逸的'云 2022-09-20 00:33:51

大概是因为没有在项目中安装eslint, 另外推荐去阅读下面三个插件,读了之后应该会比较清楚extends和plugins中每一项的作用,同时知道prettier和eslint的兼容问题

ESLint-plugin-React
eslint-config-prettier
eslint-plugin-prettier

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文