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

[Resistor Duo analyzer (#127)] Add feedback to extract the constant to the top level if defined locally #164

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

Conversation

Steffe-Dev
Copy link

The goal of this PR is to address a subset of issue #127, namely adding the feedback to extract the constant to the top level when it was defined locally to the Resistor Color Duo analyzer.

Context

The original issue posed two problems to solve:

  1. Suppress the feedback to extract a helper method when an object was used as the constant.
  2. Introduce a new feedback item that suggests extracting the constant to top level scope if it was defined locally.

This PR addresses (2), since it is an atomic piece of new functionality. After the resolution of this PR the state of the issue should be re-evaluated, since addressing (1) would, in my opinion, require a refactor, due to the entanglement of logic between the helper method feedback and the rest of the feedback, which should be weighed against the value gained.

Main changes

  • Added a new class (ShouldDefineTopLevelConstant) to denote the new kind of feedback.
  • Added logic to instantiate this class and assign it to the lastIssue_ member of the Entry class, such that it can be consumed in the index.ts file responsible for parsing the result of the Resistor Color Duo analyzer.
  • Added a new comment factory to be used for this feedback. It closely resembles the PREFER_EXTRACTED_TOP_LEVEL_CONSTANT factory defined in the GigasecondSolution.ts file. This copy will have to be added to the website_copy repo.
  • Updated the snapshot tests to reflect the change.

Copy link

Hello. Thanks for opening a PR on Exercism 🙂

We ask that all changes to Exercism are discussed on our Community Forum before being opened on GitHub. To enforce this, we automatically close all PRs that are submitted. That doesn't mean your PR is rejected but that we want the initial discussion about it to happen on our forum where a wide range of key contributors across the Exercism ecosystem can weigh in.

You can use this link to copy this into a new topic on the forum. If we decide the PR is appropriate, we'll reopen it and continue with it, so please don't delete your local branch.

If you're interested in learning more about this auto-responder, please read this blog post.


Note: If this PR has been pre-approved, please link back to this PR on the forum thread and a maintainer or staff member will reopen it.

@SleeplessByte
Copy link
Member

@Cool-Katt wanna do a first run on a review? I am currently on annual leave so a bit slow!

@Cool-Katt
Copy link

о7 i'll got on it boss, but I think it'll be tomorrow at the earliest. Real life got in the way a little.

@@ -120,6 +121,21 @@ const ISSUE_UNEXPECTED_CALL = factory<'unexpected' | 'expected'>`
CommentType.Actionable
)

const PREFER_EXTRACTED_TOP_LEVEL_CONSTANT = factory<'value' | 'name'>`
Instead of defining the constant _inside_ the function, consider extracting it

Choose a reason for hiding this comment

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

Missing emoji?
lol, jk.

Copy link
Author

@Steffe-Dev Steffe-Dev Feb 19, 2025

Choose a reason for hiding this comment

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

Jokes aside, we do need to add this to the website-copy repo, I don't know how that process works.

Copy link
Member

Choose a reason for hiding this comment

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

Open a PR on website-copy with the copy 😁

Btw, the emojis are there to quickly be able to detect what kind of comment it is when testing the analyzer.

Copy link
Author

Choose a reason for hiding this comment

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

Cool, I will do so. 👍

I copied this one directly from the GigasecondSolution.ts file, with minor modifications. Would you prefer if I added an emoji?

Copy link
Author

Choose a reason for hiding this comment

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

Here is the PR for the website-copy change.

solution to \`resistor-color\` can be used as helper method here. When using an
\`Array\` as colors source, in a years time, will the student recall why it's
the _index_ in that array? When using an \`Object\`, what does the value mean?
Re-using \`colorCode\` explains this in both cases.

Choose a reason for hiding this comment

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

Any particular reason for the removals?

Copy link
Author

Choose a reason for hiding this comment

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

In this case the must_use_a_helper feedback would be replaced by the new prefer_extracted_top_level_constant feedback. This analyzer is built in such a way that it short-circuits on the first issue it finds, in this case, since this happens in the final stages of the process, so the variable _lastIssue gets the issue. At least, that's how I understand it.

Copy link
Author

Choose a reason for hiding this comment

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

That being said, I'm not sure if everyone kept with the practive of updating the snapshots whenever they make a PR, so this batch of updates might relate to some behaviors that weren't introduced in this PR. But, I can't be sure. I'm still very unfamiliar with this repo. 😅

Copy link
Member

Choose a reason for hiding this comment

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

But, I can't be sure. I'm still very unfamiliar with this repo

I think we always run the tests, so this must come from this PR.

At least, that's how I understand it.

It can actually have multiple comments, but we only output multiple "nice to change" or "alternative option" comments to not overwhelm the student[s].

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for clarifying. In that case I will give the updated snapshots another review, and please tell me if you see anything fishy. 😅

Copy link

@Cool-Katt Cool-Katt left a comment

Choose a reason for hiding this comment

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

Preliminary report: looks good to me.

@@ -1111,6 +1125,20 @@ class Entry {
logger.log(`~> constant is not optimal`)
return false
}

private checkForShouldDefineTopLevelConstantIssue():

Choose a reason for hiding this comment

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

I would have probably put this as a public method with the other ones at the top, for consistency.
Something like hasConstantDefinedInBody() maybe

Copy link
Author

Choose a reason for hiding this comment

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

Definitely open to this, not married to the name. I try to always make my methods private if the intention is to not have them as part of the public API, but if consistency is important here then I don't mind changing it. Let's see what @SleeplessByte thinks. 😄

Copy link
Member

Choose a reason for hiding this comment

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

potato potato 🤷🏽 😄

Copy link
Author

Choose a reason for hiding this comment

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

I do like the proposed name. I changed that. 👍

@Steffe-Dev Steffe-Dev changed the title [Resistor Duo analyzer] Add feedback to extract the constant to the top level if defined locally [Resistor Duo analyzer (#127)] Add feedback to extract the constant to the top level if defined locally Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants