Friday 16 November 2012

RLint 1.0

Hi folks, Today, I'll show to you the progress from my little tool called RLint. E.G, I have a test code and I need check if it's following my coding standards. Setting up this configuration (Today hardcoded, but in release version the configuration will be through config file): Tabulation - Tabs, size 4 Class Name - Camel case Column Delimiter - 80 If Bracket - No Source code - teste.rb
class AV
end

class AudioVideo
  def method_column_delimiter_80
    "String really loooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnggggggggggggggggggggggggggg"
  end

  def method_no_bracket
    if(abc)

    end

    if abc

    end
  end
end

When running rlint.rb, I get this output (Alright, the error messages are really useless or confused, however, I know it needs improvement):
rodrigo@:~/RubyProjects/rlint$ ruby rlint.rb teste.rb
Tabulation report:
Correct: 5
Error: 13

You need review this lines:
Detected a indentation mistake.
> teste.rb - 6:   def method_foo
Detected a whitespace indentation.
> teste.rb - 6:   def method_foo
Detected a whitespace indentation.
> teste.rb - 7:     "String really loooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnggggggggggggggggggggggggggg"
Detected a indentation mistake.
> teste.rb - 8:   end
Detected a whitespace indentation.
> teste.rb - 8:   end
Detected a indentation mistake.
> teste.rb - 10:   def method_xxx
Detected a whitespace indentation.
> teste.rb - 10:   def method_xxx
Detected a whitespace indentation.
> teste.rb - 11:     if(abc)
Detected a whitespace indentation.
> teste.rb - 13:     end
Detected a whitespace indentation.
> teste.rb - 15:     if abc
Detected a whitespace indentation.
> teste.rb - 17:     end
Detected a indentation mistake.
> teste.rb - 18:   end
Detected a whitespace indentation.
> teste.rb - 18:   end


Class/Module name report:
Correct: 1
Error: 1

You need review this lines:
Detected a class name mistake. Possible Snake Case
> teste.rb - 2: class AV


If parenthesis report:
Correct: 1
Error: 1

You need review this lines:
Detected a configuration mismatch for bracket usage.
> teste.rb - 11:     if(abc)


Column Delimiter report:
Correct: 19
Error: 1

You need review this lines:
Detected a word across the delimiter.
> teste.rb - 7:     "String really loooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnggggggggggggggggggggggggggg"
I'm think so it's really delighted, if you have a program that help check your coding standards.

Thursday 1 November 2012

RLint is coming

Hi folks,

Finally, I get back to develop RLint, because I'm really excited with RHash amount of download (3777). Besides, I felt a emptiness about a tool could help detect code pattern mistakes. I've seen in Python a software amazing, the Pylint. Furthermore I think I can use this tool in own projects and share with Ruby community.

First features:
- Tabulator check (Space vs Tabs)
- Class/Module name (CamelBack vs Snake)
- If/Unless parenthesis check - Column delimiter
- Class/Module/Method size (Total of line)
- Method parenthesis check That's it.

If someone have a good idea for feature, tell me.
Let's start the ball rolling.

Tuesday 30 October 2012

Adding object dinamically to a class.

Ruby's a great programming language everybody know. The breakthrough in Ruby is adding objects dynamically in a class, it's really amazing. Why? It's possible to create a simple interface with high complexity. For example, it's really viable create a car only adding parts in the object. How did you do this? Using 'self.class.send(:define_method, name, &block)'. This code will add a instance method (name) and code method (&block). Actually, if you pass a object via &block, your new method will behave like a object and your master class will be clean and it don't need implement nothing. I'm not quite sure about design pattern name, although I like this. Example:
class Car 
 def add_wheel(wheel)
  add_object("wheel"){wheel}
 end 
 
 def add_part(name, obj)
  add_object(name){obj}
 end 
 
 private
 
 def add_object(name, &block)
  self.class.send(:define_method, name, &block)
 end   
end

class Wheel
 def initialize(size)
  @size = size
 end 
 
 def size
  puts "Wheel size #{@size}"
 end 
end 

class CarPaint
 def initialize(colour)
  @colour = colour
 end 
 
 def is_metallic_color?
  true
 end
 
 def colour
  puts "Colour #{@colour}"
 end
end 

my_car = Car.new
my_car.add_wheel(Wheel.new(17))

my_car.wheel.size
my_car.add_part("colour", CarPaint.new("red"))

puts my_car.colour.is_metallic_color?
my_car.colour.colour

Monday 3 January 2011

Rlint 0.0.1 Released

After several days looking for a tool like Pylint, I had a idea, create this gem.
This is a basic version, but along months, i will improve Rlint.

Monday 19 July 2010

Freeze Gems 0.0.2 Released

Freeze Gems foi desenvolvido com o intuito de auxiliar a instalação de gems entre computadores diferentes.
O computador com as gems que se deseja replicar nas outras máquinas, gera um arquivo .yaml, listando todas as gems que vão ser instaladas.
Já no computador que se deseja instalar as gems é necessário somente fazer a leitura do arquivo.

Freeze Gems was developed with the intention of assisting the installation of gems among different computers.
The computer with the gems that want to replicate on other machines, generates a yaml file, listing all the gems that will be installed.
In the computer you want to install the gems, you only need to read the yaml file.


Exemplo/Example:
Computer A
gem list
computer_a@desktop:$ gem list
a (0.0.1)
b (0.1.0)
c (0.1.1)
computer_a@desktop:$ freeze -c mygems
Cria no diretória atual um arquivo com nome mygems.yaml listando todas as gems.
It creates in the current path a file named mygems.yaml listing all gems.

Computer B
computer_a@desktop:$ gem list

computer_a@desktop:$ freeze -f mygems.yaml --install

RHash 0.0.6 Released

Fix: Two bugs solved.
New: Method to_yaml used for create file .yaml