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

Introduce skip_constants flag to dsl #1877

Merged
merged 1 commit into from May 2, 2024
Merged

Conversation

KaanOzkan
Copy link
Contributor

@KaanOzkan KaanOzkan commented Apr 19, 2024

Motivation

There might be need for an escape hatch that will prevent tapioca from generation DSL RBIs for specific constants.

Implementation

Remove specified constants from the list of processable constants coming from DSL compilers

Tests

Included

Copy link
Contributor

@egiurleo egiurleo left a comment

Choose a reason for hiding this comment

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

This implementation makes sense to me! In terms of naming, how do you feel about exclude_constants? I can imagine someone seeing one of the existing options named "exclude" and then searching for that, which would help them find this one.

@sambostock
Copy link
Contributor

With regards to naming, I would go so far as to say that we should deprecate exclude (and similar options) in both dsl and gem (in a separate PR) in favour of more explicit exclude_compilers and exclude_gems options, respectively. IMO it's non-obvious that exclude in dsl means to exclude compilers rather than files or constants.

@KaanOzkan
Copy link
Contributor Author

I opted to not use exclude_* because it's closely related to exclude flag. If we're having this new flag I'd also like to specify exclude option further although it'll take some time since it's a breaking change. If that's the long term plan I think exclude_constants is better.

@egiurleo
Copy link
Contributor

I like the idea of eventually deprecating exclude and only using exclude_xyz instead. Either way we'll have to do a release a deprecation and then a breaking change to there's time to fix stuff later.

@@ -149,6 +154,7 @@ def dsl(*constant_or_paths)
exclude: options[:exclude],
file_header: options[:file_header],
tapioca_path: TAPIOCA_DIR,
skip_constants: options[:skip_constant],
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't match the name of the option above, but I would suggest that we name the option as singular anyway.

@@ -135,6 +135,11 @@ def todo
type: :boolean,
desc: "Halt upon a load error while loading the Rails application",
default: true
option :skip_constants,
Copy link
Member

Choose a reason for hiding this comment

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

I suggest this becomes:

Suggested change
option :skip_constants,
option :skip_constant,

since it is primarily meant for skipping a constant but also accepts multiple constants to be specified as part of a single option.

@KaanOzkan KaanOzkan force-pushed the ko/dsl-skip-constant branch 2 times, most recently from 46891d7 to c532150 Compare April 23, 2024 18:57
@KaanOzkan KaanOzkan added the enhancement New feature or request label Apr 24, 2024
@KaanOzkan KaanOzkan marked this pull request as ready for review April 24, 2024 15:27
@KaanOzkan KaanOzkan requested a review from a team as a code owner April 24, 2024 15:27
@@ -933,6 +934,7 @@ dsl:
list_compilers: false
app_root: "."
halt_upon_load_error: true
skip_constant: []
Copy link
Contributor Author

@KaanOzkan KaanOzkan Apr 24, 2024

Choose a reason for hiding this comment

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

Decided to go with skip_constant because I believe differentiating between exclude option and this one is valuable since exclude doesn't specify what it's excluding. And to change the name of exclude option we'd have to go through a deprecation cycle and tell users to update which I believe creates unnecessary work for little benefit.

README.md Outdated
@@ -500,6 +500,7 @@ Options:
# Default: .
[--halt-upon-load-error], [--no-halt-upon-load-error], [--skip-halt-upon-load-error] # Halt upon a load error while loading the Rails application
# Default: true
[--skip-constant=constant [constant ...]] # Skip the given application constant(s) when generating RBIs
Copy link
Collaborator

Choose a reason for hiding this comment

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

While the name of the option is okay, I think we should use something else than skip in the description to better explain what it is doing:

Suggested change
[--skip-constant=constant [constant ...]] # Skip the given application constant(s) when generating RBIs
[--skip-constant=constant [constant ...]] # Do not generate RBI definition for the given application constant(s)

@@ -36,6 +37,7 @@ def initialize(
exclude:,
file_header:,
tapioca_path:,
skip_constant:,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this could be optional with a default value?

Suggested change
skip_constant:,
skip_constant: [],

@@ -149,6 +154,7 @@ def dsl(*constant_or_paths)
exclude: options[:exclude],
file_header: options[:file_header],
tapioca_path: TAPIOCA_DIR,
skip_constant: options[:skip_constant],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we check that requested_constants and skip_constant do not conflict? Or maybe add a note about which one takes precedence?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since options themselves aren't incompatible I added a detection and warning in the pipeline while looking at its contents.

@@ -124,6 +127,7 @@ def create_pipeline
error_handler: ->(error) {
say_error(error, :bold, :red)
},
skipped_constants: constantize(@skip_constant),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to also path ignore_missing to constantize?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's useful to tell the user that they are supplying an incorrect constant name so I kept this as is.

end
RB

result = @project.tapioca("dsl --skip-constant Job")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add a test with more than one value for --skip-constant so we do not accidentally break this in the future.

There might be need for an escape hatch that will prevent tapioca from
generation DSL RBIs for specific constants.
@KaanOzkan KaanOzkan merged commit 0007e48 into main May 2, 2024
34 checks passed
@KaanOzkan KaanOzkan deleted the ko/dsl-skip-constant branch May 2, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants