/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var DEFAULTS = require( './defaults.json' );


// VARIABLES //

var rule;


// FUNCTIONS //

/**
* Checks whether a number is smaller than a comparison value.
*
* @private
* @param {number} a - input value
* @param {number} b - comparison value
* @returns {boolean} boolean indicating if `a` is smaller than `b`
*/
function isSmallerOrEqual( a, b ) {
	return a <= b;
}

/**
* Checks whether a number is smaller than a comparison value.
*
* @private
* @param {number} a - input value
* @param {number} b - comparison value
* @returns {boolean} boolean indicating if `a` is greater than `b`
*/
function isGreaterOrEqual( a, b ) {
	return a >= b;
}

/**
* Rule enforcing variable declarations inside of functions to be ordered by length.
*
* @param {Object} context - ESLint context
* @returns {Object} validators
*/
function main( context ) {
	var options;
	var order;
	var fun;

	options = context.options[ 0 ];
	order = DEFAULTS.order;
	if ( hasOwnProp( options, 'order' ) ) {
		order = options.order;
	}
	switch ( order ) {
	case 'increasing':
		fun = isGreaterOrEqual;
		break;
	case 'decreasing':
	default:
		fun = isSmallerOrEqual;
		break;
	}

	/**
	* Reports the error message.
	*
	* @private
	* @param {string} msg - error message
	* @param {Object} loc - lines of code (object with `start` and `end` properties)
	*/
	function report( msg, loc ) {
		context.report({
			'node': null,
			'message': msg,
			'loc': loc
		});
	}

	/**
	* Checks whether the variable declarations inside of the supplied node are ordered.
	*
	* @private
	* @param {ASTNode} node - node to examine
	* @returns {void}
	*/
	function validate( node ) {
		var prevLength;
		var body;
		var elem;
		var name;
		var i;

		body = node.body.body;
		prevLength = null;
		for ( i = 0; i < body.length; i++ ) {
			elem = body[ i ];
			if ( elem.type === 'VariableDeclaration' && elem.kind === 'var' ) {
				name = elem.declarations[ 0 ].id.name;
				if ( prevLength && !fun( name.length, prevLength ) ) {
					return report( 'Variable declarations inside of function are not ordered by length (in '+ order +' order)', node.loc );
				}
				prevLength = name.length;
			}
		}
	}

	return {
		'FunctionDeclaration': validate,
		'FunctionExpression': validate
	};
}


// MAIN //

rule = {
	'meta': {
		'docs': {
			'description': 'require variable declarations inside of functions to be ordered by length'
		},
		'schema': [
			{
				'order': [ 'increasing', 'decreasing' ]
			}
		]
	},
	'create': main
};


// EXPORTS //

module.exports = rule;

@@ -835,32 +835,44 @@
 is smaller than 
+or equal to 
 a comparison val
@@ -1119,29 +1119,29 @@
 mber is 
-small
+great
 er than 
 a compar
@@ -1132,16 +1132,28 @@
 er than 
+or equal to 
 a compar

Fix descriptions