Identify unused methods

Is there a way to find unused methods in my meteor code ?
At the moment we are searching (Ctrl+F in visual code) for each method in the code but I am wondering if there is a plugin for this ?

Yeah, that’s called “tree shaking” and I think that it’s on the list for future Meteor features.

Are we talking about Meteor methods specifically or just methods (= functions) in general?

For general functions, tree shaking will be a future solution. Until then you can use a static code analysis tool like eslint and with the right configuration you should be able to identify some unused functions:

1 Like

Yes I was talking about meteor methods. I will have a look at the no-unused-vars but I don’t think that this work for meteor methods definition like this

    'my-unused-method': function() {}


Counterquestion: do you know which methods you use? Because all methods will be registered with their names in Meteor.server.method_handlers. Maybe this helps you to identify unused by filtering out all the ones in use? Note that accounts etc. also register methods there.

1 Like

Hello, thanks for this proposition. But I do not know which methods I use. We have a lot of deprecated methods that I would like to clean up but I think I will have to go through all my files and search for usage of each methods.

Maybe simply add a logging method to each of them. The methods which don’t hit the log are thus superfluous. Could probably be automated.

Create your own which calls the original function and then add logging for the name parameter