robotframework-robocop icon indicating copy to clipboard operation
robotframework-robocop copied to clipboard

Rule: check if dependencies are sorted

Open mnojek opened this issue 4 years ago • 6 comments

Check if dependencies in Settings section are sorted: Libraries first, then Resource files. Can also check if they are sorted alphabetically or whatever way we decide to implement it.

mnojek avatar Aug 25 '20 19:08 mnojek

It could be also possible to test if the import is local or external and propose sorting based on that (similiar as python):

Library  Collections  # internal
Library  common.py  # in the same directory
Library  MyTestLib  # external library

bhirsz avatar Aug 25 '20 21:08 bhirsz

It could be also possible to test if the import is local or external and propose sorting based on that (similiar as python):

Library  Collections  # internal
Library  common.py  # in the same directory
Library  MyTestLib  # external library

We already have this inside 'wrong-import-order' rule but without checking libraries from the same directory.

mnojek avatar Aug 24 '21 18:08 mnojek

Also, I am thinking if this is a good idea to implement this rule. I remember a discussion on slack (probably on #lsp or #devel channel) about the order of the imports and how they relate to each other. The conclusion was that sometimes different order is required due to specific variables relying on each other. So forcing user to keep one and only order is probably not a good idea... @bhirsz What do you think?

mnojek avatar Aug 24 '21 19:08 mnojek

Yeah, resources and libraries are often depending in the order of import which would be contradicting with this rule. And like you wrote there is w ring-import-order already. We can close it

bhirsz avatar Aug 24 '21 20:08 bhirsz

Another thing that comes to my mind is to create a rule for keeping settings of the same type grouped together, but again... I am not 100% sure if it will not trigger some problems with import order. @bhirsz What do you think? Can we implement such rule or we should give up with all sort of these rules related to order of imports?

mnojek avatar Aug 24 '21 20:08 mnojek

If we don't have anything for it yet (I don't think so) it could be good idea. Robotidy already group settings, for example result here. Setting order other than imports (variables, resources, libraries) doesn't matter in execution. It looks better if let's say we're keeping tag settings together with other tag settings so I'm vouting for such rule.

bhirsz avatar Aug 25 '21 06:08 bhirsz