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

🎄 🧹 New Year cleanup #21868

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open

🎄 🧹 New Year cleanup #21868

wants to merge 6 commits into from

Conversation

vkjr
Copy link
Contributor

@vkjr vkjr commented Dec 25, 2024

Summary

We had 1000 warnings reported by clj-kondo.
Problem with having tons of warnings is that we are missing all the helpful tips, we just cant see them.

So what was done to deal with warnings:

  1. All unused code removed ruthlessly - 63 files deleted entirely. If we will need something again we can always find it in git. One piece of unused code had a comment like "do not delete, I will reuse it soon"... that comment was 2 years old :)
    Though few exceptions made, you can find them in .clj-kondo/config.edn in {:linters {:clojure-lsp/unused-public-var {:exclude ..}} section.
  2. re-frame/defn doesn't throw unused public var warning anymore, that was fixed in .clj-kondo/config.edn
  3. "deprecated" flag removed from re-frame/defn declaration. Because there are around 500 usages of it and this warning occupies all the log.
  4. react-native.core/use-effect was removed from deprecateds. Its usage generates a lot of warnings, but explanation why it shouldn't be used in guidelines is not quite clear. So if we really want to get rid of use-effect, lets make it a separate tech debt issue and discuss how it should be done.
  5. all other deprecated functions are still deprecated but I suppressed all the warnings with local comments. So if you see such comment - you can fix it ;)

Errors and warnings In develop:

Screenshot 2024-12-25 at 19 03 35

Screenshot 2024-12-25 at 19 04 02

Errors and warnings in this branch:

Review notes

Testing notes

Platforms

  • Android
  • iOS

Areas that maybe impacted

Potentially everything

Functional
  • 1-1 chats
  • public chats
  • group chats
  • wallet / transactions
  • dapps / app browsing
  • account recovery
  • new account
  • user profile updates
  • networks
  • mailservers
  • fleet
  • bootnodes

status: ready

@vkjr vkjr self-assigned this Dec 25, 2024
@status-im-auto
Copy link
Member

status-im-auto commented Dec 25, 2024

Jenkins Builds

Click to see older builds (20)
Commit #️⃣ Finished (UTC) Duration Platform Result
78645ce #1 2024-12-25 13:04:37 ~3 min tests 📄log
✔️ 78645ce #1 2024-12-25 13:08:13 ~6 min ios 📱ipa 📲
✔️ 78645ce #1 2024-12-25 13:09:17 ~7 min android-e2e 🤖apk 📲
✔️ 78645ce #1 2024-12-25 13:09:18 ~7 min android 🤖apk 📲
cc89286 #2 2024-12-25 14:39:06 ~3 min tests 📄log
✔️ cc89286 #2 2024-12-25 14:42:25 ~6 min android-e2e 🤖apk 📲
✔️ cc89286 #2 2024-12-25 14:42:33 ~6 min ios 📱ipa 📲
✔️ cc89286 #2 2024-12-25 14:43:58 ~8 min android 🤖apk 📲
✔️ 886ed91 #3 2024-12-25 14:51:30 ~3 min tests 📄log
✔️ 886ed91 #3 2024-12-25 14:54:06 ~6 min ios 📱ipa 📲
✔️ 886ed91 #3 2024-12-25 14:54:08 ~6 min android-e2e 🤖apk 📲
✔️ 886ed91 #3 2024-12-25 14:54:44 ~7 min android 🤖apk 📲
✔️ 6cececa #4 2024-12-25 18:50:35 ~4 min tests 📄log
✔️ 6cececa #4 2024-12-25 18:52:48 ~6 min ios 📱ipa 📲
✔️ 6cececa #4 2024-12-25 18:53:57 ~7 min android-e2e 🤖apk 📲
✔️ 6cececa #4 2024-12-25 18:54:42 ~8 min android 🤖apk 📲
✔️ 6fb852b #5 2024-12-25 19:04:40 ~4 min tests 📄log
✔️ 6fb852b #5 2024-12-25 19:06:39 ~6 min android-e2e 🤖apk 📲
✔️ 6fb852b #5 2024-12-25 19:06:43 ~6 min ios 📱ipa 📲
✔️ 6fb852b #5 2024-12-25 19:08:18 ~8 min android 🤖apk 📲
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 82df7f7 #6 2024-12-25 19:34:56 ~4 min tests 📄log
✔️ 82df7f7 #6 2024-12-25 19:36:58 ~6 min ios 📱ipa 📲
✔️ 82df7f7 #6 2024-12-25 19:37:14 ~6 min android 🤖apk 📲
✔️ 82df7f7 #6 2024-12-25 19:38:08 ~7 min android-e2e 🤖apk 📲
✔️ b2946d0 #7 2024-12-30 15:14:45 ~3 min tests 📄log
✔️ b2946d0 #7 2024-12-30 15:17:29 ~6 min ios 📱ipa 📲
✔️ b2946d0 #7 2024-12-30 15:18:51 ~8 min android-e2e 🤖apk 📲
✔️ b2946d0 #7 2024-12-30 15:19:10 ~8 min android 🤖apk 📲

