Coder Social home page Coder Social logo

beautifyruby's People

Contributors

alkuzad avatar antoniomeireles avatar arvicco avatar benkoshy avatar cmer avatar craigwilliams avatar danryan avatar eka avatar holamendi avatar hongliang-goudou avatar jonathan-fantham avatar joshmckin avatar justinramel avatar lucianoshl avatar masal avatar pjfitzgibbons avatar printercu avatar stpn avatar thomasjachmann avatar tsaunya avatar zelig avatar zerocool4u2 avatar zhaoyk avatar zsand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beautifyruby's Issues

How do I configure the code cleanup rules?

I like to follow GitHub's ruby guidelines. So I'm curious how I change the rulesets for code cleanup

For example I'd like it to be formatted like this...

attr_accessible :id,
                :name
                :description

Not like this...

attr_accessible :id,
  :name
  :description

"Check your ruby interpreter settings" appears (Windows)

I've installed BeautifyRuby with Package Control for Sublime Text 3. I've changed my user settings to:
{
"ruby": "ruby"
}
But after trying to beautify a ruby file I get this error-message: "Check your ruby interpreter settings". What can I do with this?

Format on save results in saving content to wrong file

With mulitple files open, if you change one file but then mouse over another file while doing a save all, the changed file gets the content of the file that has mouse focus.

Only happens when format on save is true.

Fortunately I found this out on files checked into git:)

handling of '#

in our rspec suite, we have a lot of contexts like context "#cache_key" do

this works fine until you change double quotes to single quotes.

when using single quotes like context '#cache_key' do the next line does not get intended properly!

i tried to find the line for this in the plugin code, but there is so much stuff going on there...

beautifier chokes on regexes

If you have a regex like:

expression = /([0-9]*)/

The beautifier chokes and adds extra indents after it. You can work around this by commenting out the regex line, then beautifying, then uncommenting.

Does not beautify unsaved changes

When a file is edited but not yet saved, pressing the hotkey will try to beautify previous code.

This can lead to unintended consequencies if someone does not pay attention.

Sublime Text 3 - Carriage Return markers show on format

My line ending in SB3 are set to windows. When I run CTRL+ALT+K the formatting works fine but shows a CR at the end of every line. How do I get rid of the CR formatting mark showing up on every beautify_ruby command?

I have tried linux line endings as well and the same thing happens.

I am running windows 7, sublime text 3 and the latest BeautifyRuby gem.

Feature Request: Optionally allow tabs

Unless I missed something, beautifyruby converts tabs to spaces. It seems like if I used tabs, it would assume I considered them beautiful :) In any case, an option to disable this would be welcomed.

Interpreter settings not working

Hey,
I just installed the plugin on Sublime 3 via the package manager.

which ruby                                                                                                          
/usr/local/opt/ruby/bin/ruby

Then I went to preferences > package settings > beautify ruby > settings default but I'm not able to edit this file.
So I added

{
  "ruby": "/usr/local/opt/ruby/bin/ruby"
}

to the user settings of the package but when I try to use it I still get "check your ruby interpreter settings"

What am I doing wrong?

Special variable like $` causes mess

class A
  def foo
    "abc" =~ /\w+/
    puts $`
  end

  def bar
  end
end

After BeautifyRuby runs, it turns out to be:

class A
  def foo
    "abc" =~ /\w+/
    puts $`
  end

  def bar
      end    #### <---- wrong!
end

A temporary workaround is:

class A
  def foo
    "abc" =~ /\w+/
    puts $` #`    <------ workaround!
  end

  def bar
  end
end

Some other special ruby variables, such as $', $, $+, etc, would cause more serious problem than $`. They are not easy to workaround. So we need special treatment for these special variables.

beautifyRuby smashes here_docs

As a pity, BeautifyRuby does not leave here_docs untouched. This makes BeautifyRuby hard to use in this case.

Example:

module FOO
def foo
  config =<<-eos
### This file is  authorization file for #{@project_name}.
# do not remove * = at [/]

[groups]
observer=
developer=#{@project_admin_user}

[/]
@observer=r
@developer=rw
* = 
eos
end
end```

converts to

```ruby
module FOO
  def foo
    config =<<-eos
    ### This file is  authorization file for #{@project_name}.
    # do not remove * = at [/]

    [groups]
    observer=
      developer=#{@project_admin_user}

    [/]
@observer=r
@developer=rw
* = 
eos
end
end

or this example

template = %{
  <html>
    <head><title>Ruby Toys -- <%= @name %></title></head>
    <body>

      <h1><%= @name %> (<%= @code %>)</h1>
      <p><%= @desc %></p>

      <ul>
        <% @features.each do |f| %>
          <li><b><%= f %></b></li>
        <% end %>
      </ul>

      <p>
        <% if @cost < 10 %>
          <b>Only <%= @cost %>!!!</b>
        <% else %>
           Call for a price, today!
        <% end %>
      </p>

    </body>
  </html>
}.gsub(/^  /, '')

is converted to

template = %{
  <html>
  <head><title>Ruby Toys -- <%= @name %></title></head>
  <body>

  <h1><%= @name %> (<%= @code %>)</h1>
  <p><%= @desc %></p>

  <ul>
  <% @features.each do |f| %>
    <li><b><%= f %></b></li>
  <% end %>
  </ul>

  <p>
  <% if @cost < 10 %>
  <b>Only <%= @cost %>!!!</b>
  <% else %>
  Call for a price, today!
  <% end %>
  </p>

  </body>
  </html>
}.gsub(/^  /, '')

lost cursor after beautify ruby

Sublime Text 2 will lost cursor focus after beautify ruby. It's difficult to find last working line, especially when the file has lots of lines. I prefer the way that 'Reindent Lines' does.

No newline at end of file

When I run BeautifyRuby over a file, it does not place a new line character at the end of the file. It also removes any existing new line characters.

Beautify indents Comment Block

I added a comment block to a model definition and when i run beautify it indents the =begin part making the model definition not being commented out

Menu option

It would be REALLY nice if this provided a menu option, so you could get to it using Cmd+P. It's really unintuitive having to find a documentation page for a package to find out what the keyboard shortcut is when you install it from the Package Manager.

Great work though.

Sublime Text 3 support

