简体   繁体   中英

Custom indentation rule for eslint in arrays and objects

I could not find any standard rules for such indentation in arrays and objects. I need aliment by identificators ( ignoring brackets ). For our code style this approach is more convinient.

    // default indent is 4 spaces
    webix.ui({
        view: "popup",
        id: "group_name_edit",
        position: "center",
        body: {
            padding: 20,
            rows: [
                input,
              { cols: [    //       <-------- sample line
                  {},
                  { view: "button",
                    label: "Ok",
                    width: 150,
                  },
                ] 
              }
            ]
        },
    });

You could combine the indent and object-curly-newline rules:

  rules: {
    "indent": ["error", 4, { "SwitchCase": 1 }],
    "object-curly-newline": ["error", { "minProperties": 1 }]
  },

I copied your sample and applied auto-fix and this is the result:

webix.ui({
    view: "popup",
    id: "group_name_edit",
    position: "center",
    body: {
        padding: 20,
        rows: [
            input,
            {
                cols: [    
                    {},
                    {
                        view: "button",
                        label: "Ok",
                        width: 150,
                    },
                ] 
            }
        ]
    },
});

If you also want to enforce line breaks in arrays (which is not neccessary based on the given sample, as there already are line breaks), you could also add array-bracket-newline: ["error", "always"] to the rules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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