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

chore(binding-http): enable eslint/strict-boolean-expressions #1097

Merged
merged 19 commits into from
Oct 13, 2023

Conversation

JKRhb
Copy link
Member

@JKRhb JKRhb commented Sep 22, 2023

Ticks one of the boxes of #1046 :)

@codecov
Copy link

codecov bot commented Sep 22, 2023

Codecov Report

Attention: 91 lines in your changes are missing coverage. Please review.

Comparison is base (7a99bf9) 75.71% compared to head (4624a03) 75.61%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1097      +/-   ##
==========================================
- Coverage   75.71%   75.61%   -0.10%     
==========================================
  Files          80       80              
  Lines       16106    16153      +47     
  Branches     1507     1518      +11     
==========================================
+ Hits        12194    12214      +20     
- Misses       3874     3898      +24     
- Partials       38       41       +3     
Files Coverage Δ
packages/binding-http/src/http-client-impl.ts 66.01% <60.00%> (-0.25%) ⬇️
packages/binding-http/src/routes/properties.ts 61.53% <0.00%> (ø)
...ackages/binding-http/src/oauth-token-validation.ts 93.02% <50.00%> (-0.55%) ⬇️
packages/binding-http/src/routes/action.ts 58.26% <25.00%> (ø)
packages/binding-http/src/routes/event.ts 17.39% <0.00%> (ø)
...ckages/binding-http/src/routes/property-observe.ts 16.94% <0.00%> (ø)
packages/binding-http/src/routes/common.ts 59.04% <22.22%> (-0.96%) ⬇️
packages/binding-http/src/routes/property.ts 65.41% <22.22%> (-1.00%) ⬇️
...kages/binding-http/src/routes/thing-description.ts 48.40% <26.31%> (+1.91%) ⬆️
packages/binding-http/src/credential.ts 80.35% <58.13%> (-0.59%) ⬇️
... and 1 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JKRhb JKRhb force-pushed the http-strict-boolean branch from f242b2c to 640a128 Compare September 22, 2023 19:09
@JKRhb JKRhb marked this pull request as ready for review September 22, 2023 19:13
@JKRhb JKRhb force-pushed the http-strict-boolean branch 3 times, most recently from 7c99ec6 to 31a0adf Compare September 22, 2023 19:49
@JKRhb JKRhb force-pushed the http-strict-boolean branch from 31a0adf to f7cbf23 Compare September 26, 2023 09:13
@JKRhb
Copy link
Member Author

JKRhb commented Sep 26, 2023

(Rebased the PR against the latest state of master.)

Copy link
Member

@relu91 relu91 left a comment

Choose a reason for hiding this comment

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

I selected request changes but they are mostly suggestions and comments. I'm open to changing my mind on the suggested changes, let me know!

packages/binding-http/src/codecs/tuya-codec.ts Outdated Show resolved Hide resolved
packages/binding-http/src/credential.ts Outdated Show resolved Hide resolved
packages/binding-http/src/routes/property.ts Outdated Show resolved Hide resolved
packages/binding-http/src/http-server.ts Outdated Show resolved Hide resolved
packages/binding-http/src/http-server.ts Outdated Show resolved Hide resolved
packages/binding-http/src/http-server.ts Outdated Show resolved Hide resolved
packages/binding-http/src/http-server.ts Outdated Show resolved Hide resolved
packages/binding-http/src/http-server.ts Outdated Show resolved Hide resolved
packages/binding-http/src/http-server.ts Outdated Show resolved Hide resolved
@@ -565,35 +563,33 @@ export default class HttpServer implements ProtocolServer {
return;
}

if (thing.securityDefinitions) {
Copy link
Member

@relu91 relu91 Sep 30, 2023

Choose a reason for hiding this comment

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

Given the comment, this should probably be: if(thing.security == null). Right?

Copy link
Member Author

Choose a reason for hiding this comment

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

As thing.security is a mandatory field, I think this part of the code covers the thing.security.length === 0 case (i.e., the test for thing.security.length > 0 above does not return true and we did not return from the method early).

This could definitely be a bit clearer, though – maybe we can perform some additional cleanups after this PR has been merged?

Copy link
Member

Choose a reason for hiding this comment

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

It is a mandatory field in the TD but not in the ThingExposeInit. In my understanding, there is nothing so far to check if the security is defined. Probably, due to #911. Currently, we just ask the bindings to handle the ExposeThingInit see https://github.com/eclipse-thingweb/node-wot/blob/master/packages/core/src/servient.ts#L38 . So thing.security might be also null at that point in time. Do the new changes take care of this too? 🤔 .

Copy link
Member Author

Choose a reason for hiding this comment

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

Ohh, I see, then this case might not be covered yet! I will double-check this :)

Copy link
Member Author

@JKRhb JKRhb Oct 3, 2023

Choose a reason for hiding this comment

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

Hmm, the parameter passed into the method is of type ExposedThing with security being of type security: string | [string, ...string[]] – so it is mandatory, but I suppose at least one thing that is missing is the case when security is a single string?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to provide a fix now in 7a0bd02 – I think that should work for now, however, it seems to me as if the handling of security and securityDefinitions needs to be revisited in general.

Copy link
Member Author

@JKRhb JKRhb Oct 3, 2023

Choose a reason for hiding this comment

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

Aparently, the code has been correct before and did not work anymore after the change, so I reverted it. Seems to me as if the typing of the security field in the ExposedThing class/interface might need to be fixed.

Copy link
Member

Choose a reason for hiding this comment

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

I know that it is counter-intuitive and I agree that the bug is somewhere else (e.g. #911). If you go upwards in the call hierarchy you'll notice that after producing method nobody checks if security is defined, tomorrow I'll try with a practical example. However for the time being we can merge the PR and track this issue in #911 .

@JKRhb
Copy link
Member Author

JKRhb commented Sep 30, 2023

Hmm, the persisting linting errors are still puzzling me a bit, as I don't get the same errors on my own machine. I think I now remember that they were the reason why I used the === true approach in the first place. It seems to me, though, that some of the errors are caused by the TS config and using ES6 as the compile target.

I think the easiest resolution would be to stick to === true for now and maybe revisit this issue later.

@JKRhb JKRhb force-pushed the http-strict-boolean branch from 3fb7def to 4f77d90 Compare October 2, 2023 11:41
@JKRhb
Copy link
Member Author

JKRhb commented Oct 2, 2023

Since the updated eslint packages did not solve the issue and to make the history a bit cleaner, I dropped the commits merged in from #1103 and rebased against master.

@JKRhb JKRhb marked this pull request as ready for review October 3, 2023 08:00
@JKRhb JKRhb requested review from relu91 and danielpeintner October 3, 2023 08:00
@JKRhb JKRhb force-pushed the http-strict-boolean branch from e1d7c40 to 2ada086 Compare October 4, 2023 22:03
@JKRhb
Copy link
Member Author

JKRhb commented Oct 4, 2023

Rebased against master to resolve a conflict after the merging of #1103 – with the latest changes, I think/hope this PR should also be ready for merging now :)

@JKRhb JKRhb force-pushed the http-strict-boolean branch from 2ada086 to 467f883 Compare October 12, 2023 19:57
@JKRhb JKRhb force-pushed the http-strict-boolean branch from 467f883 to 99c1082 Compare October 12, 2023 20:00
Copy link
Member

@relu91 relu91 left a comment

Choose a reason for hiding this comment

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

All the comments above have been resolved. Merging. Thanks @JKRhb !!!

@relu91 relu91 merged commit b8aeef6 into eclipse-thingweb:master Oct 13, 2023
7 checks passed
@JKRhb JKRhb deleted the http-strict-boolean branch October 13, 2023 09:05
@JKRhb
Copy link
Member Author

JKRhb commented Oct 13, 2023

Awesome, thank you @relu91! :)

Maybe one thing, though: It's probably best to use the squashing strategy when merging PRs like this one, as the fixup! commits I am using are actually intended to be squashed eventually (see, e.g., here). After the discussions we had recently, I refrained from doing so which now, unfortunately, led to some of those commits "leaking" into the main branch. Maybe we could discuss our workflow with handling PRs more generally at one of the upcoming committer meetings? Potential solutions could be to let the person opening the PR merge the PR after receiving the required approvals, provided that it is a committer, or let them also give a final green light before the merge.

Personally, I would prefer if we would allow to also perform some clean-up in the PR (i.e., rebasing, squashing, and reordering of commits) itself after the reviewers gave their approval since having a clean commit history in the main branch is always a nice thing to have, I think. But maybe we could discuss this also at some point (in not too much detail) in a synchronous manner (which would also probably lead to the resolution of #558).

@danielpeintner
Copy link
Member

As said before.. rebasing, squashing, and reordering of commits while working on a PR makes it very difficult to follow what has changed between commits.

I guess the only thing we need to remember (when "actually" merging the PR) is set/choose the right option to "squash all commits".
I think on GitHub we can specify the default strategy ... we might ask Eclipse to do this setting... IF EVERYONE AGREES WITH ... which isn't clear from reading #558

Shall we continue the discussion in #558

@JKRhb
Copy link
Member Author

JKRhb commented Oct 13, 2023

As said before.. rebasing, squashing, and reordering of commits while working on a PR makes it very difficult to follow what has changed between commits.

You are completely right, that should only be done once all reviews have been addressed. Sorry once more for not following that principle before.

I guess the only thing we need to remember (when "actually" merging the PR) is set/choose the right option to "squash all commits". I think on GitHub we can specify the default strategy ... we might ask Eclipse to do this setting... IF EVERYONE AGREES WITH ... which isn't clear from reading #558

Shall we continue the discussion in #558

👍

@relu91
Copy link
Member

relu91 commented Oct 13, 2023

@JKRhb you are right I simply overlooked it, let's discuss it on #558.

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

Successfully merging this pull request may close these issues.

3 participants