Getting this:

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 382, in run_
    return self.run(edit)
  File "/Users/kain/Library/Application Support/Sublime Text 3/Packages/BeautifyRuby/beautify_ruby.py", line 21, in run
    self.update_view(self.beautify_buffer())
  File "/Users/kain/Library/Application Support/Sublime Text 3/Packages/BeautifyRuby/beautify_ruby.py", line 36, in beautify_buffer
    beautifier = subprocess.Popen(self.cmd(), shell=True, cwd=working_dir, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  File "/Users/kain/Library/Application Support/Sublime Text 3/Packages/BeautifyRuby/beautify_ruby.py", line 72, in cmd
    args = ["'" + unicode(path) + "'"]
NameError: global name 'unicode' is not defined

BeautifyRuby On Linux

The linux shortcut is missing, maybe adding a Default (Linux).sublime-keymap will help.

%x[cmd] is misaligned

Hi, great package! Although one issue, every time I write x%[] command and then beautify, code gets shifted one indent per each %x[] command..

Configure .erb vs .html.erb files

I have a few eruby files that end only with .erb and not .html.erb

How can i configure BeautifyRuby to check for the .erb files too?

Cannot find Rbenv interpreter

I used which ruby to find the best option for the ruby interpreter settings.

so for rbenv on Ubuntu its.

"ruby": "/home/sayth/.rbenv/shims/ruby",

However this still asks to check the interpreter. For Rbenv what should this be?

Incorrect indentation for until, while, and for

Here's what I'm getting: 4 spaces indent, instead of two:

      until first_section_number do
          current_line = Or.next_nonblank_line(lines: lines, start: current_line)
          aLine = lines[current_line].strip
          if aLine =~ /^([1-9]\w*\.[0-9]\w*)  +(.+)$/ then
            first_section_number = $1
            first_section_title  = $2.strip
          else
            if aLine =~ /^[^(].+[^)]$/ then # Not a sub-sub-chapter
              first_subchapter_name = aLine.titlecase
            end
          end
        end

I'm looking at the code to see how I'd fix this, if it's actually a bug.

block comments get indented

Hey, thanks for this awesome plugin!

If you have a ruby block comment:

=begin
yada yada yada
=end

it indents it to
=begin
...
=end

This breaks on most ruby 1.9.3s

the beautifier should not touch =begin and =end, they must remain totally left justified

Error in Python console

Running Beautify Ruby command always produces this error in ST2 Python console (ST2 Beta 2181, OSX 10.6.8):

Writing file /Users/vb/Library/Application Support/Sublime Text 2/Packages/BeautifyRuby/ruby/beautifier.rb with encoding UTF-8
 Exception in thread Thread-6:
 Traceback (most recent call last):
   File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 522, in __bootstrap_inner
     self.run()
   File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 477, in run
     self.__target(*self.__args, **self.__kwargs)
   File "./history.py", line 69, in run
 EOFError

Seems like there is some problem with child process that the command spawns (popen?). I have zero Python fu so no idea where to start fixing it...

Not beautifying on save

I installed BeautifyRuby on my Mac and everything works perfectly with the keyboard shortcut. I then opened my 'Setting - User' and added the line "run_on_save" : true, and restarted ST2, but it does not work. Did I configure it correctly? Did I put the config line in the wrong file? Any ideas?

Cursor moves to the start of the line

When you run on save set to true:

"run_on_save": true

Each time you save, the cursor jumps to the start of the line, like so:

beautify_ruby

Is there any way to maintain the cursor position?

Bad indentation on double quoted strings

Hello, and thanks for you work. It really useful.

Here's the indentation BR gives to me

    desc "blabla"
    task :blabla => :environment do
      filename_pattern = File.join(LOCAL_MERGE_FOLDER, "*.#{FILE_BASE_NAME}*.gz")
                                        Dir.glob(filename_pattern).sort.each do |filename|
                                          puts "Merging #{filename}"

and here's what it should be :

    desc "blabla"
    task :blabla => :environment do
      filename_pattern = File.join(LOCAL_MERGE_FOLDER, "*.#{FILE_BASE_NAME}*.gz")
      Dir.glob(filename_pattern).sort.each do |filename|
        puts "Merging #{filename}"

It seems to be related to the 'Dir.glob'.

BeautifyRuby doesn't seem to work...

After installation on sublime tekst 3 (manual installation), with ruby: ruby changed for windows, the command and keyboard shortcut do show up, but don't seem to do anything. No blank screen, no error. Is there a log file that I can consult? Any other ideas?

keeps indenting if a json hash formatted keyword is used

before_save   O.new("v"),
    if: Proc.new { |p| [154, 1217].include?(p.account_id) }
after_save    O.new("v"),
    if: Proc.new { |p| [154, 1217].include?(p.account_id) }
after_find    O.new("v"),
    if: Proc.new { |p| p.attributes.include?("v") && [154, 1217].include?(p.account_id) }

becomes:

before_save   O.new("v"),
if: Proc.new { |p| [154, 1217].include?(p.account_id) }
    after_save    O.new("v"),
    if: Proc.new { |p| [154, 1217].include?(p.account_id) }
        after_find    O.new("v"),
        if: Proc.new { |p| proposal.attributes.include?("v") && [154, 1217].include?(p.account_id) }

the top code block is correct.

I think it's seeing the "if" keywoard, and just auto-indenting the line without looking at what if is

a condition starting with if: isn't actually valid.

encoding support

should support encoding reading the first line, for example

encoding: UTF-8

if source have chars like Italians accent (for example: è à ù)
blank file

Formatter moves certain variables to column 0

class OrlandoDns < Dns

  attr_reader :srv_records

   DATA_CENTER = 'orl'

  def initialize
   @srv_records  =  parse_srv_records('orl')
    super
  end


  def to_inbound_orl
    sort_srv_records('orl')
  end
end

becomes

class OrlandoDns < Dns

  attr_reader :srv_records, :site

DATA_CENTER = 'orl'

  def initialize
@srv_records  =  parse_srv_records('orl')
    super
  end


  def to_inbound_orl
    sort_srv_records('orl')
  end
end

Notice now @srv_records and DATA_CENTER are on column 0, when they should be on column 4 and 2, respectfully

This is on STS3
-John

"Incorrect" formatting for "statement if x" expressions

The following code is formatted incorrectly (the if in line 5 is put as a new line)
Original code:

def _findLoginFormsByActions(doc)
    inputs=doc.xpath("//form").select { |n|
      bits=[]
      %w(action name).each {|x|
        bits << n[x].downcase if n[x]
          }
          bits.any? {|b|
            INTERESTING_WORDS.any? {|word| not (b.index word).nil? }
          }
    }
end

Formatted code:

def _findLoginFormsByActions(doc)
    inputs=doc.xpath("//form").select { |n|
      bits=[]
      %w(action name).each {|x|
        bits << n[x].downcase
        if n[x]
          }
          bits.any? {|b|
            INTERESTING_WORDS.any? {|word| not (b.index word).nil? }
          }
          }
        end

Add option to prevent deletion of empty lines

I would like to prevent the deleting of empty lines, especially in erb files its sometimes more comfortable to read parts if there are empty lines.

at the moment all empty lines are removed..

Could you maybe add an option?

thanks!

Formatting Multi line hash adds ridiculous indentation

Before

p = FactoryGirl.create(:content, {
                 user: @user,
                 account: @account,
                 category_id: c.id,
                 visibility: Shared::PUBLIC
            })

After

p = FactoryGirl.create(:content, {
                                                 user: @user,
                                                 account: @account,
                                                 category_id: c.id,
                                                 visibility: Shared::PUBLIC
})

Expected

p = FactoryGirl.create(:content, {
     user: @user,
     account: @account,
     category_id: c.id,
     visibility: Shared::PUBLIC
})

Is there a way to configure this? or is this a bug?

Can't format erb templates

When trying to beautify html.erb docs, I get the following error from Sublime Text:

check your ruby interpreter settings

I have the htmlbeautifier gem installed.

indention after calling private in class

i noticed today, that BeautifyRuby changed behavior for indention after calling private in a class.

unfortunately i can't say when this change appeared, but i think that this must be new somehow. i added a failing test for this: phoet@375d758

is it supposed to be that way?

Encoding error on OS X Mavericks

Under the new OS X Mavericks with Ruby 2.0.0-p247, while the ruby source file has unicode characters like Chinese words, rbeautify.rb Line 41 would raise an "invalid byte sequence in US-ASCII" exception:

41|    source.split("\n").each_with_index do |line_content, line_number|
42|      line = RBeautify::Line.new(language, line_content, line_number, block, use_tabs)
43|      dest += line.format + "\n"
44|      block = line.block
45|    end

The exception is raised by source.split("\n") because something weird happened to the source string and it's not a UTF-8 string. Workaround for this is either:

  1. Add something like source.force_encoding("UTF-8"). This should be safe because all the source string is delivered by Sublime python runtime and it uses subprocess.communicate(body.encode("UTF-8"))
  2. Change the BeautifyRuby.sublime-settings to something like this:
{
  "ruby": "/usr/bin/env ruby --encoding='utf-8'",
  // ...
}

Yes, force the ruby VM to cheat all strings as UTF-8.

Currently I can only use workaround 2 but I strongly suggest add a ```force_encoding``` call to the rbeautify.rb source code. Thanks.

rbenv

I use rbenv and can't seem to get this to work no matter what I configure the ruby path to be. Any suggestions?

$ which ruby
/Users/bhilkert/.rbenv/shims/ruby

Handle windows line endings

With windows line endings, I don't know exactly what happens but I get one line ending added on each line, so this script:

class PagesController < ApplicationController
  layout 'web_client'

  def home
    @event            = true # Max 1
    @news             = News.find(:all) # Max 3
    @books            = [1,2] # Max 2
    @events           = [1,2,3,4,5,6] # Max 6
    @initiatives      = [1,2,3] # Max 3
    @videos           = [1,2,3] # Max 3 [1, 2, 3]
    @suggested_links  = [1,2,3,4] # Max 4

    respond_to do |format|
      format.html { render } # index.html.erb
    end
  end

  def about
  end

  def contacts
  end
end

becomes this:

class PagesController < ApplicationController

  layout 'web_client'



  def home

    @event            = true # Max 1

    @news             = News.find(:all) # Max 3

    @books            = [1,2] # Max 2

    @events           = [1,2,3,4,5,6] # Max 6

    @initiatives      = [1,2,3] # Max 3

    @videos           = [1,2,3] # Max 3 [1, 2, 3]

    @suggested_links  = [1,2,3,4] # Max 4



    respond_to do |format|

      format.html { render } # index.html.erb

    end

  end



  def about

  end



  def contacts

  end

end

Very boring

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.