Skip to content
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

Merged
merged 19 commits into from
Feb 5, 2017

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Feb 3, 2017

Resolves #13

Example:

export default Ember.Route.extend({
  foo: 'bar',
  foo2: 'bar',

  setupController() {},

  foo3: 'bar',

  actions: {
    bar() {}
  },

  model() {

  },

  foo4: 'bar',
});
app/routes/foo.js
   9:3   error  The property should be above the lifecycle hook on line 7    ember/order-in-routes
  15:3   error  The model hook should be above the lifecycle hook on line 7  ember/order-in-routes
  19:3   error  The property should be above the lifecycle hook on line 7    ember/order-in-routes

@Turbo87 Turbo87 changed the title Report correct positions for "order-in-components" rule Report correct positions for "order-in-*" rules Feb 3, 2017
var nextSourceLine = firstPropertyOfNextType.node.loc.start.line;

context.report(property,
`The ${typeName} should be above the ${nextTypeName} on line ${nextSourceLine}`);
Copy link
Member

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}`);`

Copy link
Member Author

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',
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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',
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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 :)

Copy link
Member

@michalsnik michalsnik left a 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 = [
Copy link
Contributor

@bardzusny bardzusny Feb 5, 2017

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:

Copy link
Contributor

@bardzusny bardzusny Feb 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just created related issues - see #17 , #18 .

'unknown',
];

const NAMES = {
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Member Author

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) {

Copy link
Contributor

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();`,
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Contributor

@bardzusny bardzusny left a 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.

Copy link
Contributor

@bardzusny bardzusny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little uncomfortable with basic ES6 constructs appearing in the codebase for the first time out of nowhere. With #17, #18 and #19 on the way though - I'm happy to approve. 🚢 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants