UNPKG

831 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to require sorting of variables within a single Variable Declaration block
3 * @author Ilya Volodin
4 */
5
6//------------------------------------------------------------------------------
7// Rule Definition
8//------------------------------------------------------------------------------
9
10module.exports = function(context) {
11
12 "use strict";
13
14 return {
15 "VariableDeclaration": function(node) {
16 node.declarations.reduce(function(memo, decl) {
17 if(decl.id.name < memo.id.name) {
18 context.report(decl, "Variables within the same declaration block should be sorted alphabetically");
19 return memo;
20 } else {
21 return decl;
22 }
23 }, node.declarations[0]);
24 }
25 };
26};