-
Notifications
You must be signed in to change notification settings - Fork 0
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
Adapter for gems #1
Comments
So here is a simple script for reek: require 'reek'
file = File.read 'filename.rb'
examiner = Reek::Examiner.new file
examiner.smells.each do |smell|
puts "#{smell.class}\t#{smell.subclass}\t#{smell.message}\t#{smell.location['context']}\t#{smell.location['lines']}"
end For each smell the most important params are:
Seems like we need not only write adapters but aggregate all the codesmells from all gems to add refactor_url to each of them. These codesmells will be hardcoded in our gem, lets call it cc-middleman 😄 |
@makaroni4 Awesome! Could you please provide an example of param values? |
classes: subclasses: messages: location context (location lines is just array of integers): |
Seems like we don't need class because it is always Reek::SmellWarning |
So I see the list of params like this: Codesmell:
|
Here is brakeman json output: https://www.refheap.com/paste/701a97d125f5bab90e3c96198 All this information could be also extracted using the following ruby script: require 'brakeman'
require 'brakeman/scanner'
options = Brakeman.set_options app_path: '../brakeman/test/apps/rails3.2'
scanner = Brakeman::Scanner.new options
tracker = scanner.process
tracker.run_checks
%w(model_warnings controller_warnings template_warnings warnings).each do |type|
tracker.checks.send(type).each do |warning|
p warning.check
p warning.confidence
puts "#{warning.file}:#{warning.line}"
p warning.class
p warning.method
p warning.warning_set
p warning.warning_type
p warning.called_from
p warning.template
end
end PS. I don't like brakeman codebase – it smells a lot for me. I'd consider using standard json output and sending it to our app as is. In that case our app will be responsible to extract useful info from json and save it to the database. |
Here is how we can use flog require 'flog'
flogger = Flog.new(all: true, parser: Ruby19Parser)
flogger.flog 'filename.rb'
flogger.each_by_score do |method, score, call_list|
puts "#{method} => #{score.round(2)}"
end Script's output looks like
where
{
"Flog#flog"=>{:assignment=>8.100000000000001, :expand_dirs_to_files=>1.1, :branch=>12.000000000000004, :each=>1.1, :===>1.4000000000000004, :read=>1.5000000000000004, :binread=>1.5000000000000004, :option=>5.100000000000001, :[]=>4.500000000000002, :warn=>12.200000000000005, :new=>1.4000000000000006, :process=>2.9000000000000012, :mass=>2.800000000000001, :inspect=>3.1000000000000014, :backtrace=>4.200000000000001, :lit_fixnum=>1.0500000000000003, :first=>3.800000000000001, :join=>3.4000000000000012, :raise=>1.7000000000000008, :class=>1.7000000000000006, :message=>1.9000000000000006, :strip=>1.7000000000000006},
"Flog::parse_options"=>{:assignment=>21.300000000000004, :branch=>25.400000000000002, :new=>1.3, :separator=>3.0000000000000004, :on=>19.500000000000004, :puts=>1.7000000000000004, :exit=>1.7000000000000004, :each=>3.1000000000000005, :<<=>1.7000000000000004, :plugins=>1.7000000000000002, :empty?=>1.5000000000000002, :methods=>1.9000000000000001, :grep=>1.7000000000000002, :-=>1.5000000000000002, :sort=>1.7000000000000002, :send=>4.800000000000001, :Array=>1.3, :parse!=>1.1},
"Flog::load_plugins"=>{:assignment=>9.8, :branch=>10.900000000000002, :find_files=>1.5, :reverse=>1.3, :each=>3.3000000000000003, :basename=>1.4000000000000001, :intern=>1.2000000000000002, :[]=>1.3000000000000003, :warn=>4.300000000000001, :load=>1.5000000000000004, :inspect=>1.6000000000000003, :message=>1.6000000000000003, :plugins=>1.3, :merge=>1.1, :constants=>1.5, :map=>1.3, :to_s=>1.4000000000000001, :reject=>1.1, :const_get=>1.3000000000000003, :====>1.3000000000000003},
"Flog#none"=>{:lit_fixnum=>11.799999999999994, :new=>1.1, :merge!=>3.3000000000000003, :attr_accessor=>1.1, :attr_reader=>2.2, :alias=>13.200000000000006},
"Flog#report"=>{:assignment=>2.300000000000001, :total=>3.1000000000000014, :%=>2.800000000000001, :puts=>2.4000000000000012, :average=>1.6000000000000005, :branch=>3.600000000000002, :option=>4.200000000000002, :[]=>3.600000000000002, :*=>1.3000000000000007, :output_details_grouped=>1.3000000000000007, :output_details=>1.3000000000000007, :reset=>1.1000000000000005},
"main#none"=>{:require=>5.5}
} that shows why each method so complex. |
rails bpoutputs YAML file looks like: - !ruby/object:RailsBestPractices::Core::Error
filename: ./app/helpers/comment_helper.rb
line_number: '6'
message: not use time_ago_in_words
type: RailsBestPractices::Reviews::NotUseTimeAgoInWordsReview
url: http://rails-bestpractices.com/posts/105-not-use-time_ago_in_words
git_commit:
git_username:
hg_commit:
hg_username: also railsbp has a config file: AddModelVirtualAttributeCheck: { }
AlwaysAddDbIndexCheck: { }
DryBundlerInCapistranoCheck: { }
#HashSyntaxCheck: { }
IsolateSeedDataCheck: { }
KeepFindersOnTheirOwnModelCheck: { }
LawOfDemeterCheck: { }
#LongLineCheck: { max_line_length: 80 }
MoveCodeIntoControllerCheck: { }
MoveCodeIntoHelperCheck: { array_count: 3 }
MoveCodeIntoModelCheck: { use_count: 2 }
MoveFinderToNamedScopeCheck: { }
MoveModelLogicIntoModelCheck: { use_count: 4 }
NeedlessDeepNestingCheck: { nested_count: 2 }
NotRescueExceptionCheck: { }
NotUseDefaultRouteCheck: { }
NotUseTimeAgoInWordsCheck: {}
OveruseRouteCustomizationsCheck: { customize_count: 3 }
ProtectMassAssignmentCheck: {}
RemoveEmptyHelpersCheck: {}
#RemoveTabCheck: {}
RemoveTrailingWhitespaceCheck: { }
RemoveUnusedMethodsInControllersCheck: { except_methods: [] }
RemoveUnusedMethodsInHelpersCheck: { except_methods: [] }
RemoveUnusedMethodsInModelsCheck: { except_methods: [] }
ReplaceComplexCreationWithFactoryMethodCheck: { attribute_assignment_count: 2 }
ReplaceInstanceVariableWithLocalVariableCheck: { }
RestrictAutoGeneratedRoutesCheck: { }
SimplifyRenderInControllersCheck: {}
SimplifyRenderInViewsCheck: {}
#UseBeforeFilterCheck: { customize_count: 2 }
UseModelAssociationCheck: { }
UseMultipartAlternativeAsContentTypeOfEmailCheck: {}
UseObserverCheck: { }
#UseParenthesesInMethodDefCheck: {}
UseQueryAttributeCheck: { }
UseSayWithTimeInMigrationsCheck: { }
UseScopeAccessCheck: { } |
brakeman @lest
flay/flog @Proghat
railsbp @releu
reek @makaroni4
The text was updated successfully, but these errors were encountered: