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

Fixes for Ruby 2.7 keyword arguments warnings #625

Merged
merged 3 commits into from
Sep 17, 2019
Merged

Fixes for Ruby 2.7 keyword arguments warnings #625

merged 3 commits into from
Sep 17, 2019

Conversation

amatsuda
Copy link
Member

This PR updates the code base to be Ruby 3.0 compatible.

After a very long discussion at https://bugs.ruby-lang.org/issues/14183, the Ruby core team finally decided to introduce a slight incompatibility to keyword arguments from Ruby 3.0, i.e. complete separation of keyword arguments literal from Hash literal.

With that, current Ruby master warns when a Hash object was passed in as keyword arguments.

$ ruby -ve 'def f(x: nil) p x; end; hash = {x: 1}; f(hash)'
ruby 2.7.0dev (2019-09-14T20:57:39Z master 1edcfd6107) [x86_64-darwin18]
-e:1: warning: The last argument is used as the keyword parameter
-e:1: warning: for `f' defined here

To eliminate this warning, we need to prefix a "double splat" (**) in order to avoid ambiguity.

$ ruby -ve 'def f(x: nil) p x;end; hash = {x: 1}; f(**hash)'
ruby 2.7.0dev (2019-09-14T20:57:39Z master 1edcfd6107) [x86_64-darwin18]
1

Also, calling super between methods with "last hash argument" and methods with kwargs would warn.

$ ruby -ve 'class A; def f(**opts) p opts; end; end; class B < A; def f(opts = {}) super; end; end; B.new.f'
ruby 2.7.0dev (2019-09-14T20:57:39Z master 1edcfd6107) [x86_64-darwin18]
-e:1: warning: The last argument is used as the keyword parameter
-e:1: warning: for `f' defined here

This PR includes fixes for these Ruby 2.7 warnings (this ensures that this code works with Ruby 3.0) without breaking compatibility with Ruby < 2.7.

@schneems
Copy link
Member

schneems commented Sep 16, 2019

Thanks a ton for the PR! Looks like there are some failures on older rubies:

  1) Failure:
273TestManifestUtils#test_warn_on_two [/home/travis/build/rails/sprockets/test/test_manifest_utils.rb:31]:
274--- expected
275+++ actual
276@@ -1 +1 @@
277-"/home/travis/build/rails/sprockets/test/fixtures/manifest_utils/with_two_manifests/.sprockets-manifest-00000000000000000000000000000000.json"
278+"/home/travis/build/rails/sprockets/test/fixtures/manifest_utils/with_two_manifests/.sprockets-manifest-f4bf345974645583d284686ddfb7625e.json"
279
280
281890 runs, 3922 assertions, 1 failures, 0 errors, 4 skips
282
283You have skipped tests. Run with --verbose for details.

@amatsuda
Copy link
Member Author

@schneems The build failures are also happening in the nightly builds
https://travis-ci.org/rails/sprockets/builds,
and #626 has to fix the build!

@schneems schneems merged commit d9e7037 into rails:master Sep 17, 2019
@schneems
Copy link
Member

thanks a ton!

@ahorek ahorek mentioned this pull request Oct 1, 2019
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Nov 4, 2019
Update ruby-sprockets to 4.0.0.

* pkgsr change: Add "USE_LANGUAGES=	# none".


## 4.0.0

- Fixes for Ruby 2.7 keyword arguments warnings [#625](rails/sprockets#625)
- Manifest files are sorted alphabetically [#626](rails/sprockets#626)

## 4.0.0.beta10

- Fix YACB (Yet Another Caching Bug) [Fix broken expansion of asset link paths](rails/sprockets#614)

## 4.0.0.beta9

- Minimum Ruby version for Sprockets 4 is now 2.5+ which matches minimum ruby verision of Rails [#604]
- Fix threading bug introduced in Sprockets 4 [#603]
- Warn when two potential manifest files exist. [#560]

## 4.0.0.beta8

- Security release for [CVE-2018-3760](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-3760)

## 4.0.0.beta7

- Fix a year long bug that caused `Sprockets::FileNotFound` errors when the asset was present [#547]
- Raise an error when two assets such as foo.js and foo.js.erb would produce the same output artifact (foo.js) [#549 #530]
- Process `*.jst.eco.erb` files with ERBProcessor

## 4.0.0.beta6

- Fix source map line offsets [#515]
- Return a `400 Bad Request` when the path encoding is invalid. [#514]

## 4.0.0.beta5

- Reduce string allocations
- Source map metadata uses compressed form specified by the [source map v3 spec](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k). [#402] **[BREAKING]**
- Generate [index maps](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt) when decoding source maps isn't necessary. [#402]
- Remove fingerprints from source map files. [#402]

## 4.0.0.beta4

- Changing the version now busts the digest of all assets [#404]
- Exporter interface added [#386]
- Using ENV vars in templates will recompile templates when the env vars change. [#365]
- Source maps for imported sass files with sassc is now fixed [#391]
- Load paths now in error messages [#322]
- Cache key added to babel processor [#387]
- `Environment#find_asset!` can now be used to raise an exception when asset could not be found [#379]

## 4.0.0.beta3

- Source Map fixes [#255] [#367]
- Performance improvements

## 4.0.0.beta2

- Fix load_paths on Sass processors [#223]


## 4.0.0.beta1

- Initial release of Sprockets 4

Please upgrade to the latest Sprockets 3 version before upgrading to Sprockets 4. Check the 3.x branch for previous changes https://github.com/rails/sprockets/blob/3.x/CHANGELOG.md.
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.

2 participants