OsmosysSoftware / dev-standards

Documentation for all the development category standards followed at Osmosys
2 stars 11 forks source link

Disable class-methods-use-this for Angular #61

Closed IAM5K closed 1 month ago

IAM5K commented 3 months ago

Resource link

https://github.com/OsmosysSoftware/dev-standards/blob/main/coding-standards/angular.md

Description

image In angular we can use such function because the function has to be referred by HTML files. Having the function that returns value in other file and then use is wont work because function expects a value from its own ts file.

Proposed solution

Remove this rule and suggest team leads to apply the latest rules. Also there are many rules that are mainly for React, vannila js or vue, Angular is a framework and different from these. Please keep this as note while creating rules.

osm-vishnukyatannawar commented 2 months ago

We will soon address this. Someone from our team will look into this. While I think having class-methods-use-this check make sense. I want to know more about your use case on why it should be removed.

In angular we can use such function because the function has to be referred by HTML files. Having the function that returns value in other file and then use is wont work because function expects a value from its own ts file.

@vikas-kyatannawar can you look into this?

IAM5K commented 2 months ago

@osm-vishnukyatannawar @xixas As mentioned earlier, In any component where we need a function that is associated with UI in this case isChecklistComplete() we call this function to disable a button and we need this in component.ts because we have some logic that is/maybe related with other functions and variables declared. Another such example can be calling an onDDropdownValueChange() this function can be seen in all components where we update the data in 1st drop-down/input and based on it options/behaviour of the 2nd drop-down/input is updated.

The current rule expects to invoke this function at least once using this else disable this rule. It is also seen in code that in an ExampleComponent internal functions are called as ExampleComponent.functionName() which is an incorrect way. but our rule allows it.

xixas commented 2 months ago

@osm-vishnukyatannawar we can disable this rule for Angular. Though developers should take care to not add any methods which should be in utility. Most examples can be modified to enforce this rule(and disable for the particular if its really not making sense). Methods that are called from component templates typically should not be static, even if they don't use this.

xixas commented 2 months ago

@IAM5K You can create a PR for the change

xixas commented 2 months ago

@osm-vishnukyatannawar Enforcing it strictly as error for Angular is not needed. If we want to keep it it would be only to avoid developers from writing bad code i.e. adding methods which should not be present(or moved out from) in the component file.

osm-vishnukyatannawar commented 1 month ago

This issue is addressed and be closed.