Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Apr 22, 2022
1 parent 7658e5b commit 1cdf021
Show file tree
Hide file tree
Showing 22 changed files with 138 additions and 1,161 deletions.
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ The comment in the above example should stay in place.

```ruby
begin

rescue Foo, Bar
# comment
end
Expand Down Expand Up @@ -476,7 +475,8 @@ return (a or b) if c?
- kddnewton - Support for the `nokw_param` node for specifying when methods should no accept keywords, as in:

```ruby
def foo(**nil); end
def foo(**nil)
end
```

- kddnewton - Support for the `args_forward` node for forwarding all types of arguments, as in:
Expand Down Expand Up @@ -522,9 +522,9 @@ will now be printed as:

```ruby
Config::Download.new(
'prettier',
filename: 'prettier.yml',
url: 'https://raw.githubusercontent.com/...'
"prettier",
filename: "prettier.yml",
url: "https://raw.githubusercontent.com/..."
).perform
```

Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ d = [
30_643_069_058
]
a, s = [], $*[0]
s.each_byte { |b| a << ('%036b' % d[b.chr.to_i]).scan(/\d{6}/) }
s.each_byte { |b| a << ("%036b" % d[b.chr.to_i]).scan(/\d{6}/) }
a.transpose.each do |a|
a.join.each_byte { |i| print i == 49 ? ($*[1] || '#') : 32.chr }
a.join.each_byte { |i| printi == 49 ? ($*[1] || "#") : 32.chr }
puts
end
```
Expand All @@ -83,7 +83,7 @@ This plugin currently supports formatting the following kinds of files:
Add this line to your application's Gemfile:

```ruby
gem 'prettier'
gem "prettier"
```

And then execute:
Expand Down Expand Up @@ -128,11 +128,11 @@ The `prettier` executable is now installed and ready for use:

Below are the options (from [`src/plugin.js`](src/plugin.js)) that `@prettier/plugin-ruby` currently supports:

| API Option | CLI Option | Default | Description |
| ------------------ | ---------------------- | :------: | ------------------------------------------------------------------------------------------------------------------------------------ |
| `printWidth` | `--print-width` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)). |
| `requirePragma` | `--require-pragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)). |
| `tabWidth` | `--tab-width` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)). |
| API Option | CLI Option | Default | Description |
| --------------- | ------------------ | :-----: | --------------------------------------------------------------------------------------------------- |
| `printWidth` | `--print-width` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)). |
| `requirePragma` | `--require-pragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)). |
| `tabWidth` | `--tab-width` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)). |

