Commit graph

14675 commits

Author SHA1 Message Date
Earlopain
67e6ccb23f [ruby/prism] Optimize array inclusion checks in the parser translator
I see `Array.include?` as 2.4% runtime. Probably because of `LPAREN_CONVERSION_TOKEN_TYPES` but
the others will be faster as well.

Also remove some inline array checks. They are specifically optimized in Ruby since 3.4, but for now prism is for >= 2.7

ca9500a3fc
2025-03-13 13:52:45 +00:00
Earlopain
4b844f7d9e [ruby/prism] Ensure backwards compatibility with the custom parser builder
Temoprary backwards-compat code so that current users
don't break.

Eventually the Translation::Parser initializer should asser that the correct class is passed in.

66b0162b35
2025-03-13 12:06:58 +00:00
Hartley McGuire
8cc85dc00f [rubygems/rubygems] Remove array allocation from Candidate#<=>
In a large application I profiled allocations while running `bundle
update` and found that this method was ~60% of allocations while
resolving (and Candidate#<=> is almost half of the total runtime).

This commit removes the array allocation in Candidate#<=> (and similar
methods since the implementations are so simple). The array is always
the same two elements so they can just be compared directly.

6a7c411ba7
2025-03-13 10:24:21 +09:00
Kevin Newton
af76b7f4d9 [ruby/prism] Revert "Mark extension as Ractor-safe"
56eaf53732
2025-03-12 19:56:22 +00:00
Kevin Newton
242e99eb0f [ruby/prism] Mark extension as Ractor-safe
10e5431b38
2025-03-12 19:15:03 +00:00
Jacob Atzen
63dbb2f8a2 [rubygems/rubygems] Update docs for with/without consistency
The with and without flags accepts both comma and space separated values.

b6149f61e3
2025-03-12 18:02:09 +09:00
David Rodríguez
510edbccf9 [rubygems/rubygems] Fix ENAMETOOLONG error when creating compact index cache
If a custom rubygems source URI is long enough, Bundler may end up
raising an `ENAMETOOLONG` error and crash.

This commit fixes the problem by trimming the cache slug size to fit
usual OS requirements.

df40ff1e14

Co-authored-by: mbclu <mbclu@users.noreply.github.com>
Co-authored-by: martinemde <martinemde@users.noreply.github.com>
2025-03-12 18:02:09 +09:00
Koichi ITO
6b4453e332 [ruby/prism] Support itblock for Prism::Translation::Parser
## Summary

`itblock` node is added to support the `it` block parameter syntax introduced in Ruby 3.4.

```console
$ ruby -Ilib -rprism -rprism/translation/parser34 -e 'buffer = Parser::Source::Buffer.new("path"); buffer.source = "proc { it }"; \
                                                      p Prism::Translation::Parser34.new.tokenize(buffer)[0]'
s(:itblock,
  s(:send, nil, :proc), :it,
  s(:lvar, :it))
```

This node design is similar to the `numblock` node, which was introduced for the numbered parameter syntax in Ruby 2.7.

```
$ ruby -Ilib -rprism -rprism/translation/parser34 -e 'buffer = Parser::Source::Buffer.new("path"); buffer.source = "proc { _1 }"; \
                                                      p Prism::Translation::Parser34.new.tokenize(buffer)[0]'
s(:numblock,
  s(:send, nil, :proc), 1,
  s(:lvar, :_1))
```

The difference is that while numbered parameters can have multiple parameters, the `it` block parameter syntax allows only a single parameter.

In Ruby 3.3, the conventional node prior to the `it` block parameter syntax is returned.

```console
$ ruby -Ilib -rprism -rprism/translation/parser33 -e 'buffer = Parser::Source::Buffer.new("path"); buffer.source = "proc { it }"; \
                                                      p Prism::Translation::Parser33.new.tokenize(buffer)[0]'
s(:block,
  s(:send, nil, :proc),
  s(:args),
  s(:send, nil, :it))
```

## Development Note

The Parser gem does not yet support the `it` block parameter syntax. This is the first case where Prism's node design precedes that of the Parser gem.
When implementing https://github.com/whitequark/parser/issues/962, this node design will need to be taken into consideration.

