【问题标题】:How can i improve code formatting using prettier configuration如何使用更漂亮的配置改进代码格式
【发布时间】:2020-06-28 23:17:10
【问题描述】:

我正在使用 prettiervs code 以及选项 "editor.formatOnSave": true

这是我的 .prettierrc 配置:

module.exports = {
    semi: false,
    overrides: [
        {
            files: ['*.js', '*.json', '*.css'],
            options: {
                trailingComma: 'es5',
                tabWidth: 4,
                semi: true,
                singleQuote: true,
            },
        },
        {
            files: ['*.html'],
            options: {},
        },
    ],
};

有没有更好的方法呢?以及我应该在 HTML 选项中添加什么以获得更清晰的 HTML 代码,而无需像这样:

<tr
                    ng-repeat="student in displayVars.studentsToShow track by student.id"
                >

我的 HTML 文件应该在一行中,但我不确定发生了什么

<tr ng-repeat="student in displayVars.studentsToShow track by student.id">

顺便说一句,我使用的是angulars 1,这是一个需要维护的旧项目。

【问题讨论】:

    标签: javascript html visual-studio-code formatting prettier


    【解决方案1】:

    我们应该在 1000 中添加 printWidth 选项

    module.exports = {
        semi: false,
        overrides: [
            {
                files: ['*.js', '*.json', '*.css'],
                options: {
                    trailingComma: 'es5',
                    tabWidth: 4,
                    semi: true,
                    singleQuote: true,
                },
            },
    
            {
                files: ['*.html'],
                options: {
                    printWidth: 1000,
                    tabWidth: 4,
                    htmlWhitespaceSensitivity: 'ignore',
                    proseWrap: 'never',
                },
            },
        ],
    };
    

    【讨论】:

      猜你喜欢
      • 2020-04-28
      • 2019-10-26
      • 1970-01-01
      • 2023-02-19
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 2020-09-03
      • 2022-12-23
      相关资源
      最近更新 更多