Any of these can be added to your existing [prettier configuration
file](https://prettier.io/docs/en/configuration.html). For example:
Expand Down
10 changes: 5 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rake/testtask'
require "bundler/gem_tasks"
require "rake/testtask"

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

task default: :test
6 changes: 3 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require 'bundler/setup'
require 'prettier'
require "bundler/setup"
require "prettier"

require 'irb'
require "irb"
IRB.start(__FILE__)
14 changes: 7 additions & 7 deletions bin/debug
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/usr/bin/env ruby

require 'bundler/inline'
require "bundler/inline"

gemfile do
source 'https://rubygems.org'
gem 'sinatra', require: 'sinatra/base'
gem 'webrick'
source "https://rubygems.org"
gem "sinatra", require: "sinatra/base"
gem "webrick"
end

require_relative '../src/ruby/parser'
require_relative "../src/ruby/parser"

class App < Sinatra::Base
HTML = DATA.read

get '/' do
get "/" do
HTML
end

post '/ast' do
post "/ast" do
response = Prettier::Parser.parse(request.body.read)
response ? JSON.fast_generate(response) : halt(422)
rescue Prettier::Parser::ParserError
Expand Down
2 changes: 1 addition & 1 deletion bin/lex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby

require 'ripper'
require "ripper"

source = File.file?(ARGV[0]) ? File.read(ARGV[0]) : ARGV[0].gsub('\\n', "\n")
pp Ripper.lex(source)
6 changes: 3 additions & 3 deletions bin/sexp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env ruby

require_relative '../src/ruby/parser'
require_relative "../src/ruby/parser"

source =
if !ARGV[0]
File.read('test.rb')
File.read("test.rb")
elsif File.file?(ARGV[0])
File.read(ARGV[0])
else
Expand All @@ -13,7 +13,7 @@ source =

parsed = SyntaxTree.parse(source)

puts '=== SOURCE === '
puts "=== SOURCE === "
puts source

puts "\n=== COMMENTS ==="
Expand Down
4 changes: 2 additions & 2 deletions exe/rbprettier
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

$:.unshift(File.expand_path(File.join('..', 'lib'), __dir__))
require 'prettier'
$:.unshift(File.expand_path(File.join("..", "lib"), __dir__))
require "prettier"

exit(Prettier.run(ARGV))
18 changes: 9 additions & 9 deletions lib/prettier.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# frozen_string_literal: true

require 'json' unless defined?(JSON)
require 'open3'
require "json" unless defined?(JSON)
require "open3"

module Prettier
PLUGIN = -File.expand_path('..', __dir__)
BINARY = -File.join(PLUGIN, 'node_modules', 'prettier', 'bin-prettier.js')
VERSION = -JSON.parse(File.read(File.join(PLUGIN, 'package.json')))['version']
PLUGIN = -File.expand_path("..", __dir__)
BINARY = -File.join(PLUGIN, "node_modules", "prettier", "bin-prettier.js")
VERSION = -JSON.parse(File.read(File.join(PLUGIN, "package.json")))["version"]

def self.run(args)
quoted = args.map { |arg| arg.start_with?('-') ? arg : "\"#{arg}\"" }
command = "node #{BINARY} --plugin \"#{PLUGIN}\" #{quoted.join(' ')}"
quoted = args.map { |arg| arg.start_with?("-") ? arg : "\"#{arg}\"" }
command = "node #{BINARY} --plugin \"#{PLUGIN}\" #{quoted.join(" ")}"

stdout, stderr, status =
Open3.capture3({ 'RBPRETTIER' => '1' }, command, stdin_data: STDIN)
Open3.capture3({ "RBPRETTIER" => "1" }, command, stdin_data: STDIN)
STDOUT.puts(stdout)

# If we completed successfully, then just exit out.
Expand All @@ -30,7 +30,7 @@ def self.run(args)
If you installed this dependency through git instead of from rubygems,
it does not install the necessary files by default. To fix this you can
either install them yourself by cd-ing into the directory where this gem
is located (#{File.expand_path('..', __dir__)}) and running:
is located (#{File.expand_path("..", __dir__)}) and running:
`yarn && yarn prepublishOnly`
or
Expand Down
10 changes: 5 additions & 5 deletions lib/prettier/rake/task.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'rake'
require 'rake/tasklib'
require "rake"
require "rake/tasklib"

module Prettier
module Rake
Expand Down Expand Up @@ -35,7 +35,7 @@ class Task < ::Rake::TaskLib
def initialize(name = :prettier)
@name = name
@write = true
@source_files = 'lib/**/*.rb'
@source_files = "lib/**/*.rb"

yield self if block_given?
define_task
Expand All @@ -44,12 +44,12 @@ def initialize(name = :prettier)
private

def define_task
desc 'Runs prettier over source files'
desc "Runs prettier over source files"
task(name) { run_task }
end

def run_task
Prettier.run([('--write' if write), source_files].compact)
Prettier.run([("--write" if write), source_files].compact)
exit($?.exitstatus) if $?&.exited?
end
end
Expand Down
40 changes: 20 additions & 20 deletions prettier.gemspec
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
# frozen_string_literal: true

require 'json' unless defined?(JSON)
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
require "json" unless defined?(JSON)
package = JSON.parse(File.read(File.join(__dir__, "package.json")))

Gem::Specification.new do |spec|
spec.name = 'prettier'
spec.version = package['version']
spec.authors = [package['author']]
spec.name = "prettier"
spec.version = package["version"]
spec.authors = [package["author"]]

spec.summary = package['description']
spec.homepage = package['homepage']
spec.license = package['license']
spec.summary = package["description"]
spec.homepage = package["homepage"]
spec.license = package["license"]

spec.files =
Dir.chdir(__dir__) do
%w[LICENSE bin/console package.json rubocop.yml] +
Dir['{{exe,lib,dist}/**/*,*.md}'] +
Dir["{{exe,lib,dist}/**/*,*.md}"] +
Dir[
'node_modules/prettier/{package.json,index.js,cli.js,doc.js,bin-prettier.js,third-party.js,parser-*.js}'
"node_modules/prettier/{package.json,index.js,cli.js,doc.js,bin-prettier.js,third-party.js,parser-*.js}"
]
end

spec.required_ruby_version = '>= 2.7.3'
spec.required_ruby_version = ">= 2.7.3"

spec.bindir = 'exe'
spec.executables = 'rbprettier'
spec.bindir = "exe"
spec.executables = "rbprettier"
spec.require_paths = %w[lib]

spec.add_dependency 'syntax_tree'
spec.add_dependency 'syntax_tree-haml'
spec.add_dependency 'syntax_tree-rbs'
spec.add_dependency 'rbs', '~> 2'
spec.add_dependency "syntax_tree"
spec.add_dependency "syntax_tree-haml"
spec.add_dependency "syntax_tree-rbs"
spec.add_dependency "rbs", "~> 2"

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'minitest'
spec.add_development_dependency 'rake'
spec.add_development_dependency "bundler"
spec.add_development_dependency "minitest"
spec.add_development_dependency "rake"
end
Loading

0 comments on commit 1cdf021

Please sign in to comment.