c141e1420a
2025-03-10 16:57:46 +00:00
Nobuyoshi Nakada
97c133a859 [ruby/optparse] bump up to 0.7.0.dev.1 [ci skip]
f4d64b0b17
2025-03-10 11:06:55 +00:00
Nobuyoshi Nakada
13fa6cc6a3 [ruby/optparse] [DOC] Extract description from README
83e8c23d68
2025-03-10 11:01:03 +00:00
Kouhei Yanagita
3cd3f76679 [ruby/optparse] Fix LESS environment variable setup in OptionParser#help_exit
If the original value of LESS ends with an option starting with "--",
simply appending "Fe" would result in an invalid option string.

30571f91d3
2025-03-10 10:21:29 +00:00
Koichi ITO
f4c16c57aa [ruby/optparse] Make the result of tty? obtainable with flexible stdout
In mock testing for stdout, `StringIO.new` is sometimes used to redirect the output.
In such cases, the assignment is done with `$stdout = StringIO.new`, not the constant `STDOUT`.
e.g., https://github.com/rubocop/rubocop/blob/v1.71.1/lib/rubocop/rspec/shared_contexts.rb#L154-L164

After assigning `StringIO.new`, `$stdout.tty?` returns `false`,
allowing the standard output destination to be switched during test execution.

```ruby
STDOUT.tty?       # => true
StringIO.new.tty? # => false
```

However, since `STDOUT.tty?` returns `true`, a failure occurred in environments
where the environment variables `RUBY_PAGER` or `PAGER` are set.
e.g., https://github.com/rubocop/rubocop/pull/13784

To address this, `STDOUT` has been updated to `$stdout` so that the result of `tty?` can be flexibly overridden.

A potential concern is that `$stdout`, unlike `STDOUT`,
does not always represent the standard output at the time the Ruby process started.
However, no concrete examples of issues related to this have been identified.

`STDOUT.tty?` is the logic of optparse introduced in https://github.com/ruby/optparse/pull/70.

This PR replaces `STDOUT` with `$stdout` throughout, based on the assumption
that `$stdout` is sufficient for use with optparse.

262cf6f9ac
2025-03-10 10:19:58 +00:00
Nobuyoshi Nakada
9e265b583b [ruby/optparse] Add post-check of value
Fix https://github.com/ruby/optparse/pull/80

050a87d029
2025-03-10 09:55:29 +00:00
Nobuyoshi Nakada
b51450f3bd [ruby/optparse] Update argument check with save navigation operator
71e2b31824
2025-03-10 08:03:55 +00:00
Nobuyoshi Nakada
dad0f876a9 [ruby/optparse] Remove extra blank lines [ci skip]
d7dec6808f
2025-03-10 08:03:54 +00:00
Nobuyoshi Nakada
9de9cb53c0 [ruby/optparse] [DOC] Update documents to use single quotes instead of backqoutes
5e71a70cb5
2025-03-10 07:56:44 +00:00
David Rodríguez
e21e5bc814 [rubygems/rubygems] Fix gem rdoc not working with newer versions of rdoc
369f9b9311
2025-03-10 12:43:36 +09:00
Tara Bass
4323674fe4 [rubygems/rubygems] Don't treat a git-sourced gem install as complete if only the '.git' directory is present. This recovers cases where a git-sourced install can be left in a partially installed state.
d132b7008d
2025-03-10 12:43:36 +09:00
Sean Collins
71e340881f [rubygems/rubygems] Switch inject to use shorthand hash syntax
ba5a62fd04
2025-03-10 12:43:36 +09:00
Sean Collins
8acf0d7bcc [rubygems/rubygems] Use shorthand hash syntax for bundle add
9691097036
2025-03-10 12:43:36 +09:00
Nobuyoshi Nakada
cdf36d6bfd [ruby/optparse] Allow non-string enum list #79
Command line arguments are strings, convert enum list elements to
strings to match.

c5ec052efc
2025-03-09 14:32:17 +00:00
Nobuyoshi Nakada
0c73328aff [ruby/optparse] Use \A instead of ^ as the beginning of string
a3f1029815
2025-03-09 14:09:16 +00:00
Nobuyoshi Nakada
49199445f5 [ruby/optparse] [DOC] Manage rdoc options only in .rdoc_options file
Make `rdoc .` and `rake rdoc` consistent.

