Skip to content

Enable identical and similar code statements in CodeClimate configuration#10383

Merged
andreslucena merged 12 commits intodevelopfrom
chore/patch-codeclimate
Sep 12, 2023
Merged

Enable identical and similar code statements in CodeClimate configuration#10383
andreslucena merged 12 commits intodevelopfrom
chore/patch-codeclimate

Conversation

@alecslupu
Copy link
Copy Markdown
Contributor

🎩 What? Why?

In order to increase the maintainability, we have to identify duplicated code, so that we may address the issue at some point.

♥️ Thank you!

@alecslupu alecslupu added the type: internal PRs that aren't necessary to add to the CHANGELOG for implementers label Feb 14, 2023
@ahukkanen
Copy link
Copy Markdown
Contributor

Overall I like this idea but I think we need to add some exclude rules for example to exclude decidim_app-design from these rules because it is complaining we have the same JS code in two places and this is on purpose right now because of some limitations in NPM that we cannot refer to local NPM packages at higher levels in the directory structure (see #8159).

Also some other issues it is identifying do not seem to make sense, as refactoring duplicated route definitions. To me the current way of defining the routes makes more sense.

The other issues could be debated, such as repeating similarly named attributes in two different forms. Sometimes it makes more sense to repeat, sometimes it might make more sense to refactor to a common module.

As said, overall I like this kind of changes but I'm just not sure if any of the issues created through this change by Code Climate make sense in the real world.

@alecslupu
Copy link
Copy Markdown
Contributor Author

The main ideea, is not to generate more work, but to use the tool so we could identify duplicate code ...
Like the one in

decidim/decidim-participatory_processes/app/models/decidim/participatory_process_user_role.rb
decidim/decidim-assemblies/app/models/decidim/assembly_user_role.rb
decidim/decidim-conferences/app/models/decidim/conference_user_role.rb

There are a few lines of code, that could be extracted in a concern (that may either reside in decidim-core, or along with other space related elements could be the base of an abstract module like decidim-generic-spaces), or we could use STI model.

@alecslupu
Copy link
Copy Markdown
Contributor Author

Overall I like this idea but I think we need to add some exclude rules for example to exclude decidim_app-design from these rules because it is complaining we have the same JS code in two places and this is on purpose right now because of some limitations in NPM that we cannot refer to local NPM packages at higher levels in the directory structure (see #8159).

Also some other issues it is identifying do not seem to make sense, as refactoring duplicated route definitions. To me the current way of defining the routes makes more sense.

The other issues could be debated, such as repeating similarly named attributes in two different forms. Sometimes it makes more sense to repeat, sometimes it might make more sense to refactor to a common module.

As said, overall I like this kind of changes but I'm just not sure if any of the issues created through this change by Code Climate make sense in the real world.

Regarding the exceptions that we want to create, we could ignore it from code-climate ... yes, is going a bit of work until we get it to green, but would be better on the long run.

@alecslupu alecslupu changed the title Enable Identical and symilar code statements Enable Identical and similar code statements Feb 15, 2023
@andreslucena
Copy link
Copy Markdown
Member

To move this forward, this is my take in all the issues to fix detected by codeclimate:

scope_types_controller.rb and area_types_controller.rb

Areas is not actively maintained. On @decidim/product we've discussed that we wanted to deprecated and integrate it better in Scopes. See https://docs.decidim.org/en/develop/admin/areas.html

We can ignore this for the moment (adding an exclusion)

meeting_m_cell.rb and meeting_s_cell.rb

I'm not sure if they're still relevant with the Redesign.

On the other hand I see that MeetingSCell is inheriting from MeetingMCell so we could remove it from there?

voting_stats_presenter.rb and assembly_stats_presenter.rb

Seems like it's also missing participatory_process_stats_presenter.rb

We could do a ParticipatorySpaceStatsPresenter or something like that, but I'm not so sure if this will be still relevant with the Redesign as the plan is to migrate these to ContentBlocks.

filters_participatory_space_user_roles_examples.rb and filters_participatory_space_users_examples.rb

I think that by changing wording/naming a bit we could remove one of those

amendment_accepted_event_examples.rb and amendment_rejected_event_examples.rb

We could probably refactor and DRY this up.

add_questions.rb

We could probably refactor and DRY this up.

invites.rb and conference_invites.rb

We could probably refactor and DRY this up.

admin_engine.rb and admin_engine.rb

Aka the routes in spaces. This will probably happen to with Votings and Conferences. I agree that ignoring it for now will be cleaner as it's on the Rails routes DSL and I'm not so sure how to tackle it.

assembly_publications_controller.rb and conference_publications_controller.rb

It probably also happens on other Spaces. We could do a SpacePublicationsController class or a SpacePublicable concern.

polling_officer_form.rb and monitoring_committee_member_form.rb

We could probably refactor and DRY this up.


All in all, I think that as fixing all of these issues could be too much effort, for now I'd add them as exclusions, so we can merge this new change in the configuration and keep it from introducing new ones. I think that our current priority should be on lowering the number of open PRs.

With the rest we should probably discuss a bit more if they're worth the effort, or we can live with a bit of duplication for now. Also to take into account is that sometimes CodeClimate find only two locations but for sure it could be more, specially the ones that's detecting about Spaces (ie it only detects similarity between decidim-assemblies and decidim-conferencesbut probably it also applies todecidim-participatory_processes`.

@andreslucena andreslucena changed the title Enable Identical and similar code statements Enable identical and similar code statements inCodeClimate configuration May 5, 2023
@andreslucena andreslucena changed the title Enable identical and similar code statements inCodeClimate configuration Enable identical and similar code statements in CodeClimate configuration May 5, 2023
@andreslucena
Copy link
Copy Markdown
Member

@alecslupu have you seen my last comment?

@alecslupu
Copy link
Copy Markdown
Contributor Author

alecslupu commented May 25, 2023 via email

Copy link
Copy Markdown
Member

@andreslucena andreslucena left a comment

Choose a reason for hiding this comment

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

I'd add some exclusions here as these are things that we can live with some identical/similarity.

Regarding the one that's missing (filterable), I'm working on it

alecslupu and others added 3 commits September 7, 2023 09:53
@andreslucena
Copy link
Copy Markdown
Member

I've merged with develop to see that the last CodeClimate offense is fixed and then if everything is OK I'll merge this PR. 🤞🏽

Copy link
Copy Markdown
Member

@andreslucena andreslucena left a comment

Choose a reason for hiding this comment

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

🥳

@andreslucena andreslucena merged commit a44de3d into develop Sep 12, 2023
@andreslucena andreslucena deleted the chore/patch-codeclimate branch September 12, 2023 10:10
entantoencuanto added a commit that referenced this pull request Sep 12, 2023
* develop:
  Enable identical and similar code statements in CodeClimate configuration (#10383)
  Fix flaky spec for mobile version of the search form (#11558)
  Remove duplication for ParticipatorySpace User examples (#11578)
  Add title in arrows while navigating meetings (#11574)
@alecslupu alecslupu added this to the 0.28.0 milestone Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: internal PRs that aren't necessary to add to the CHANGELOG for implementers

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants