Class: Hone::Patterns::Base
- Inherits:
-
Prism::Visitor
- Object
- Prism::Visitor
- Hone::Patterns::Base
- Defined in:
- lib/hone/patterns/base.rb
Direct Known Subclasses
ArrayCompact, ArrayIncludeSet, BlockToProc, BsearchVsFind, CharsMapOrd, CharsToVariable, ConstantRegexp, CountVsSize, Divmod, DynamicIvar, DynamicIvarGet, EachWithIndex, EachWithObject, FlattenOnce, GsubToTr, HashEachKey, HashEachValue, HashKeysInclude, HashMergeBang, HashValuesInclude, InjectSum, KernelLoop, LazyIvar, MapCompact, MapFlatten, MapSelectChain, ParallelAssignment, PositivePredicate, RangeInclude, RedundantStringChars, RegexpMatch, ReverseEach, ReverseFirst, SelectCount, SelectFirst, SelectMap, ShuffleFirst, SliceWithLength, SortByFirst, SortByLast, SortFirst, SortLast, SortReverse, StringCasecmp, StringCharsEach, StringConcatInLoop, StringDeletePrefix, StringDeleteSuffix, StringEmpty, StringEndWith, StringShovel, StringStartWith, TaintTrackingBase, TimesMap, UniqBy, YieldVsBlock
Class Attribute Summary collapse
-
.optimization_type ⇒ Object
Returns the value of attribute optimization_type.
-
.pattern_id ⇒ Object
Returns the value of attribute pattern_id.
- .scope ⇒ Object
Instance Attribute Summary collapse
-
#findings ⇒ Object
readonly
Returns the value of attribute findings.
Class Method Summary collapse
Instance Method Summary collapse
- #add_finding(node, message:, speedup: nil) ⇒ Object
-
#initialize(file_path) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(file_path) ⇒ Base
Returns a new instance of Base.
53 54 55 56 |
# File 'lib/hone/patterns/base.rb', line 53 def initialize(file_path) @file_path = file_path @findings = [] end |
Class Attribute Details
.optimization_type ⇒ Object
Returns the value of attribute optimization_type.
37 38 39 |
# File 'lib/hone/patterns/base.rb', line 37 def optimization_type @optimization_type end |
.pattern_id ⇒ Object
Returns the value of attribute pattern_id.
37 38 39 |
# File 'lib/hone/patterns/base.rb', line 37 def pattern_id @pattern_id end |
.scope ⇒ Object
39 40 41 |
# File 'lib/hone/patterns/base.rb', line 39 def scope @scope || :ruby end |
Instance Attribute Details
#findings ⇒ Object (readonly)
Returns the value of attribute findings.
58 59 60 |
# File 'lib/hone/patterns/base.rb', line 58 def findings @findings end |
Class Method Details
.inherited(subclass) ⇒ Object
33 34 35 |
# File 'lib/hone/patterns/base.rb', line 33 def self.inherited(subclass) Patterns.register(subclass) end |
.scan_file(path) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/hone/patterns/base.rb', line 46 def self.scan_file(path) result = Prism.parse_file(path) pattern = new(path) result.value.accept(pattern) pattern.findings end |
Instance Method Details
#add_finding(node, message:, speedup: nil) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/hone/patterns/base.rb', line 60 def add_finding(node, message:, speedup: nil) @findings << Finding.new( file: @file_path, line: node.location.start_line, column: node.location.start_column, pattern_id: self.class.pattern_id, optimization_type: self.class.optimization_type, source: :hone, message: , speedup: speedup, code: node.location.slice ) end |