Skip to content

Commit

Permalink
Merge branch 'trunk' into reese-arm
Browse files Browse the repository at this point in the history
  • Loading branch information
reese authored Sep 12, 2023
2 parents 8e31845 + e00d2ab commit c28e6ca
Show file tree
Hide file tree
Showing 90 changed files with 2,780 additions and 802 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ jobs:
key: ${{ runner.os }}-${{ matrix.target }}-ruby-v1-${{ hashFiles('.git/modules/librubyfmt/ruby_checkout/HEAD') }}
- if: runner.os == 'macOS'
run: |
brew install automake
brew install automake bison
echo "/usr/local/opt/bison/bin:$PATH" >> $GITHUB_PATH
- run: ./script/test.sh
env:
TARGET: ${{ matrix.target }}
Expand Down
97 changes: 97 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Release
on:
push:
tags:
- "*"

env:
BUNDLE_PATH: /tmp/.bundle
GEM_HOME: /tmp/.bundle
GEM_PATH: /tmp/.bundle
TERM: xterm256

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: native
- os: macos-latest
target: native
- os: ubuntu-20.04
target: aarch64-unknown-linux-gnu
steps:
- uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 0
- if: runner.os == 'macOS'
uses: actions-rs/toolchain@v1
with:
toolchain: 1.63.0
target: aarch64-apple-darwin
default: true
override: true
profile: minimal
- if: runner.os != 'macOS'
uses: actions-rs/toolchain@v1
with:
toolchain: 1.63.0
override: true
profile: minimal
target: aarch64-unknown-linux-gnu
- uses: actions/cache@v2
with:
path: |
librubyfmt/ruby_checkout
key: ${{ runner.os }}-${{matrix.target}}-ruby-v1-${{ hashFiles('.git/modules/librubyfmt/ruby_checkout/HEAD') }}
- if: runner.os == 'macOS'
run: |
brew install automake bison
echo "/usr/local/opt/bison/bin:$PATH" >> $GITHUB_PATH
- run: ./script/make_release
- uses: actions/upload-artifact@v3
with:
name: rubyfmt-release-artifact-${{ matrix.os }}-${{ matrix.target }}
path: rubyfmt-*.tar.gz
source-release:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 0
- run: |
TAG=$(git describe HEAD)
RELEASE_DIR="out/release"
mkdir -p ${RELEASE_DIR}
./script/make_source_release ${TAG}
- uses: actions/upload-artifact@v3
with:
name: rubyfmt-source-release
path: "out/release/source"
release:
runs-on: macos-latest
needs:
- build
- source-release
steps:
- uses: actions/download-artifact@v3
with:
name: rubyfmt-source-release
- uses: actions/download-artifact@v3
with:
name: rubyfmt-release-artifact-ubuntu-latest
- uses: actions/download-artifact@v3
with:
name: rubyfmt-release-artifact-macos-latest
- name: Ship It 🚢
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: rubyfmt-*.tar.gz
fail_on_unmatched_files: true
generate_release_notes: true
33 changes: 29 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ members = [

[package]
name = "rubyfmt-main"
version = "0.8.0-pre"
version = "0.10.0"
authors = ["Penelope Phippen <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
atty = "0.2"
clap = { version = "3.2.16", features = ["derive"] }
ctrlc = { version = "3.2", features = ["termination"] }
dirs = "3.0.2"
filetime = "0.2.14"
glob = "0.3"
Expand Down
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@

## How do I use it

Build it:

### Install from `brew`

On Mac and Linux, `rubyfmt` can be installed with [Homebrew](https://brew.sh/):

```bash
brew install rubyfmt
```

### Build from source

1. Make sure you've got cargo installed
2. Run `make all`
3. Copy target/release/rubyfmt-main to somewhere on your path as `rubyfmt`
Expand All @@ -18,6 +28,10 @@ Rubyfmt supports the following CLI invocations:
* `rubyfmt --header-opt-in -- files or directories` to format files only with a `# rubyfmt: true` comment at the top of the file
* `rubyfmt --header-opt-out -- files or directories` to skip formatting files with a `# rubyfmt: false` comment at the top of the file

`rubyfmt` also supports ignoring files with a `.rubyfmtignore` file when present in the root of the working directory.
`.rubyfmtignore` uses the same syntax as `.gitignore`, so you can choose to ignore whole directories or use globs as needed.
By default, `rubyfmt` also ignores files in `.gitignore` during file traversal, but you can force these files to be formatted by using the `--include-gitignored` flag.

## Editor Support

### Vim
Expand All @@ -29,6 +43,22 @@ plugin from a git clone is fairly easy:
* Add `source /path/to/rubyfmt.vim` to your `~/.vimrc` (e.g. [my dotfiles](https://github.com/penelopezone/dotfiles/commit/2c0e9c1215de368e64e063021e9523aa349c5454#diff-2152fa38b4d8bb10c75d6339a959650dR253) please note, this line is commented)
* Add `let g:rubyfmt_path = /path/to/target/release/rubyfmt-main` beneath the source line

### Neovim + LSP + null-ls

If you use the popular [null-ls](https://github.com/jose-elias-alvarez/null-ls.nvim) LSP plugin to manage formatters, it supports `rubyfmt` out of the box. You can add the formatter to your existing `setup()` configuration:

```diff
local null_ls = require("null-ls")

null_ls.setup({
sources = {
+ null_ls.builtins.formatting.rubyfmt,
},
})
```

Read more in the [null-ls documentation](https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md#rubyfmt).

### Visual Studio Code

Rubyfmt is a supported formatter in the popular
Expand Down
1 change: 1 addition & 0 deletions dockerfiles/build.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8
RUN apt-get install -y bison libyaml-dev

ADD ./ /root/rubyfmt.git
9 changes: 7 additions & 2 deletions fixtures/large/rspec_mocks_proxy_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,10 @@ def reset
class PartialDoubleProxy < Proxy
def original_method_handle_for(message)
if any_instance_class_recorder_observing_method?(@object.class, message)
message = ::RSpec::Mocks.space.any_instance_recorder_for(@object.class).build_alias_method_name(message)
message = ::RSpec::Mocks
.space
.any_instance_recorder_for(@object.class)
.build_alias_method_name(message)
end

::RSpec::Support.method_handle_for(@object, message)
Expand Down Expand Up @@ -390,7 +393,9 @@ def initialize(source_space, *args)
# That's what this method (together with `original_unbound_method_handle_from_ancestor_for`)
# does.
def original_method_handle_for(message)
unbound_method = superclass_proxy && superclass_proxy.original_unbound_method_handle_from_ancestor_for(message.to_sym)
unbound_method = superclass_proxy && superclass_proxy.original_unbound_method_handle_from_ancestor_for(
message.to_sym
)

return super unless unbound_method
unbound_method.bind(object)
Expand Down
20 changes: 20 additions & 0 deletions fixtures/small/aref_field_actual.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# As above
a[0] = b
# So below

a[puts a] = ""
a[puts(a)] = ""
a[()] = ""
a[class A; def foo; puts a; end; end] = ""
a[begin; ""; rescue StandardException; ""; end] = ""
# Users can override #[]= to not have args
a[] = ""
# Users can override #[]= to have multiple args
a[1, 2] = ""

a[puts a]
a[puts(a)]
a[()]
a[class A; def foo; puts a; end; end]
a[begin; ""; rescue StandardException; ""; end]
# Users can override #[] to not have args
a[]
# Users can override #[] to have multiple args
a[1, 2]
44 changes: 44 additions & 0 deletions fixtures/small/aref_field_expected.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
# As above
a[0] = b
# So below

a[puts(a)] = ""
a[puts(a)] = ""
a[()] = ""
a[
class A
def foo
puts(a)
end
end
] = ""
a[
begin
""
rescue StandardException
""
end
] = ""
# Users can override #[]= to not have args
a[] = ""
# Users can override #[]= to have multiple args
a[1, 2] = ""

a[puts(a)]
a[puts(a)]
a[()]
a[
class A
def foo
puts(a)
end
end
]
a[
begin
""
rescue StandardException
""
end
]
# Users can override #[] to not have args
a[]
# Users can override #[] to have multiple args
a[1, 2]
9 changes: 8 additions & 1 deletion fixtures/small/aref_in_call_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@
)
.void
end
def foo; end
def foo; end

Array[
@root_fragment,
@lemon_tea_fragment,
@green_tea_fragment,
@cake_fragment
].sort_by(&:name)
7 changes: 7 additions & 0 deletions fixtures/small/aref_in_call_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@
end
def foo
end

Array[
@root_fragment,
@lemon_tea_fragment,
@green_tea_fragment,
@cake_fragment
].sort_by(&:name)
4 changes: 4 additions & 0 deletions fixtures/small/begin_end_stack_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
a = begin
end
end

begin
end
.freeze
3 changes: 3 additions & 0 deletions fixtures/small/begin_end_stack_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
a = begin
end
end

begin
end.freeze
Loading

0 comments on commit c28e6ca

Please sign in to comment.