61b4ea0704
2025-03-09 14:03:55 +00:00
Michael Chui
fdf1076ef9 [rubygems/rubygems] docs(bundle-exec): recommend non-deprecated methods
3b4934fb69
2025-03-03 15:52:35 +09:00
Mateo
a98c3d229e [rubygems/rubygems] docs(bundle-config): hint default group when using only option
c258e45b44
2025-03-03 15:52:35 +09:00
Josef Šimánek
29e3ee0568 [rubygems/rubygems] Bring man pages up to date
591d2c0503
2025-03-03 15:52:35 +09:00
Hiroshi SHIBATA
e4c5531b4c [rubygems/rubygems] Update vendored uri to 1.0.3
176dc7421c
2025-03-03 15:52:35 +09:00
Martin Emde
19bdcc8f0c
[rubygems/rubygems] Retry gracefully on blank partial response in compact index
fafb9ae090
2025-02-28 12:34:57 +09:00
Hiroshi SHIBATA
9cf5d20e5f
[ruby/cgi] Bump up v0.4.2
ab84b7fe66
2025-02-27 13:32:32 +09:00
Hiroshi SHIBATA
cdc55c2452
[ruby/cgi] Bump up 0.4.2.beta2
8e6fb1041b
2025-02-27 13:32:32 +09:00
Martin Emde
61060d349d
[rubygems/rubygems] Remove MD5 digesting of compact index responses
It has been over a year since the release, so let's stop MD5ing everything

29ef4ca30b
2025-02-27 13:32:32 +09:00
David Rodríguez
3e78a2f58e
[rubygems/rubygems] Improve error message when on read-only filesystems
If we fail to write the lockfile, give a better error.

81a08d6eda
2025-02-27 13:32:32 +09:00
yuuji.yaginuma
75f07afd18 [ruby/uri] Use a fully qualified name in warning messages
Currently, some warning messages don't contain a `URI` like the following.

```ruby
warning: URI::ABS_URI is obsolete. Use RFC2396_PARSER.regexp[:ABS_URI] explicitly.
```

But, without `URI` prefix, the suggested value doesn't work.
So I think we should use a fully qualified name to avoid confusion.

428eb10e44
2025-02-27 04:32:27 +00:00
Yuji Yaginuma
31bd669f67 [ruby/uri] Fix the mention to removed URI.escape/URI::Escape
This was removed by #9.

fec924238f
2025-02-27 04:30:23 +00:00
Hiroshi SHIBATA
237ab21f25 [ruby/cgi] Escape/unescape unclosed tags as well
cd1eb08076

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2025-02-26 07:34:04 +00:00
Hiroshi SHIBATA
fc60a04de9 [ruby/cgi] Use String#concat instead of String#+ for reducing cpu usage
9907b76dad

Co-authored-by: "Yusuke Endoh" <mame@ruby-lang.org>
2025-02-26 07:34:03 +00:00
Hiroshi SHIBATA
eac8b1197f [ruby/uri] Bump up v1.0.3
3213f4a0f8
2025-02-26 07:12:53 +00:00
Hiroshi SHIBATA
b407b6b5b2 [ruby/uri] Fix merger of URI with authority component
https://hackerone.com/reports/2957667

2789182478

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2025-02-26 07:08:45 +00:00
Hiroshi SHIBATA
57dcb4bb9b [ruby/uri] Truncate userinfo with URI#join, URI#merge and URI#+
3675494839
2025-02-26 07:08:44 +00:00
Hiroshi SHIBATA
ae0853b5f5 [ruby/cgi] Bump up 0.4.2.beta1
3f5b4ed9e9
2025-02-26 06:20:36 +00:00
Koichi ITO
6efd15a128 [ruby/prism] Restore a comment for Prism::Translation::Parser#initialize
This restores the missing method comments in https://github.com/ruby/prism/pull/3479.

78b8f67dee
2025-02-25 22:18:02 +00:00
Earlopain
044570fd76 [ruby/prism] Fix merge mishap
Caused by https://github.com/ruby/prism/pull/3478 and https://github.com/ruby/prism/pull/3443

I also made the builder reference more explicit to clearly distinquish
between `::Parser` and `Prism::Translation::Parser`

