-
-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report correct positions for "order-in-*" rules #15
Conversation
and derive "order" from that
... that need to be moved further up
var nextSourceLine = firstPropertyOfNextType.node.loc.start.line; | ||
|
||
context.report(property, | ||
`The ${typeName} should be above the ${nextTypeName} on line ${nextSourceLine}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about updating this to provide also information about the initial line number?
var sourceLine = info.node.loc.start.line;
// ...
`The ${typeName} at line ${sourceLine} should be above the ${nextTypeName} on line ${nextSourceLine}`);`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's unnecessary because ESLint will add that information itself in the reporter
]; | ||
|
||
const NAMES = { | ||
'service': 'service injection', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about moving all those names to a separate file and using them inside property-order.js
? It looks like there are some unnecessary duplications in current solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, we could probably do that in a separate refactoring. I would also like to add the names of the properties to the type descriptions if possible, but I wanted to get this PR merged first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that's fine to me 👍
'relationship': 'relationship', | ||
'single-line-function': 'single-line function', | ||
'multi-line-function': 'multi-line function', | ||
'other': 'property', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe here we can also assume that otherwise there is an unknown
instead of other
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the problem is that "unknown" is different than "other". For "unknown" we really don't know what type of property it could be because we should've caught all the ones we know about. For "other" we don't analyze all and treat all the ones we haven't analyzed further the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so let's leave this as a separate concern. Anyway your solution seems to be better than enough and I'm happy to push this forward :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more approve and we're ready to release new version 🚀
var ember = require('../utils/ember'); | ||
var reportUnorderedProperties = require('../utils/property-order').reportUnorderedProperties; | ||
|
||
const ORDER = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using ES5 across the rest of the codebase. For now I'd revert to var
, and start an effort which would:
- Add lint config, ran as part of CI check - ensuring consistency here (linting ESLint plugin, inception :) ).
- Update test matrix to run not only Node.js 6 (as currently - https://github.com/netguru/eslint-plugin-ember/blob/master/.travis.yml) but also oldest version that we're striving to support (likely 4).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'unknown', | ||
]; | ||
|
||
const NAMES = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above about const
/var
.
return 'actions'; | ||
} else if (ember.isComponentCustomFunction(node)) { | ||
return 'method'; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This else
is redundant - if we got that far, we can just return
directly. I understand it's a matter of style preference, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should I change all the else if
too just if
too?
}; | ||
|
||
function toType(node) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line.
@@ -15,63 +15,114 @@ var eslintTester = new RuleTester(); | |||
eslintTester.run('order-in-controllers', rule, { | |||
valid: [ | |||
{ | |||
code: 'export default Controller.extend();', | |||
code: `export default Controller.extend();`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Template strings - see comment above about const
/var
, this is related.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template strings are supported in Node 4, shouldn't be a problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not requesting changes per se - but I think we should at the very least update CI config to consider oldest supported Node.js version before merging, since some ES6 features were used here (understandably - life is hard without them :) ). So let's wait with merge until we're 100% sure this won't cause any regressions - either by modifying Travis configuration, or resigning from const
/template strings for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolves #13
Example: