-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Remove custom curly rule from canvas #27083
Remove custom curly rule from canvas #27083
Conversation
@stacey-gammon don't forget to The output looks mostly correct, but I'm reminded of why I set that rule in the first place. The diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.js
index f3f1672759..b0c995e048 100644
--- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.js
+++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.js
@@ -103,9 +103,9 @@ export const ply = () => ({
const datatablePromises = originalDatatables.map(originalDatatable => {
let expressionResultPromises = [];
- if (args.expression)
+ if (args.expression) {
expressionResultPromises = args.expression.map(expression => expression(originalDatatable));
- else expressionResultPromises.push(Promise.resolve(originalDatatable));
+ } else expressionResultPromises.push(Promise.resolve(originalDatatable));
return Promise.all(expressionResultPromises).then(combineAcross);
}); There's a handful of these cases, where the rule I chose produced consistent output, which is why I went with it. You're welcome to clean those things up by hand, of course, but it means that the linter isn't going to catch those uses, even though they conflict with the styleguide. |
💔 Build Failed |
So weird, I ran It looks also like there is existing code outside of Canvas that mixes the rule. And if I write in non canvas code, there is no lint error reported: That's why I thought this change would be simple, if we didn't auto fix anything, just stopped the auto fixing (until we can figure out a more consistent path forward - e.g. actually setting a rule and then fixing everything). so, thoughts on removing this without auto fixing anything? |
The CI won't pass that way, as you can see in the build failure above (more specifically, in this failure). |
This applies towards #25753... I appreciate you working on this while I tackle i18n. You're awesome, @stacey-gammon...! |
ahhhh, okay, it's because if it's on a single line, it's acceptable to the linter (e.g. |
Also, I don't know why it didn't work earlier but this time around i ran
in kibana dir and it worked. Maybe |
💔 Build Failed |
d92f033
to
3703548
Compare
💔 Build Failed |
So, the tooling doesn't actually match the styleguide? It's a pretty hard and clear rule that one-line conditionals are never acceptable: Always use braces for conditionals and loops// good
if (err) {
return cb(err);
}
// bad
if (err) cb(err);
// bad
if (err)
return cb(err); Even with this change, our tooling produces code that is in violation of the styleguide. This needs to be fixed upstream I think, right? |
expressionResultPromises = args.expression.map(expression => expression(originalDatatable)); | ||
else expressionResultPromises.push(Promise.resolve(originalDatatable)); | ||
} else expressionResultPromises.push(Promise.resolve(originalDatatable)); |
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 violates the styleguide: https://github.com/elastic/kibana/blob/master/style_guides/js_style_guide.md#always-use-braces-for-conditionals-and-loops
I think the requirement of human review for this seems to indicate a problem upstream 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.
Just for clarity, I'm totally cool with you merging this ahead of an upstream fix as long as you manually fix these.
this.setState({ selectedIndex: selectedIndex + 1 }); | ||
else this.setState({ selectedIndex: 0 }); | ||
} else this.setState({ selectedIndex: 0 }); |
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.
+1 This change should not require human review and produce code that matches the style guide. If anything, this PR is a great test case for the effectiveness of the rule. |
3703548
to
fa85084
Compare
I touched on this in the initial comment - our style guide and the airbnb style guide conflict. The linter rule is inline with the airbnb style guide. If we decide there is no good reason to deviate from the airbnb style guide, then those specific one liners are allowed to stay and would not require any manual intervention. The situation prior to this PR was:
The situation with this PR in its current form:
I agree there is a more ideal situation:
This PR tackles the short term approach. I don't think I should need to manually tweak all of Canvas's code in order to get this merged (which would still leave Kibana code containing the accepted one liners). I can create an issue for the longer term approach, since I agree the situation as it stands is not ideal, as our rule does not accurately reflect the style guide. |
💚 Build Succeeded |
You're trying to enforce the styleguide, and you've introduced 2 changes that do not follow it. It seems reasonable to ask you to fix them in review. |
I thought we already went through that, but I can't find the issue where this would have been discussed. The history of the styleguide is interesting though, we used to only require curlies for multi-line, and prefer them over single-line conditionals. Then later, in #7435 the rule became always use curlies, no exception. So maybe the styleguide was changed but the linter was never actually updated to enforce it correctly? |
That code existed prior to this PR, I didn't introduce it. I used automatic fixing to make sure canvas code adheres to Kibana's current linting rules. The second part - changing the linting rules to reflect the style guide, is a separate issue that can be tackled in another PR, by anyone who has a desire to do so. And at that point, automatic fixing can be used to bulk fix the places in canvas, and elsewhere, in one go. I re-opened #11398 and asked Kibana folks to weigh in so we can figure out which direction to go in for the longer term solution. |
I think we can close this PR with #27176 |
Remove the eslint rule for canvas that will cause this code:
to be reported as an error, and auto fixed to this code:
Our style guide explicitly states the former is better . So I thought about adding a rule to be explicit about our style guide suggestion which, imo, being explicit is better than not. But then we also talked about just adhering to the airbnb style guide, which says you can do either. So rather that really get into the weeds about the right rules we should be using, which would end up being a much bigger conversation, I think the best short term strategy is just to remove the error output.
Oh and actually I think I'm noticing it so much because I believe the tslinter actually prefers the first and will auto correct to it.