d52aaa75b6
2025-02-25 17:11:39 +00:00
Earlopain
790b3858e8 [ruby/prism] Add a custom builder class for the parser translator
I want to add new node types to the parser translator, for example `itblock`. The bulk of the work is already done by prism itself. In the `parser`
builder, this would be a 5-line change at most but we don't control that here.

Instead, we can add our own builder and either overwrite the few methods we need,
or just inline the complete builder. I'm not sure yet which would be better.

`rubocop-ast` uses its own builder for `parser`. For this to correctly work, it must explicitly choose to extend the
prism builder and use it, same as it currently chooses to use a different parser when prism is used.

I'd like to enforce that the builder for prism extends its custom one since it will lead to
some pretty weird issues otherwise. But first, I'd like to change `rubocop-ast` to make use of this.

b080e608a8
2025-02-25 15:44:56 +00:00
Koichi ITO
2c3d2415d1 [ruby/prism] Support custom parser in Prism::Translation::Parser
Follow-up to https://github.com/Shopify/ruby-lsp/pull/1849.

This is an extension of `Prism::Translation::Parser` to implement https://github.com/Shopify/ruby-lsp/pull/1849.
It is based on the comments in https://github.com/Shopify/ruby-lsp/pull/1849#pullrequestreview-1966020868,
but also adds a default argument for delegation to `Parser::Base` super class.

Using this API, https://github.com/rubocop/rubocop-ast/pull/359 has been implemented in RuboCop AST.
As detailed in https://github.com/rubocop/rubocop-ast/pull/359, this change is expected to improve performance by 1.3x
for some source code.
Achieving a 1.3x speedup with such this simple modification is a significant improvement for Ruby LSP and its users.

925725291c
2025-02-25 15:41:29 +00:00
David Rodríguez
158e4cc4ec [rubygems/rubygems] Improve log message about adding a new platform
This message is printed when running `bundle lock --add-platform`. This
command affects the lockfile, not the gemfile, and I think it's better
to use "You are adding" rather than "You added", because the addition is
happening during the current invocation (as opposed to other log
messages that talk about a change made to the Gemfile prior to running
the command).

aba1e55f5b
2025-02-25 15:36:46 +09:00
David Rodríguez
5284719273 [rubygems/rubygems] Refactor handling platform removals
And make it consistent with platform additions.

64342ae404
2025-02-25 15:36:46 +09:00
David Rodríguez
8b952e6489 [rubygems/rubygems] Improve log message when resolving due to local platform not in lockfile
Current it says "you added a new platform to your gemfile", but that's
not actually the case here.

1e39527a38
2025-02-25 15:36:46 +09:00
Edouard CHIN
71f0c37473 [rubygems/rubygems] Modify bundle doctor to not report issue when files aren't writable:
- ### Problem

  Running `bundle doctor` warn about files that aren't writable.
  This makes the output of `bundle doctor` very verbose for something
  I believe isn't really an issue.

  ### Context

  Rubygems keeps the files original permission at the time the gem
  is packaged.
  Many gem maintainers have decided that the permissions of the files
  in their bundled would be 0444, this includes amongst others:
  minitest, selenium, brakeman...

  Any git gems that had a 0444 permissions at some point in its git
  history would also be reported (as bundle doctor look in the
  `cache/bundler/git/<gem>/object` path).

  While it completely make sense to report when files aren't readable,
  maybe it's worth questioning the usefulness of reporting files
  that can't be written and what problem this causes to the user
  (if any).

  ### Solution

  Removed the check for unwritable file.

  ### Side note

  I also tweaked the "No issues ..." message logic as it was doing
  the opposite (reporting an issue when there is none and vice versa).
  This wasn't caught in tests because as a stub on `Bundler.ui.info`
  was missing.

9a426b9495
2025-02-25 15:36:46 +09:00
Samuel Williams
021ccbf7e8 [ruby/pp] Ensure the thread local state is always set up.
(https://github.com/ruby/pp/pull/38)

5b5d483ac2
2025-02-25 03:38:04 +00:00
Hiroshi SHIBATA
d97884a58b [ruby/cgi] Use license files same as ruby/ruby
defbdf9a30
2025-02-21 06:20:13 +00:00