首页 > 解决方案 > 使用 eslint 和 prettier 在 typescript 中配置换行符

问题描述

我正在用打字稿写一个项目。我在项目的根目录中定义了一些关于 prettier 和 eslintrc.js 文件的配置。当 max-len 达到 100 个字符时,每个参数都设置在一行中。

但是,我想要完成的结果是尽可能多地填充线条。例如 :

const subPopulate = { path: 'appointments', match: { memberId: new Types.ObjectId(member._id) }, populate: 'notes', test1: '123', test2: '456'};

我使用 prettier 和 eslintrc 有什么:

const subPopulate = {
  path: 'appointments',
  match: { memberId: new Types.ObjectId(member._id) },
  populate: 'notes',
  test1: '123',
  test2: '456',
};

我想尽可能多地填写这条线,我想要什么:

const subPopulate = { path: 'appointments', 
  match: { memberId: new Types.ObjectId(member._id) },
  populate: 'notes', test1: '123', test2: '456'};

我想在定义变量和函数时这样做(同样的问题)。

试图在eslint 规则和更漂亮的规则中找到一些东西,但没有运气:(

我的更漂亮

{
  "singleQuote": true,
  "trailingComma": "all",
  "bracketSpacing": true,
  "printWidth": 100
}

我的 eslintrc

module.exports = {
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: 'tsconfig.json',
    sourceType: 'module',
  },
  plugins: ['@typescript-eslint/eslint-plugin'],
  extends: ['plugin:@typescript-eslint/recommended'],
  root: true,
  env: {
    node: true,
    jest: true,
  },
  ignorePatterns: ['.eslintrc.js'],
  rules: {
    '@typescript-eslint/interface-name-prefix': 'off',
    '@typescript-eslint/explicit-function-return-type': 'off',
    '@typescript-eslint/explicit-module-boundary-types': 'off',
    '@typescript-eslint/no-explicit-any': 'off',
    'max-len': ['error', { code: 100 }],
    'no-var': 'error',
    semi: 'error'
  },
};

标签: typescripteslintprettier

解决方案


推荐阅读