@vkjr vkjr changed the title [WIP] 🎄 🧹 New Year cleanup 🎄 🧹 New Year cleanup Dec 25, 2024
@briansztamfater
Copy link
Member

Thanks @vkjr for addressing this cleanup!

  1. All unused code removed ruthlessly - 63 files deleted entirely. If we will need something again we can always find it in git. One piece of unused code had a comment like "do not delete, I will reuse it soon"... that comment was 2 years old :)
    Though few exceptions made, you can find them in .clj-kondo/config.edn in {:linters {:clojure-lsp/unused-public-var {:exclude ..}} section.

@status-im/mobile, is there any reason to keep the legacy.status-im. namespaces? I feel they add little value now, and if any of that code is still needed in production, it might make more sense to move it into a status-im. namespace instead of keeping it marked as legacy. We would still have the Git history in case we need to bring back an old feature or check an old implementation.

Most of the legacy code is only used or referenced in legacy namespaces, so I feel the cleanup could be more extensive this way.

If this change is too broad for this PR, we could address it in a separate one. What do you think?

  1. react-native.core/use-effect was removed from deprecateds. Its usage generates a lot of warnings, but explanation why it shouldn't be used in guidelines is not quite clear. So if we really want to get rid of use-effect, lets make it a separate tech debt issue and discuss how it should be done.

If I remember correctly, we already discussed this during the last offsite and agreed to remove the deprecation. Therefore, removing the deprecation is the right approach, but the guidelines should also be updated accordingly. I'll tag @ilmotta here so we can confirm the outcome of that discussion in Montenegro.

@vkjr
Copy link
Contributor Author

vkjr commented Dec 26, 2024

@briansztamfater, I also think that 'legacy' folder should be cleaned more or removed altogether but that would take slightly different approach. Code should be moved around.
In this PR I concentrated only on warnings and deletions of obviously unused.
So yeah, lets do this separately :)

Copy link
Member

@seanstrom seanstrom left a comment

Choose a reason for hiding this comment

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

This is an epic cleanup, well done 🙌

I left some small comments, apologies for any duplicates, it was easier to copy-and-paste some comments about naming.

Overall, I think things look good, though I wonder whether we should avoid suppressing warnings if we plan to do more PRs for resolving the warnings. For example, maybe we want to use the warnings for helping us find which code we want to revise next (?). Let me know your thoughts when you have a chance please 🙏

Comment on lines +235 to +242
st (state custom-domain? username usernames)]
(reset! resolve-last-id (random/id))
(merge
{:db (update db
:ens/registration assoc
:username username
:state state)}
(when (= state :searching)
:state st)}
(when (= st :searching)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe st could be named next-state?

Comment on lines +96 to +105
[{:keys [db] :as cofx} {h :hash :as transaction}]
(when-let [watch-params
(get-in db [:ethereum/watched-transactions hash])]
(get-in db [:ethereum/watched-transactions h])]
(let [{:keys [trigger-fn on-trigger]} watch-params]
(when (trigger-fn db transaction)
(rf/merge cofx
{:db (update db
:ethereum/watched-transactions
dissoc
hash)}
h)}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe h could be named transaction-hash or tx-hash?

Comment on lines +127 to +134
[{:keys [db] :as cofx} {h :hash :keys [id address] :as transfer}]
(let [transfer-by-hash (get-in db [:wallet-legacy :accounts address :transactions h])]
(when-let [unique-id (when-not (= transfer transfer-by-hash)
(if (and transfer-by-hash
(not (= :pending
(:type transfer-by-hash))))
id
hash))]
h))]
Copy link
Member

Choose a reason for hiding this comment

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

Maybe h could be named transaction-hash or tx-hash?

Comment on lines +158 to 166
{h :hash block :block}]
(cond
(or (nil? min-block) (> min-block (js/parseInt block)))
{:min-block (js/parseInt block)
:min-block-transfers-count 1}

(and (= min-block block)
(nil? (get-in db [:wallet-legacy :accounts checksum :transactions hash])))
(nil? (get-in db [:wallet-legacy :accounts checksum :transactions h])))
(update acc :min-block-transfers-count inc)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe h could be named transaction-hash or tx-hash?

(get-in db [:wallet-legacy :accounts (eip55/address->checksum address) :max-block]))

(defn min-block-transfers-count
(defn min-block-transfers-count-fn
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this could be named count-min-block-transfers ?

Comment on lines +207 to 210
[{:keys [db]} k value]
{:db (-> db
(assoc-in [:bug-report/details key] value)
(assoc-in [:bug-report/details k] value)
(dissoc :bug-report/description-error))})
Copy link
Member

Choose a reason for hiding this comment

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

Maybe k could be named log-key?

Comment on lines -193 to -204
(defn hash-transaction
"used for keycard"
[rpcParams callback]
(log/debug "[native-module] hash-transaction")
(.hashTransaction ^js (encryption) rpcParams callback))

(defn hash-message
"used for keycard"
[message callback]
(log/debug "[native-module] hash-message")
(.hashMessage ^js (encryption) message callback))

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if these native bindings should get some extra review since they could still be valuable references to old/upcoming features. Some of these seem they might be related to some upcoming keycard features for signing transactions and etc, but I'm not sure.

cc @flexsurfer @ilmotta

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point @seanstrom This namespace I'd consider leaving untouched with unused public vars so that it serves as a reference API. Also, if we remove from the Clojure layer, we should remove from the native layer as well in the repo. Maybe some of these functions are not even used by the desktop client, in which case we can also remove from status-go.

Comment on lines +113 to +114
;; deprecated warning suppressed but please rewrite if you have time
#_{:clj-kondo/ignore [:deprecated-var]}
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should try formatting these comments with a prefix like: TODO: deprecated ..., so that they're easier to search for throughout the code. thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have 86 TODOs in the code already) I don't think increasing this value by 100 with those deprecated suppression would make any change. Plus, we aren't really need rewriting what is deprecated. It would be nice, it would be better but it is not really a TODO.

Overall, I think things look good, though I wonder whether we should avoid suppressing warnings if we plan to do more PRs for resolving the warnings.

Overall I'd prefer maintaining a zero-warnings policy (and ensuring it with the automatic PR check). To be sure that if anything triggered a warning in the future - that was seen and fixed. And warnings that we already have... well it is possible that we will fix them but it is also possible that not. In any case old warnings shouldn't stay in our way of preventing new ones. wdyt?

@vkjr
Copy link
Contributor Author

vkjr commented Dec 27, 2024

@seanstrom, thanks for all the comments, agree with the renamings!

Copy link
Contributor

@ilmotta ilmotta left a comment

Choose a reason for hiding this comment

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

Such a nice gift for Christmas @vkjr! Thank you!

react-native.core/use-effect was removed from deprecateds.

We had an agreement between us that use-effect shouldn't be considered deprecated, so I think this is fine.

"deprecated" flag removed from re-frame/defn declaration.

Makes sense to me. We all know this is super deprecated and every now and then people rewrite usages of this macro.


The sticky point for me is that I don't currently agree with the addition of so many warning suppression comments.

When we run make lint we ignore all clj-kondo warnings via grep, thus why do we want to suppress warnings twice (code & make target)? When the dev wants to see the full list of warnings, they can run make lint CLJ_LINTER_PRINT_WARNINGS=true. The dev can also easily pipe a grep to filter/focus on certain warnings.

This is a flexible approach that doesn't require adding suppression comments.

When we add suppression comments, we are removing a nice hint in text editors for the developer to see the warning and we are also making the code noisy because the code #_{:clj-kondo/ignore [:deprecated-namespace]} is noisier than a squiggle line or hint (depending on the text editor). The suppression comment is also tied to the code structure and must be moved around correctly.

When I work with warnings, I don't care about the whole list of warnings because I want to fix one type of warning at a time, and for that reason I grep only specific warnings.

The correct IMO is to resolve warnings in bite-size PRs, not suppress them (unless it's really an exception).

@@ -548,8 +502,8 @@

(rf/defn lock-pressed
{:events [:browser.ui/lock-pressed]}
[cofx secure?]
(update-browser-option cofx :show-tooltip (if secure? :secure :not-secure)))
[cofx is-secure?]
Copy link
Contributor

@ilmotta ilmotta Dec 27, 2024

Choose a reason for hiding this comment

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

Why this change from secure? to is-secure? ? secure? follows the Clojure style guide our style guide.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

probably was shadowing something, will check!

@@ -1,8 +1,7 @@
(ns legacy.status-im.utils.utils-test
(:require
[cljs.test :refer-macros [deftest is]]
[legacy.status-im.utils.core :as u]
[legacy.status-im.utils.utils :as uu]))
[legacy.status-im.utils.core :as u]))
Copy link
Contributor

Choose a reason for hiding this comment

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

We sort of have a convention to use sut as the alias for the namespace under test. Could you alias to sut instead of u?

Comment on lines -193 to -204
(defn hash-transaction
"used for keycard"
[rpcParams callback]
(log/debug "[native-module] hash-transaction")
(.hashTransaction ^js (encryption) rpcParams callback))

(defn hash-message
"used for keycard"
[message callback]
(log/debug "[native-module] hash-message")
(.hashMessage ^js (encryption) message callback))

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point @seanstrom This namespace I'd consider leaving untouched with unused public vars so that it serves as a reference API. Also, if we remove from the Clojure layer, we should remove from the native layer as well in the repo. Maybe some of these functions are not even used by the desktop client, in which case we can also remove from status-go.

:test/assoc-in
(fn [app-db [_ path value]]
(assoc-in app-db path value))))

(defn spy-event-fx
Copy link
Contributor

Choose a reason for hiding this comment

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

When I wrote abstractions like spy-event-fx I was trying to come up with an intermediary solution between our current integration tests and unit testing event handlers like we do now. I didn't like the experience and the brittleness of this spying/stubbing solution for events, so I stopped using this.

If you can remove in this PR, please remove spy-event-fx, spy-fx, stub-fx-with-callbacks. I think db function can also be removed if there are no usages.

@@ -39,15 +39,23 @@
(defn percentage-change
[customization-color theme]
{:color (colors/theme-colors
;; deprecated warning suppressed but please rewrite if you have time
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels excessive to have two comments the same thing. The clj-kondo clearly means it's suppressing a warning. If you agree, could you remove all such ;; deprecated warning ... comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I won't insist too much on having also textual comment but think that it makes better call to action in comparison to just having a suppressed warning. So better chance to have warnings fixed :)

;; be removed:
keycard.keycard
test-helpers.unit
test-helpers.component
Copy link
Contributor

Choose a reason for hiding this comment

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

The unused vars in test-helpers.component: after-each, test-only, describe-only, and describe-skip can also be used only temporarily during development, thus not necessarily to commit. For this namespace in particular I think we can just ignore the unused public vars, but shouldn't consider deleting.

@vkjr
Copy link
Contributor Author

vkjr commented Dec 28, 2024

@ilmotta

When we run make lint we ignore all clj-kondo warnings via grep, thus why do we want to suppress warnings twice (code & make target)?

Yes, currently we ignore warnings in linting. And we allow the new code to be committed with warnings. But I suggest to only commit code without warnings :)

To start forcing "no-warnings" policy we need to get rid of ALL existing warnings. Lets be honest, we won't make anytime soon an effort to really remove them. But that shouldn't stop us from implementing no-warnings policy. We can suppress an existing ones and never add new. And slowly fix already existing but suppressed.

When we add suppression comments, we are removing a nice hint in text editors for the developer to see the warning and we are also making the code noisy

Yes, editor hint is nice, but as we can see from the experience, having a thousand hints in editor just makes us blind to the warnings :) On the other side when there were no warnings in develop and now there are one or two in your local branch, you know that you are responsible and need to fix them.

And I don't really think that ugliness of suppression comment is a bad thing. Maybe it is something that would push us to fix those parts instead of ignoring them.

So in the end of the day my suggestion is to have all existing warnings suppressed and start having no-warnings policy. What do you think?

I'd be happy to hear more opinions on this point from the team.
cc @flexsurfer, @ulisesmac, @briansztamfater, @clauxx, @shivekkhurana, @seanstrom

@vkjr
Copy link
Contributor Author

vkjr commented Dec 28, 2024

@ilmotta, thanks for checking the pr! 🙏

@seanstrom
Copy link
Member

seanstrom commented Dec 29, 2024

@vkjr I like the idea of avoiding deprecation warnings and limiting what kind of code we check-in to the codebase 👍

Though I think we should try to resolve the current warnings as soon as possible to get the best benefits. So with that in mind I've tried to help with cleaning up some of the new deprecation warning suppressions (the one's introduced in this PR) by creating another PR based on these changes that try to resolve a good chunk of the warnings there: #21874

Hopefully this will help with merging this PR and enabling the zero-warnings policy 🙌

Lmk your thoughts when you have a chance 🙏

@vkjr
Copy link
Contributor Author

vkjr commented Dec 30, 2024

@seanstrom, wow, thanks a lot!

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

Successfully merging this pull request may close these issues.

5 participants