Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved error messages for
order-in
rules (#23)
* rules/order: Extract common determinePropertyType() function * utils/property-order: Merge duplicate "service" checks * utils/property-order: Add missing strict mode directive * utils/property-order: Merge duplicate "unknown" branches * utils/property-order: Merge duplicate "method" branches * utils/property-order: Merge duplicate "actions" branches * utils/property-order: Merge duplicate "property" branches * rules/order: Merge NAMES hashes * rules/order: Merge duplicate code * utils/property-order: Inline toPropertyInfo() function * utils/property-order: Sort unknown types below everything else * utils/property-order: Merge duplicate "observer" branches * utils/property-order: Merge duplicate "single/multi-line-function" branches * rules/order: Allow users to override the default order * utils/property-order: Extract getOrder() function * utils/property-order: Allow multiple types per order * utils/property-order: Extract getName() function * utils/property-order: Include key names in property descriptions * utils/property-order: Replace "default-property" with "inherited-property"
- Loading branch information
Showing
9 changed files
with
308 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,31 @@ | ||
'use strict'; | ||
|
||
var ember = require('../utils/ember'); | ||
var reportUnorderedProperties = require('../utils/property-order').reportUnorderedProperties; | ||
var propOrder = require('../utils/property-order'); | ||
|
||
var reportUnorderedProperties = propOrder.reportUnorderedProperties; | ||
|
||
const ORDER = [ | ||
'attribute', | ||
'relationship', | ||
'single-line-function', | ||
'multi-line-function', | ||
'other', | ||
]; | ||
|
||
const NAMES = { | ||
'attribute': 'attribute', | ||
'relationship': 'relationship', | ||
'single-line-function': 'single-line function', | ||
'multi-line-function': 'multi-line function', | ||
'other': 'property', | ||
}; | ||
|
||
function toType(node) { | ||
if (ember.isModule(node.value, 'attr', 'DS')) { | ||
return 'attribute'; | ||
} else if (ember.isRelation(node)) { | ||
return 'relationship'; | ||
} else if (ember.isSingleLineFn(node)) { | ||
return 'single-line-function'; | ||
} else if (ember.isMultiLineFn(node)) { | ||
return 'multi-line-function'; | ||
} else { | ||
return 'other'; | ||
} | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
// Organizing - Organize your models | ||
// Attributes -> Relations -> Computed Properties | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = function(context) { | ||
var options = context.options[0] || {}; | ||
var order = options.order || ORDER; | ||
|
||
return { | ||
CallExpression: function(node) { | ||
if (!ember.isDSModel(node)) return; | ||
|
||
reportUnorderedProperties(node, context, function(property) { | ||
var type = toType(property); | ||
|
||
return { | ||
node: property, | ||
name: NAMES[type], | ||
order: ORDER.indexOf(type) | ||
}; | ||
}); | ||
reportUnorderedProperties(node, context, 'model', order); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,33 @@ | ||
'use strict'; | ||
|
||
var ember = require('../utils/ember'); | ||
var reportUnorderedProperties = require('../utils/property-order').reportUnorderedProperties; | ||
var propOrder = require('../utils/property-order'); | ||
|
||
var reportUnorderedProperties = propOrder.reportUnorderedProperties; | ||
|
||
const ORDER = [ | ||
'service', | ||
'default-property', | ||
'inherited-property', | ||
'property', | ||
'model', | ||
'lifecycle-hook', | ||
'actions', | ||
'method', | ||
'unknown', | ||
]; | ||
|
||
const NAMES = { | ||
'service': 'service injection', | ||
'default-property': 'default property', | ||
'property': 'property', | ||
'model': 'model hook', | ||
'lifecycle-hook': 'lifecycle hook', | ||
'actions': 'actions hash', | ||
'method': 'custom method', | ||
'unknown': 'unknown property type', | ||
}; | ||
|
||
function toType(node) { | ||
|
||
if (ember.isInjectedServiceProp(node.value)) { | ||
return 'service'; | ||
} else if (ember.isRouteDefaultProp(node)) { | ||
return 'default-property'; | ||
} else if (ember.isCustomProp(node)) { | ||
return 'property'; | ||
} else if (ember.isModelProp(node)) { | ||
return 'model'; | ||
} else if (ember.isRouteDefaultMethod(node)) { | ||
return 'lifecycle-hook'; | ||
} else if (ember.isActionsProp(node)) { | ||
return 'actions'; | ||
} else if (ember.isRouteCustomFunction(node)) { | ||
return 'method'; | ||
} else { | ||
return 'unknown'; | ||
} | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
// Organizing - Organize your routes and keep order in objects | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = function(context) { | ||
var message = 'Check order of properties'; | ||
|
||
function report(node) { | ||
context.report(node, message); | ||
} | ||
var options = context.options[0] || {}; | ||
var order = options.order || ORDER; | ||
|
||
return { | ||
CallExpression: function(node) { | ||
if (!ember.isEmberRoute(node)) return; | ||
|
||
reportUnorderedProperties(node, context, function(property) { | ||
var type = toType(property); | ||
|
||
return { | ||
node: property, | ||
name: NAMES[type], | ||
order: ORDER.indexOf(type) | ||
}; | ||
}); | ||
reportUnorderedProperties(node, context, 'route', order); | ||
} | ||
}; | ||
}; |
Oops, something went wrong.