Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce dependencies #245

Merged
merged 4 commits into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 21 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,27 @@ jobs:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: ${{ matrix.ruby }}
- run: bundle install
- run: bundle exec rspec spec/unit
ruby-mutant:
name: Mutant
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
ruby: [ruby-2.5, ruby-2.6, ruby-2.7, ruby-3.0]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: ${{ matrix.ruby }}
- run: bundle exec mutant run --since origin/master --zombie
ruby-integration-spec:
name: Integration Specs
runs-on: ${{ matrix.os }}
Expand All @@ -39,8 +57,8 @@ jobs:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: ${{ matrix.ruby }}
- run: bundle install
- run: bundle exec rspec spec/integration
ruby-rubocop:
name: Rubocop
Expand All @@ -55,6 +73,6 @@ jobs:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: ${{ matrix.ruby }}
- run: bundle install
- run: bundle exec rubocop
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ AllCops:
- 'Gemfile'
- 'Gemfile.triage'
Exclude:
- lib/unparser/precedence/data.rb
- tmp
- tmp/**/*
- vendor/**/*
NewCops: enable

# Avoid parameter lists longer than five parameters.
Expand Down
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v0.6.0 unreleased

[245](https://github.com/mbj/unparser/pull/245)

* Change to raise Unparser::InvalidNode error in some cases when unparsing invalid AST.
* Change `Unparser.unparse` into an official public API.
* Remove lots of dependencies.

# v0.5.7 2020-12-25

* Fix heredocs in return arguments [#244](https://github.com/mbj/unparser/pull/244)
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ source 'https://rubygems.org'

gemspec

gem 'mutant', git: 'https://github.com/mbj/mutant', branch: 'upgrade/unparser'

source 'https://oss:Px2ENN7S91OmWaD5G7MIQJi1dmtmYrEh@gem.mutant.dev' do
gem 'mutant-license'
end
75 changes: 19 additions & 56 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,69 +1,35 @@
GIT
remote: https://github.com/mbj/mutant
revision: d151dd5fdee91695fc0fde7591d498e6e27c7355
branch: upgrade/unparser
specs:
mutant (0.10.25)
ast (~> 2.2)
diff-lcs (~> 1.3)
parser (~> 3.0.0)
regexp_parser (~> 2.0, >= 2.0.3)
unparser (~> 0.6.0)
mutant-rspec (0.10.25)
mutant (= 0.10.25)
rspec-core (>= 3.8.0, < 4.0.0)

PATH
remote: .
specs:
unparser (0.5.7)
abstract_type (~> 0.0.7)
adamantium (~> 0.2.0)
anima (~> 0.3.1)
concord (~> 0.1.5)
unparser (0.6.0)
diff-lcs (~> 1.3)
equalizer (~> 0.0.9)
mprelude (~> 0.1.0)
parser (>= 3.0.0)
procto (~> 0.0.2)

GEM
remote: https://rubygems.org/
remote: https://oss:Px2ENN7S91OmWaD5G7MIQJi1dmtmYrEh@gem.mutant.dev/
specs:
abstract_type (0.0.7)
adamantium (0.2.0)
ice_nine (~> 0.11.0)
memoizable (~> 0.4.0)
anima (0.3.2)
abstract_type (~> 0.0.7)
adamantium (~> 0.2)
equalizer (~> 0.0.11)
ast (2.4.1)
concord (0.1.6)
adamantium (~> 0.2.0)
equalizer (~> 0.0.9)
diff-lcs (1.4.4)
equalizer (0.0.11)
ice_nine (0.11.2)
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
mprelude (0.1.0)
abstract_type (~> 0.0.7)
adamantium (~> 0.2.0)
concord (~> 0.1.5)
equalizer (~> 0.0.9)
ice_nine (~> 0.11.1)
procto (~> 0.0.2)
mutant (0.10.25)
abstract_type (~> 0.0.7)
adamantium (~> 0.2.0)
anima (~> 0.3.1)
ast (~> 2.2)
concord (~> 0.1.5)
diff-lcs (~> 1.3)
equalizer (~> 0.0.9)
ice_nine (~> 0.11.1)
memoizable (~> 0.4.2)
mprelude (~> 0.1.0)
parser (~> 3.0.0)
procto (~> 0.0.2)
regexp_parser (~> 2.0, >= 2.0.3)
unparser (~> 0.5.6)
variable (~> 0.0.1)
mutant-license (0.1.1.2.2355046999240944981729280251890364410689.4)
mutant-rspec (0.10.25)
mutant (= 0.10.25)
rspec-core (>= 3.8.0, < 4.0.0)
parallel (1.20.1)
parser (3.0.0.0)
ast (~> 2.4.1)
procto (0.0.3)
rainbow (3.0.0)
regexp_parser (2.0.3)
rexml (3.2.4)
Expand Down Expand Up @@ -97,18 +63,15 @@ GEM
rubocop-packaging (0.5.1)
rubocop (>= 0.89, < 2.0)
ruby-progressbar (1.11.0)
thread_safe (0.3.6)
unicode-display_width (2.0.0)
variable (0.0.1)
equalizer (~> 0.0.11)

PLATFORMS
ruby

DEPENDENCIES
mutant (~> 0.10.22)
mutant!
mutant-license!
mutant-rspec (~> 0.10.22)
mutant-rspec (~> 0.10.25)
rspec (~> 3.9)
rspec-core (~> 3.9)
rspec-its (~> 1.3.0)
Expand All @@ -117,4 +80,4 @@ DEPENDENCIES
unparser!

BUNDLED WITH
2.2.3
2.2.5
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ People

Various people contributed to this repository. See [Contributors](https://github.com/mbj/unparser/graphs/contributors).

Included Libraries
------------------

For dependency reduction reasons unparser ships vendored (and reduced) versions of:

* [abstract_type](https://github.com/mbj/concord) -> Unparser::AbstractType
* [adamantium](https://github.com/dkubb/adamantium) -> Unparser::Adamantium
* [anima](https://github.com/mbj/concord) -> Unparser::Anima
* [concord](https://github.com/mbj/concord) -> Unparser::Concord
* [memoizable](https://github.com/dkubb/memoizable) -> Unparser::Adamantium
* [mprelude](https://github.com/dkubb/memoizable) -> Unparser::Either

Contributing
-------------

Expand Down
35 changes: 35 additions & 0 deletions config/mutant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,38 @@ includes:
integration: rspec
requires:
- unparser
matcher:
subjects:
- 'Unparser*'
ignore:
# API changed between ruby versions and each of them
# have a different minimal form
- 'Unparser::Concord#define_readers'
- 'Unparser::Builder#initialize'
- 'Unparser::CLI*'
- 'Unparser::Emitter#emit_comments'
- 'Unparser::Emitter#emit_comments_before'
- 'Unparser::Emitter#emit_eol_comments'
- 'Unparser::Emitter.handle'
- 'Unparser::Emitter::Args#normal_arguments'
- 'Unparser::Emitter::Args#shadowargs'
- 'Unparser::Emitter::Array#emitters'
- 'Unparser::Emitter::Binary#writer'
- 'Unparser::Emitter::Block#target_writer'
- 'Unparser::Emitter::Class#dispatch'
- 'Unparser::Emitter::Class#local_variable_scope'
- 'Unparser::Emitter::Def#local_variable_scope'
- 'Unparser::Emitter::HashPattern#write_symbol_body'
- 'Unparser::Emitter::LocalVariableRoot*'
- 'Unparser::Emitter::LocalVariableRoot.included'
- 'Unparser::Emitter::Module#local_variable_scope'
- 'Unparser::Emitter::Root#local_variable_scope'
- 'Unparser::Emitter::Send#writer'
- 'Unparser::NodeDetails.included'
- 'Unparser::Validation.from_string'
- 'Unparser::Validation::Literal*'
- 'Unparser::Writer.included'
- 'Unparser::Writer::Binary#left_emitter'
- 'Unparser::Writer::Binary#right_emitter'
- 'Unparser::Writer::Send#details'
- 'Unparser::Writer::Send#effective_writer'
44 changes: 31 additions & 13 deletions lib/unparser.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# frozen_string_literal: true

require 'abstract_type'
require 'anima'
require 'concord'
require 'diff/lcs'
require 'diff/lcs/hunk'
require 'mprelude'
require 'optparse'
require 'parser/current'
require 'procto'
require 'set'

require 'unparser/equalizer'
require 'unparser/adamantium'
require 'unparser/adamantium/method_builder'
require 'unparser/abstract_type'

require 'unparser/concord'
require 'unparser/either'
require 'unparser/anima'
require 'unparser/anima/attribute'
require 'unparser/anima/error'

# Library namespace
module Unparser
# Unparser specific AST builder defaulting to modern AST format
Expand All @@ -27,7 +33,18 @@ def initialize
EMPTY_STRING = ''.freeze
EMPTY_ARRAY = [].freeze

private_constant(*constants(false))
private_constant(*constants(false) - %i[Adamantium AbstractType Anima Concord Either Equalizer Memoizable])

# Error raised when unparser encounters an invalid AST
class InvalidNodeError < RuntimeError
attr_reader :node

def initialize(message, node)
super(message)
@node = node
freeze
end
end

# Unparse an AST (and, optionally, comments) into a string
#
Expand All @@ -36,8 +53,10 @@ def initialize
#
# @return [String]
#
# @api private
# @raise InvalidNodeError
# if the node passed is invalid
#
# @api public
def self.unparse(node, comment_array = [])
return '' if node.nil?

Expand All @@ -61,9 +80,9 @@ def self.unparse_validate(node, comment_array = [])
validation = Validation.from_string(generated)

if validation.success?
MPrelude::Either::Right.new(generated)
Either::Right.new(generated)
else
MPrelude::Either::Left.new(validation)
Either::Left.new(validation)
end
end

Expand All @@ -75,8 +94,7 @@ def self.unparse_validate(node, comment_array = [])
#
# @return [Either<Exception, String>]
def self.unparse_either(node)
MPrelude::Either
.wrap_error(Exception) { unparse(node) }
Either.wrap_error(Exception) { unparse(node) }
end

# Parse string into AST
Expand All @@ -92,9 +110,9 @@ def self.parse(source)
#
# @param [String] source
#
# @return [MPrelude::Either<Parser::SyntaxError, (Parser::ASTNode, nil)>]
# @return [Either<Parser::SyntaxError, (Parser::ASTNode, nil)>]
def self.parse_either(source)
MPrelude::Either.wrap_error(Parser::SyntaxError) do
Either.wrap_error(Parser::SyntaxError) do
parser.parse(buffer(source))
end
end
Expand Down
Loading