coffeelint-alphabetize-keys
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -32,6 +32,11 @@ // Generated by CoffeeScript 1.10.0 | ||
AlphabetizeKeys.prototype._lintClass = function(node, astApi) { | ||
var classKeys, instanceKeys, privateKeys; | ||
classKeys = []; | ||
instanceKeys = []; | ||
privateKeys = []; | ||
var id, keys, keysMapping, results; | ||
keysMapping = { | ||
instanceMethods: [], | ||
instanceVariables: [], | ||
privateMethods: [], | ||
privateVariables: [], | ||
staticMethods: [], | ||
staticVariables: [] | ||
}; | ||
node.body.expressions.forEach((function(_this) { | ||
@@ -46,8 +51,18 @@ return function(expression) { | ||
key = keyNode.base.value; | ||
if (key === 'this') { | ||
return classKeys.push(keyNode.properties[0].name.value); | ||
} else if (key[0] === '_') { | ||
return privateKeys.push(key); | ||
} else if (key !== 'constructor') { | ||
return instanceKeys.push(key); | ||
if (astApi.getNodeName(property.value) === 'Code') { | ||
if (key === 'this') { | ||
return keysMapping.staticMethods.push(keyNode.properties[0].name.value); | ||
} else if (key[0] === '_') { | ||
return keysMapping.privateMethods.push(key); | ||
} else if (key !== 'constructor') { | ||
return keysMapping.instanceMethods.push(key); | ||
} | ||
} else { | ||
if (key === 'this') { | ||
return keysMapping.staticVariables.push(keyNode.properties[0].name.value); | ||
} else if (key[0] === '_') { | ||
return keysMapping.privateVariables.push(key); | ||
} else { | ||
return keysMapping.instanceVariables.push(key); | ||
} | ||
} | ||
@@ -57,5 +72,8 @@ }); | ||
})(this)); | ||
this._lintNodeKeys(node, astApi, classKeys); | ||
this._lintNodeKeys(node, astApi, instanceKeys); | ||
return this._lintNodeKeys(node, astApi, privateKeys); | ||
results = []; | ||
for (id in keysMapping) { | ||
keys = keysMapping[id]; | ||
results.push(this._lintNodeKeys(node, astApi, keys)); | ||
} | ||
return results; | ||
}; | ||
@@ -62,0 +80,0 @@ |
{ | ||
"name": "coffeelint-alphabetize-keys", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Coffeelint rule that verifies object keys are in alphabetical order", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -8,8 +8,2 @@ # coffeelint-alphabetize-keys | ||
## Examples | ||
```coffee | ||
{keyA, keyB, keyC} # Good | ||
{keyC, keyB, keyA} # Bad | ||
``` | ||
## Installation | ||
@@ -30,1 +24,42 @@ | ||
``` | ||
## Examples | ||
### Objects | ||
```coffee | ||
{keyA, keyB, keyC} # Good | ||
{keyC, keyB, keyA} # Bad | ||
``` | ||
The rule applies to both defining and destructing objects. | ||
### Classes | ||
The rule differentiates between variables and methods, | ||
and each are required to only be individually alphabetical. | ||
```coffee | ||
# Good | ||
class A | ||
variableA: 1 * 2 | ||
variableB: 'abc' | ||
variableC: fn() | ||
methodA: -> | ||
methodB: -> | ||
methodC: -> | ||
# Bad | ||
class A | ||
variableC: fn() | ||
variableB: 'abc' | ||
variableA: 1 * 2 | ||
methodC: -> | ||
methodB: -> | ||
methodA: -> | ||
``` | ||
Methods and variables are also broken down into static, instance, and private instance (starting with `_`) | ||
where each are required to only be individually alphabetical. |
6623
119
64