-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a `Local Bear` for `Ruby`, wrapping `fasterer`. Closes #444
- Loading branch information
Showing
6 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from coalib.bearlib.abstractions.Linter import linter | ||
from dependency_management.requirements.GemRequirement import GemRequirement | ||
|
||
|
||
@linter(executable='fasterer', | ||
output_format='regex', | ||
output_regex=r'(?P<message>.*\.).*:\s(?P<line>\d+)') | ||
class RubyFastererBear: | ||
""" | ||
The ``RubyFastererBear`` will suggest some speed improvements which you | ||
can check in details at the <https://github.com/JuanitoFatas/fast-ruby>. | ||
It uses ``fasterer``. See <https://www.rubydoc.info/gems/fasterer/0.4.1> | ||
for more info. | ||
""" | ||
|
||
LANGUAGES = {'Ruby'} | ||
REQUIREMENTS = {GemRequirement('fasterer', '0.4.1')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Complexity'} | ||
SEE_MORE = 'https://github.com/DamirSvrtan/fasterer' | ||
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file): | ||
return filename, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import os | ||
from queue import Queue | ||
|
||
from coalib.results.Result import Result | ||
from coalib.settings.Section import Section | ||
from coalib.testing.BearTestHelper import generate_skip_decorator | ||
from coalib.testing.LocalBearTestHelper import LocalBearTestHelper | ||
|
||
from bears.ruby.RubyFastererBear import RubyFastererBear | ||
|
||
|
||
def get_testfile_path(name): | ||
return os.path.join(os.path.dirname(__file__), | ||
'fasterer_test_files', | ||
name) | ||
|
||
|
||
def load_testfile(name): | ||
with open(get_testfile_path(name)) as f: | ||
return f.readlines() | ||
|
||
|
||
@generate_skip_decorator(RubyFastererBear) | ||
class RubyFastererBearTest(LocalBearTestHelper): | ||
|
||
def setUp(self): | ||
self.uut = RubyFastererBear(Section('name'), Queue()) | ||
|
||
def test_module_eval_vs_define_method(self): | ||
filename = 'module_eval.rb' | ||
file_contents = load_testfile(filename) | ||
self.check_results( | ||
self.uut, | ||
file_contents, | ||
[Result.from_values('RubyFastererBear', | ||
message='Using module_eval is slower than ' | ||
'define_method.', | ||
file=get_testfile_path(filename), | ||
line=3)], | ||
filename=get_testfile_path(filename)) | ||
|
||
def test_sort_vs_sort_by(self): | ||
filename = 'sort_vs_sort_by.rb' | ||
file_contents = load_testfile(filename) | ||
self.check_results( | ||
self.uut, | ||
file_contents, | ||
[Result.from_values('RubyFastererBear', | ||
message='Enumerable#sort is slower than ' | ||
'Enumerable#sort_by.', | ||
file=get_testfile_path(filename), | ||
line=6)], | ||
filename=get_testfile_path(filename)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Hihi | ||
class << self | ||
module_eval %{ | ||
def hello | ||
puts "win" | ||
end | ||
} | ||
end | ||
end | ||
|
||
Hihi.hello | ||
|
||
Hihi.module_eval %{ | ||
puts @foo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
User = Struct.new(:name) | ||
ARRAY = Array.new(3) do | ||
User.new(sprintf("%010d"), rand(1_000_000_000)) | ||
end | ||
|
||
ARRAY.sort { |a, b| a.name <=> b.name } | ||
ARRAY.sort_by(&:name) | ||
|
||
ARRAY.sort |