Class: Hephaestus::Actions::StripCommentsAction::StripLeadingScopeNewlines

Inherits:
Object
  • Object
show all
Defined in:
lib/hephaestus/actions/strip_comments_action.rb

Overview

The intent of this class is purely aesthetic: remove leading newlines inside of code scopes like blocks and begin/end. Example input:

module MyGem

  MyGem.application.configure do |config|

    config.option1 = true

    config.option2 = false
  end
end

The output is:

module MyGem
  MyGem.application.configure do |config|
    config.option1 = true

    config.option2 = false
  end
end

Defined Under Namespace

Classes: LeadingNewlineStripRewriter

Class Method Summary collapse

Class Method Details

.call(source, parser) ⇒ Object



148
149
150
151
152
153
# File 'lib/hephaestus/actions/strip_comments_action.rb', line 148

def call(source, parser)
  buffer = Parser::Source::Buffer.new(nil, source: source)
  ast = parser.parse(buffer)

  LeadingNewlineStripRewriter.new.rewrite(buffer, ast).lstrip
end