Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into awesomecode-plugin-ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed Feb 10, 2021
2 parents 68a3d14 + 637b841 commit 72fa7f5
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
# - truffleruby
runs-on: ${{ matrix.os }}
env:
CI: true
PLUGIN_RUBY_CI: true
steps:
- uses: actions/checkout@master

Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
name: Lint
runs-on: ubuntu-latest
env:
CI: true
PLUGIN_RUBY_CI: true
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@v2-beta
Expand Down
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]

## [1.5.2] - 2021-02-03

### Changed

- kddeisz - Fix up `binary` node comparison operators so that it will handle either Symbol literals or the `@op` nodes which are incorrectly coming from JRuby (https://github.com/jruby/jruby/issues/6548).

## [1.5.1] - 2021-01-27

### Changed
Expand Down Expand Up @@ -199,7 +205,7 @@ end
- kddeisz - Fix up a bug with constant aliases, e.g., `alias in IN`.
- andyw8, kddeisz - Ensure `rescue` comments stay on the same line as their declaration.

# [0.22.0] - 2020-12-08
## [0.22.0] - 2020-12-08

### Changed

Expand Down Expand Up @@ -1071,7 +1077,8 @@ would previously result in `array[]`, but now prints properly.

- Initial release 🎉

[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.5.1...HEAD
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.5.2...HEAD
[1.5.2]: https://github.com/prettier/plugin-ruby/compare/v1.5.1...v1.5.2
[1.5.1]: https://github.com/prettier/plugin-ruby/compare/v1.5.0...v1.5.1
[1.5.0]: https://github.com/prettier/plugin-ruby/compare/v1.4.0...v1.5.0
[1.4.0]: https://github.com/prettier/plugin-ruby/compare/v1.3.0...v1.4.0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "awesomecode-plugin-ruby",
"version": "1.5.1",
"version": "1.5.2",
"description": "prettier plugin for the Ruby programming language",
"main": "src/plugin.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/parser/server.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'bundler/setup' if ENV['CI']
require 'bundler/setup' if ENV['PLUGIN_RUBY_CI']
require 'socket'
require 'json'

Expand All @@ -14,7 +14,7 @@
# Make sure we trap these signals to be sure we get the quit command coming from
# the parent node process
quit = false
trap(:QUIT) { quit = true }
trap(:QUIT) { quit = true } if RUBY_PLATFORM != 'java'
trap(:INT) { quit = true }
trap(:TERM) { quit = true }

Expand Down
12 changes: 7 additions & 5 deletions src/ruby/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
stripTrailingHardline
} = require("../prettier");

const { literalLineNoBreak } = require("../utils");
const { literallineWithoutBreakParent } = require("../utils");

const parsers = {
css: "css",
Expand All @@ -30,7 +30,7 @@ function replaceNewlines(doc) {
? concat(
currentDoc
.split(/(\n)/g)
.map((v, i) => (i % 2 === 0 ? v : literalLineNoBreak))
.map((v, i) => (i % 2 === 0 ? v : literallineWithoutBreakParent))
)
: currentDoc
);
Expand Down Expand Up @@ -106,7 +106,7 @@ function embed(path, print, textToDoc, _opts) {

// Pass that content into the embedded parser. Get back the doc node.
const formatted = concat([
literalLineNoBreak,
literallineWithoutBreakParent,
replaceNewlines(stripTrailingHardline(textToDoc(content, { parser })))
]);

Expand All @@ -119,7 +119,7 @@ function embed(path, print, textToDoc, _opts) {
group(
concat([
indent(markAsRoot(formatted)),
literalLineNoBreak,
literallineWithoutBreakParent,
ending.trim()
])
)
Expand All @@ -132,7 +132,9 @@ function embed(path, print, textToDoc, _opts) {
return markAsRoot(
concat([
path.call(print, "beging"),
lineSuffix(group(concat([formatted, literalLineNoBreak, ending.trim()])))
lineSuffix(
group(concat([formatted, literallineWithoutBreakParent, ending.trim()]))
)
])
);
}
Expand Down
8 changes: 5 additions & 3 deletions src/ruby/nodes/heredocs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { concat, group, lineSuffix, join } = require("../../prettier");
const { literalLineNoBreak } = require("../../utils");
const { literallineWithoutBreakParent } = require("../../utils");

function printHeredoc(path, opts, print) {
const { body, ending } = path.getValue();
Expand All @@ -11,7 +11,7 @@ function printHeredoc(path, opts, print) {
}

// In this case, the part of the string is just regular string content
return join(literalLineNoBreak, part.body.split("\n"));
return join(literallineWithoutBreakParent, part.body.split("\n"));
});

// We use a literalline break because matching indentation is required
Expand All @@ -23,7 +23,9 @@ function printHeredoc(path, opts, print) {
concat([
path.call(print, "beging"),
lineSuffix(
group(concat([literalLineNoBreak].concat(parts).concat(ending)))
group(
concat([literallineWithoutBreakParent].concat(parts).concat(ending))
)
)
])
);
Expand Down
6 changes: 6 additions & 0 deletions src/ruby/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,12 @@ def on_begin(bodystmt)
# binary is a parser event that represents a binary operation between two
# values.
def on_binary(left, oper, right)
# On most Ruby implementations, oper is a Symbol that represents that
# operation being performed. For instance in the example `1 < 2`, the `oper`
# object would be `:<`. However, on JRuby, it's an `@op` node, so here we're
# going to explicitly convert it into the same normalized form.
oper = scanner_events.delete(oper)[:body] unless oper.is_a?(Symbol)

{
type: :binary,
body: [left, oper, right],
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
isEmptyStmts: require("./utils/isEmptyStmts"),
hasAncestor: require("./utils/hasAncestor"),
literal: require("./utils/literal"),
literalLineNoBreak: require("./utils/literalLineNoBreak"),
literallineWithoutBreakParent: require("./utils/literallineWithoutBreakParent"),
makeCall: require("./utils/makeCall"),
noIndent: require("./utils/noIndent"),
printEmptyCollection: require("./utils/printEmptyCollection"),
Expand Down
7 changes: 0 additions & 7 deletions src/utils/literalLineNoBreak.js

This file was deleted.

7 changes: 7 additions & 0 deletions src/utils/literallineWithoutBreakParent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const literallineWithoutBreakParent = {
type: "line",
hard: true,
literal: true
};

module.exports = literallineWithoutBreakParent;

0 comments on commit 72fa7f5

Please sign in to comment.