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

Frozen string literal #1790

Closed
wants to merge 27 commits into from
Closed

Frozen string literal #1790

wants to merge 27 commits into from

Conversation

ericproulx
Copy link
Contributor

Hi,

Since ruby 2.3, we can add the comment # frozen_string_literal: true at the start of the files to make all strings literals frozen by default. Since I'm using your gem on ruby 2.3, I thought it would be a great idea.

@dblock
Copy link
Member

dblock commented Sep 15, 2018

We use RuboCop that adds .freeze in all the right places AFAIK which makes it better for all non 2.3 versions. Seems like that's better than doing it automatically for only 2.3 no? Potentially we could end up having different behavior for as long as we support all of 2.x.

I could misunderstand what this does, but otherwise I propose we don't merge this.

If we were to merge this, I'd want to see rubocop rules changed to enforce this header everywhere and remove the freeze calls.

@ericproulx
Copy link
Contributor Author

The .freeze makes total sense for everyone under Ruby 2.3. In my opinion, since Ruby 2.2 support has ended in June, I think ruby-grape should move forward and look at the future. Strings will be immutable by default in Ruby 3.0.

I'm totally fine with removing all .freeze and change Rubocop target ruby version to 2.3. At the end, it's your call 👍

@dblock
Copy link
Member

dblock commented Sep 15, 2018

I think if we move forward with 2.3 minimum then yes, but even though support has ended in June I think we're ok being a bit behind. In my own org we're running a ton of Ruby 2.2 right now.

@ericproulx I think you should turn this PR into exactly what you propose and lets see what other maintainers say? @namusyaka for example?

@namusyaka
Copy link
Contributor

Thanks for your contribution.
As the rails community have switched, I think it may be worth trying.

But I don't think this changes improve performance largely, and not only that, this has possibility of leading new painful for us.

I don't say that your change isn't reasonable however we should consider the switching timing and the sustainability of the grape for users.
At least, if we merge this change, we should forward to the new minor or major versions.

Copy link
Contributor

@namusyaka namusyaka left a comment

Choose a reason for hiding this comment

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

If you would like to go on the issue, you should take a look at Rubocop configuration.
https://github.com/rubocop-hq/rubocop/blob/master/manual/cops_style.md#stylefrozenstringliteralcomment

@@ -35,16 +35,17 @@ def pattern_options
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't you add the comment in this file?

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 guess I forgot :(

# Conflicts:
#	CHANGELOG.md
#	lib/grape/util/inheritable_values.rb
#	lib/grape/util/reverse_stackable_values.rb
#	lib/grape/util/stackable_values.rb
#	lib/grape/validations/validators/all_or_none.rb
#	lib/grape/validations/validators/at_least_one_of.rb
#	lib/grape/validations/validators/exactly_one_of.rb
#	lib/grape/validations/validators/mutual_exclusion.rb
@dblock
Copy link
Member

dblock commented Oct 26, 2019

Is running rubocop -a ; rubocop --auto-gen-config a noop after this?


pattern + suffix.to_s
new_pattern + suffix.to_s
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we do patter = pattern + or something like that within the condition, instead of duplicating it every time?

@dblock
Copy link
Member

dblock commented Oct 28, 2019

Let us know when this is ready to merge. Don't forget CHANGELOG. Maybe squash?

@dnesteryuk
Copy link
Member

@ericproulx
Copy link
Contributor Author

I'm closing this PR, I opened another one #1941

@ericproulx ericproulx closed this Dec 9, 2019
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.

4 participants