Search code examples
javascripthtmlvisual-studio-codeformattingprettier

How can i improve code formatting using prettier configuration


I am using prettier with vs code with the option "editor.formatOnSave": true

Here is my .prettierrc config:

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

is there a better way of doing that? and what should I put in the HTML option for a cleaner HTML code without having something like this:

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

my HTML files should be in the one line something like that and I am not sure what's going on

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

by the way, I am using angulars 1 it's an old project to maintain.


Solution

  • we should add printWidth option to 1000

    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',
                },
            },
        ],
    };