Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ruby-syntax-tree/prettier_print
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.1.0
Choose a base ref
...
head repository: ruby-syntax-tree/prettier_print
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.0.0
Choose a head ref
  • 5 commits
  • 5 files changed
  • 3 contributors

Commits on Oct 4, 2022

  1. Bump test-unit from 3.5.3 to 3.5.5

    Bumps [test-unit](https://github.com/test-unit/test-unit) from 3.5.3 to 3.5.5.
    - [Release notes](https://github.com/test-unit/test-unit/releases)
    - [Commits](test-unit/test-unit@3.5.3...3.5.5)
    
    ---
    updated-dependencies:
    - dependency-name: test-unit
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Oct 4, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3a529d3 View commit details
  2. Merge pull request #1 from ruby-syntax-tree/dependabot/bundler/test-u…

    …nit-3.5.5
    
    Bump test-unit from 3.5.3 to 3.5.5
    github-actions[bot] authored Oct 4, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e71c168 View commit details

Commits on Oct 17, 2022

  1. Optimizations

    This commit brings a bunch of optimizations to prettier_print, mostly
    in terms of cutting down on allocations.
    
    Most of the common patterns are now using pre-allocated doc nodes
    instead of building new ones every time. For nodes that are markers
    like BreakParent or Trim, there are now instances that correspond to
    them like BREAK_PARENT and TRIM which are used.
    
    For breakables, we now have methods that encapsulate the most common
    use cases. These are:
    
    * breakable_space = breakable
    * breakable_empty = breakable("")
    * breakable_force = breakable("", force: true)
    * breakable_return = breakable(" ", indent: false, force: true)
    
    In terms of a couple of breaking changes:
    
    * Trim now strips its whitespace using rstrip! instead of a custom
      gsub!. This means that other forms of whitespace beyond tabs and
      spaces are included. This shouldn't really impact anyone unless
      they're using vertical tab or something in combination with trim
      nodes and wanted them to stay in.
    * There is no longer a PrettierPrint::DefaultBuffer class. Since
      there were only ever two implementations, those implementations
      now no longer share a parent.
    * PrettierPrint::IndentLevel is now entirely gone. This was mostly
      an implementation detail, and no one should have been relying on
      it anyway. However, it means that the ability to use nest with a
      string literal is now gone as well. It can be created again by
      using seplist though, so the functionality just isn't there in
      the shortcut version. This means we're able to keep track of
      indentation as a single integer again, which drastically
      simplifies the code.
    * Strings can now be added directly to the output buffer, which
      means they don't have to be placed into the Text node. This cuts
      down on quite a bit of allocations.
    
    The last optimization is that if_break and if_flat now check if
    the parent group is already broken. If it is, then they don't
    bother inserting the content into the final tree. This can cut down
    on the number of nodes in the final tree by quite a lot.
    kddnewton committed Oct 17, 2022
    Copy the full SHA
    14c1c7c View commit details
  2. Merge pull request #2 from ruby-syntax-tree/opt

    Optimizations
    kddnewton authored Oct 17, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    15a016d View commit details
  3. Bump to v1.0.0

    kddnewton committed Oct 17, 2022
    Copy the full SHA
    655114f View commit details
Showing with 231 additions and 237 deletions.
  1. +19 −0 CHANGELOG.md
  2. +3 −2 Gemfile.lock
  3. +1 −5 README.md
  4. +207 −229 lib/prettier_print.rb
  5. +1 −1 lib/prettier_print/version.rb
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,25 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]

## [1.0.0] - 2022-10-17

### Added

* `breakable_space` - a shortcut for `breakable`
* `breakable_empty` - a shortcut for `breakable("")`
* `breakable_force` - a shortcut for `breakable("", force: true)`
* `breakable_return` - a shortcut for `breakable(" ", indent: false, force: true)`
* Strings can now be added directly to the output buffer, which means they don't have to be placed into the `Text` node. This cuts down on quite a bit of allocations.

### Changed

* `trim` now strips its whitespace using `rstrip!` instead of a custom `gsub!`. This means that other forms of whitespace beyond tabs and spaces are included. This shouldn't really impact anyone unless they're using vertical tab or something in combination with `trim` and wanted them to stay in.

### Removed

* There is no longer a `PrettierPrint::DefaultBuffer` class. Since there were only ever two implementations, those implementations now no longer share a parent.
* `PrettierPrint::IndentLevel` is now entirely gone. This was mostly an implementation detail, and no one should have been relying on it anyway. However, it means that the ability to use nest with a string literal is now gone as well. It can be created again by using seplist though, so the functionality just isn't there in the shortcut version. This means we're able to keep track of indentation as a single integer again, which drastically simplifies the code.

## [0.1.0] - 2022-05-13

### Added
5 changes: 3 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
PATH
remote: .
specs:
prettier_print (0.1.0)
prettier_print (1.0.0)

GEM
remote: https://rubygems.org/
specs:
power_assert (2.0.1)
rake (13.0.6)
test-unit (3.5.3)
test-unit (3.5.5)
power_assert

PLATFORMS
arm64-darwin-21
x86_64-darwin-21
x86_64-linux

6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -137,11 +137,7 @@ This node increases the indentation by a fixed number of spaces or a string. It
q.nest(2) {}
```

It accepts a block that specifies the contents of the alignment node. The value that you're indenting by can be positive or negative. It can also be a string, in which case that value will be used at the beginning of each line, as in:

```ruby
q.nest("-->") {}
```
It accepts a block that specifies the contents of the alignment node. The value that you're indenting by can be positive or negative.

#### `BreakParent`

Loading