Class: StoryboardLint::Linter

Inherits:
Object
  • Object
show all
Defined in:
lib/storyboardlint.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sb_scanner, source_scanner) ⇒ Linter

Returns a new instance of Linter.



144
145
146
147
# File 'lib/storyboardlint.rb', line 144

def initialize(sb_scanner, source_scanner)
  @sb_scanner = sb_scanner
  @source_scanner = source_scanner
end

Class Method Details

.run!(*args) ⇒ Object



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/storyboardlint.rb', line 203

def self.run!(*args)
  puts "StoryboardLint"
  puts "by Johannes Fahrenkrug, @jfahrenkrug, springenwerk.com"
  puts

  if args.size < 1
    puts "Usage: storyboardlint <target directory>"
    exit
  end

  sb_scanner = StoryboardLint::StoryboardScanner.new(ARGV[0])
  source_scanner = StoryboardLint::SourceScanner.new(ARGV[0])

  linter = StoryboardLint::Linter.new(sb_scanner, source_scanner)
  linter.lint
  
  return 0
end

Instance Method Details

#check_custom_classesObject



175
176
177
178
179
180
181
# File 'lib/storyboardlint.rb', line 175

def check_custom_classes
  @sb_scanner.custom_class_names.each do |custom_class|
    if !@source_scanner.class_names.map {|cn| cn[:class_name]}.include?(custom_class[:class_name])
      puts "error: Custom class '#{custom_class[:class_name]}' used in #{File.basename(custom_class[:file])} could not be found in source code."    
    end
  end
end

#check_idsObject



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/storyboardlint.rb', line 183

def check_ids
  @source_scanner.segue_ids.each do |seg_id|
    if !@sb_scanner.segue_ids.map {|sb_seg_id| sb_seg_id[:id]}.include?(seg_id[:id])
      puts "#{seg_id[:file]}:#{seg_id[:line]}: warning: Segue ID '#{seg_id[:id]}' could not be found in any Storyboard."    
    end
  end
  
  @source_scanner.storyboard_ids.each do |sb_id|
    if !@sb_scanner.storyboard_ids.map {|sb_sb_id| sb_sb_id[:id]}.include?(sb_id[:id])
      puts "#{sb_id[:file]}:#{sb_id[:line]}: warning: Storyboard ID '#{sb_id[:id]}' could not be found in any Storyboard."    
    end
  end
  
  @source_scanner.reuse_ids.each do |ru_id|
    if !@sb_scanner.reuse_ids.map {|sb_ru_id| sb_ru_id[:id]}.include?(ru_id[:id])
      puts "#{ru_id[:file]}:#{ru_id[:line]}: warning: Reuse ID '#{ru_id[:id]}' could not be found in any Storyboard."    
    end
  end
end

#check_namingObject



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/storyboardlint.rb', line 155

def check_naming
  @sb_scanner.segue_ids.each do |seg_id|
    if seg_id[:id] !~ /$#{SEGUE_ID_PREFIX}/
      puts "warning: Segue ID '#{seg_id[:id]}' used in #{File.basename(seg_id[:file])} does not start with '#{SEGUE_ID_PREFIX}' prefix."
    end
  end
  
  @sb_scanner.storyboard_ids.each do |sb_id|
    if sb_id[:id] !~ /$#{STORYBOARD_ID_PREFIX}/
      puts "warning: Storyboard ID '#{sb_id[:id]}' used in #{File.basename(sb_id[:file])} does not start with '#{STORYBOARD_ID_PREFIX}' prefix."
    end
  end
  
  @sb_scanner.reuse_ids.each do |ru_id|
    if ru_id[:id] !~ /$#{REUSE_ID_PREFIX}/
      puts "warning: Reuse ID '#{ru_id[:id]}' used in #{File.basename(ru_id[:file])} does not start with '#{REUSE_ID_PREFIX}' prefix."
    end
  end
end

#lintObject



149
150
151
152
153
# File 'lib/storyboardlint.rb', line 149

def lint
 check_naming
 check_custom_classes
 check_ids
end