sort-vars

要求对同一声明块中的变量进行排序

一些该规则报告的问题可以通过 --fix 命令行选项 自动修复

在同一块中声明多个变量时,一些开发人员更喜欢按字母顺序对变量名称进行排序,以便以后更容易找到必要的变量。其他人则认为它增加了复杂性并成为维护的负担。

规则详情

此规则检查所有变量声明块并验证所有变量是否按字母顺序排序。规则的默认配置是区分大小写的。

此规则的错误代码示例:

/*eslint sort-vars: "error"*/

var b, a;

var a, B, c;

var a, A;

NwldEOIuHKyv0R+3pkUiuSlq7yzV1WsYiQ97qEISbUzf2ki35mZ0HV/HKFTSzvSb

/*eslint sort-vars: "error"*/

var a, b, c, d;

var _a = 10;
var _b = 20;

var A, a;

var B, a, c;

cRggsLAoeyD+gHqxQaN6WaW+3MTZYKjo0bt+Tenp9EZmxIFJh43amCEFVlBkv0tGgLzop6qb0x1lY0xB1bsOQuE99IZajyG2gE7a9bPWyZeKkXHr4UGCWfZkm8oXE9tUDBfGlcBXzwKYxyThlM9S2Aqt7pLibmK24+NI8I/ujpSdvvkTyif6PvwfMREWT9hDYzNXtAJ3kOpp+sTpPooGKg==

/*eslint sort-vars: "error"*/

var c, d, a, b;

XBchsjCtPXrb0h6ht3n5zZzW/sNbqeotse41IGSq9Uf0aShx672698sNR684y81+

/*eslint sort-vars: "error"*/

var c, d, a, e;

选项

zaHvPcgsugX4MUASJPYCXtmNqHTCIN7Divdsz+quHFroUBdd/PBMuxfBLX/bmPvZ

    RBFrdS5Q6NfjuVRcsNrMXdQ3KdP8juFttVmJe+djK+91fWjxMSqUJnOfDX2eZAKFX/Au1IiIOVxBwZVDz77brWARJpc+SntuiBNO2vT1P/ZWs0wC2rWk9KFdnbBEgCUIM/6EXKX4ZgUq/V+wM/uv52f7QSveeUrAF279zdGAqvA=

ignoreCase

Bv4sMSnguAQJ4kJJZCKogntI43+lhYOH9+VFi/vrhj41g9mqi+P8MUDBnQhCOBThJIuAynFh664P9K2WM/IA9bXc4n3oWfBFZYrJWsxM9YsA+go4dln9YCqhBQsPobyO

/*eslint sort-vars: ["error", { "ignoreCase": true }]*/

var a, A;

var a, B, c;

何时不使用

Kkor7dBeRQ2QnVveEEeBWCvUtW9nhqR1N3BU+/A5JDEeWLePU+Bf9jDXf21RXBQW3BtJ6Gb88pL7WlYh5fBP+1QUZnnhRPsTQYZSd7ftKbnsvitEfINr3ZslMrAoR1tuQBD+dQ/QiiKLbf7C8AwN+RxywXnQB3cI/l3uh9YdT7l21rn+Ycm7tGqwcy24LB0qe2BlnI4WJkUPJfHPXyIC2KzWBEJHsVVnRPbHqI/yb+5pyuBJ2iRqI53ykUsRqoQ+PdAyhHl4JzYZd9L83QDWEQ==