mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 00:19:36 +00:00

PR-URL: https://github.com/iojs/io.js/pull/1539 Fixes: https://github.com/iojs/io.js/issues/1253 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
/**
|
|
* @fileoverview Rule to require sorting of variables within a single Variable Declaration block
|
|
* @author Ilya Volodin
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
module.exports = function(context) {
|
|
|
|
var configuration = context.options[0] || {},
|
|
ignoreCase = configuration.ignoreCase || false;
|
|
|
|
return {
|
|
"VariableDeclaration": function(node) {
|
|
node.declarations.reduce(function(memo, decl) {
|
|
var lastVariableName = memo.id.name,
|
|
currenVariableName = decl.id.name;
|
|
|
|
if (ignoreCase) {
|
|
lastVariableName = lastVariableName.toLowerCase();
|
|
currenVariableName = currenVariableName.toLowerCase();
|
|
}
|
|
|
|
if (currenVariableName < lastVariableName) {
|
|
context.report(decl, "Variables within the same declaration block should be sorted alphabetically");
|
|
return memo;
|
|
} else {
|
|
return decl;
|
|
}
|
|
}, node.declarations[0]);
|
|
}
|
|
};
|
|
};
|