Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
62f6231
Start building out jest test cases
kddnewton Apr 11, 2019
e914c02
Split up test utils
kddnewton Apr 11, 2019
1d5ec2e
Move setup into test directory
kddnewton Apr 11, 2019
9306f70
Fix up tests
kddnewton Apr 11, 2019
60ba16f
Make checks async
kddnewton Apr 11, 2019
88c4826
Move old tests into new format
kddnewton Apr 11, 2019
dc9c1ee
Move binary test over
kddnewton Apr 11, 2019
c72e60e
Move numbers test over
kddnewton Apr 11, 2019
f27c902
Move range tests over
kddnewton Apr 11, 2019
e4755f9
Move next tests over
kddnewton Apr 11, 2019
b257fde
Move over super tests
kddnewton Apr 11, 2019
4af28fb
Move return tests over
kddnewton Apr 11, 2019
d9e293b
Move over hooks tests
kddnewton Apr 11, 2019
86ddb31
Move over regexp tests
kddnewton Apr 12, 2019
7d1ed94
Move over rescue tests
kddnewton Apr 12, 2019
c0b395e
Move lambda tests over
kddnewton Apr 12, 2019
f109ca5
Move over encoding tests
kddnewton Apr 12, 2019
f723f7b
Move over embdoc tests
kddnewton Apr 12, 2019
4d1d212
Move over case tests
kddnewton Apr 12, 2019
3a0a072
Move hash tests over
kddnewton Apr 12, 2019
c76c06e
Move over kwargs test
kddnewton Apr 12, 2019
0b9ed44
Move over layout tests
kddnewton Apr 12, 2019
e3ff01e
Move over string tests
kddnewton Apr 12, 2019
2cb505e
Fix up test formatting
kddnewton Apr 12, 2019
05ca16d
Move method tests over
kddnewton Apr 12, 2019
7bbdee9
Move over conditionals tests
kddnewton Apr 12, 2019
8160206
Move over assign tests
kddnewton Apr 12, 2019
f4103c4
Move error tests over
kddnewton Apr 12, 2019
de6dfbc
Add methref test
kddnewton Apr 12, 2019
132010d
Move escapePattern tests over
kddnewton Apr 12, 2019
3ba93f0
Move hasPragma tests over
kddnewton Apr 12, 2019
9060539
Move over class tests
kddnewton Apr 12, 2019
beb8748
Move nodes tests over
kddnewton Apr 12, 2019
89e365f
Remove old test runner
kddnewton Apr 12, 2019
cd9733c
Move over block tests
kddnewton Apr 12, 2019
5896ab8
Move over comment tests
kddnewton Apr 12, 2019
5419511
Remove defunct test configs
kddnewton Apr 12, 2019
62d2f9a
Move ruby tests under test/rb
kddnewton Apr 12, 2019
851d52d
Move over files to match interpreter tests
kddnewton Apr 12, 2019
7de2e9a
Rename some test files
kddnewton Apr 12, 2019
6f6a9df
Test out invalid ruby parsing
kddnewton Apr 12, 2019
3686bae
Bump deps
kddnewton Apr 13, 2019
5bc389e
Fix up lint
kddnewton Apr 14, 2019
03090ee
Fix up loop spacing
kddnewton Apr 14, 2019
0f3a989
Fix up ruby tests
kddnewton Apr 14, 2019
6a3e1f4
Try explicitly setting the ruby version for travis
kddnewton Apr 14, 2019
dd791a5
Fix up command call inline comments
kddnewton Apr 14, 2019
5082ea9
Fix up comment pulling
kddnewton Apr 14, 2019
5dd436c
Run prettier
kddnewton Apr 14, 2019
d309ca5
Make when predicates fill the line and then break
kddnewton Apr 14, 2019
6655d37
Reformat the parser
kddnewton Apr 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}],
"object-curly-newline": "off",
"prefer-spread": "off",
"quotes": ["error", "double"]
"quotes": "off"
},
"globals": {
"runCase": "readonly"
Expand Down
1 change: 1 addition & 0 deletions 1 .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.eslintcache
/coverage/
/node_modules/
/yarn-error.log
Expand Down
8 changes: 4 additions & 4 deletions 8 .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
language: ruby
rvm:
- ruby-head
- 2.6.1
- 2.5.3
- 2.6.2
- 2.5.5
branches:
only: master
before_install: bin/ci-install
script:
- yarn test
- RUBY_VERSION=$(ruby -e 'puts RUBY_VERSION') yarn test
- yarn lint
- yarn build
- gem build prettier.gemspec
- bundle exec rake test
- bundle exec rbprettier --check 'src/ripper.rb' 'lib/**/*.rb' 'test/*_test.rb' 'prettier.gemspec'
- bundle exec rbprettier --check 'src/ripper.rb' 'lib/**/*.rb' 'test/rb/*_test.rb' 'prettier.gemspec'
cache:
- bundler
- yarn
2 changes: 2 additions & 0 deletions 2 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
## [Unreleased]
### Added
- Support for parsing things with a ruby shebang (e.g., `#!/usr/bin/env ruby` or `#!/usr/bin/ruby`).
- [INTERNAL] Big tests refactor.
- Make multiple `when` predicates break at 80 chars and then wrap to be inline with the other predicates.

## [0.10.0] - 2019-03-25
### Added
Expand Down
4 changes: 2 additions & 2 deletions 4 Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ require 'bundler/gem_tasks'
require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'test/rb'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
t.test_files = FileList['test/rb/**/*_test.rb']
end

task default: :test
6 changes: 3 additions & 3 deletions 6 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "src/ruby.js",
"scripts": {
"build": "pkg --output pkg/prettier --targets=linux,macos,win node_modules/prettier/bin-prettier.js",
"lint": "eslint .",
"lint": "eslint --cache .",
"print": "prettier --plugin=.",
"rubocop": "run() { prettier --plugin=. $@ | bundle exec rubocop --stdin $1; }; run",
"test": "jest"
Expand All @@ -32,8 +32,8 @@
"pkg": "^4.3.7"
},
"jest": {
"setupFiles": [
"./test/testRunner.js"
"setupFilesAfterEnv": [
"./test/js/setupTests.js"
],
"testRegex": ".test.js$"
}
Expand Down
11 changes: 9 additions & 2 deletions 11 src/nodes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { align, breakParent, concat, dedent, group, hardline, ifBreak, indent, join, line, literalline, markAsRoot, softline, trim } = require("prettier").doc.builders;
const { align, breakParent, concat, dedent, fill, group, hardline, ifBreak, indent, join, line, literalline, markAsRoot, softline, trim } = require("prettier").doc.builders;
const { removeLines } = require("prettier").doc.utils;
const { concatBody, empty, first, literal, makeArgs, makeCall, makeList, prefix, printComments, skipAssignIndent } = require("./utils");

Expand Down Expand Up @@ -564,8 +564,15 @@ const nodes = {
when: (path, opts, print) => {
const [_predicates, _statements, addition] = path.getValue().body;

const predicates = path.call(print, "body", 0).reduce(
(accum, pred, index) => (
index === 0 ? [pred] : accum.concat([",", line, pred])
),
null
);

const stmts = path.call(print, "body", 1);
const parts = [group(concat(["when ", join(", ", path.call(print, "body", 0))]))];
const parts = [group(concat(["when ", align(5, fill(predicates))]))];

if (!stmts.parts.every(part => !part)) {
parts.push(indent(concat([hardline, stmts])));
Expand Down
7 changes: 5 additions & 2 deletions 7 src/nodes/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,14 @@ const printBlock = (path, opts, print) => {
return concat([breakParent, doBlock]);
}

const hasBody = stmts.some(({ type }) => type !== "void_stmt");
const braceBlock = concat([
" { ",
" {",
(hasBody || variables) ? " " : "",
variables ? path.call(print, "body", 0) : "",
path.call(print, "body", 1),
" }"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

hasBody ? " " : "",
"}"
]);

return group(ifBreak(doBlock, braceBlock));
Expand Down
8 changes: 5 additions & 3 deletions 8 src/ripper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ module InlineComments
assoc_new: [:body, 1],
break: [:body, 0],
command: [:body, 1],
command_call: [:body, 3],
string_literal: [:body, 0]
}

Expand All @@ -268,7 +269,7 @@ def self.prepended(base)
define_method(:"on_#{event}") do |*body|
@last_sexp =
super(*body).tap do |sexp|
comments = sexp.dig(*path).delete(:comments)
comments = (sexp.dig(*path) || {}).delete(:comments)
sexp.merge!(comments: comments) if comments
end
end
Expand Down Expand Up @@ -320,7 +321,8 @@ def on_comment(body)
case RipperJS.lex_state_name(state)
when 'EXPR_END', 'EXPR_ARG|EXPR_LABELED', 'EXPR_ENDFN'
last_sexp.merge!(comments: [sexp])
when 'EXPR_CMDARG', 'EXPR_END|EXPR_ENDARG', 'EXPR_ENDARG', 'EXPR_ARG', 'EXPR_FNAME|EXPR_FITEM', 'EXPR_CLASS', 'EXPR_END|EXPR_LABEL'
when 'EXPR_CMDARG', 'EXPR_END|EXPR_ENDARG', 'EXPR_ENDARG', 'EXPR_ARG',
'EXPR_FNAME|EXPR_FITEM', 'EXPR_CLASS', 'EXPR_END|EXPR_LABEL'
inline_comments << sexp
when 'EXPR_BEG|EXPR_LABEL', 'EXPR_MID'
inline_comments << sexp.merge!(break: true)
Expand Down Expand Up @@ -410,7 +412,7 @@ class RipperJS < Ripper
builder = RipperJS.new($stdin.read)
response = builder.parse

if builder.error?
if !response && builder.error?
STDERR.puts 'Invalid ruby'
exit 1
end
Expand Down
8 changes: 5 additions & 3 deletions 8 src/ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ const print = require("./print");
const pragmaPattern = /#\s*@(prettier|format)/;
const hasPragma = text => pragmaPattern.test(text);

// extensions, filenames and interpreters mostly pulled from linguist and rubocop
// https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
// https://github.com/rubocop-hq/rubocop/blob/master/spec/rubocop/target_finder_spec.rb
/*
* metadata mostly pulled from linguist and rubocop:
* https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
* https://github.com/rubocop-hq/rubocop/blob/master/spec/rubocop/target_finder_spec.rb
*/

module.exports = {
languages: [{
Expand Down
29 changes: 0 additions & 29 deletions 29 test/cases/__snapshots__/alias.test.js.snap

This file was deleted.

189 changes: 0 additions & 189 deletions 189 test/cases/__snapshots__/array.test.js.snap

This file was deleted.

Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.