Class: Chutney::InvalidFileName

Inherits:
Linter
  • Object
show all
Defined in:
lib/chutney/linter/invalid_file_name.rb

Overview

service class to lint for invalid file names

Instance Attribute Summary

Attributes inherited from Linter

#configuration, #filename, #issues

Instance Method Summary collapse

Methods inherited from Linter

#add_issue, #and_word?, #background, #background_word?, #but_word?, descendants, #dialect, #dialect_word, #elements, #examples_word?, #feature, #feature_word?, #filled_scenarios, #given_word?, #initialize, linter_name, #linter_name, #location, #off_switch?, #render_step, #render_step_argument, #scenario_outline_word?, #scenarios, #steps, #tags_for, #then_word?, #type, #when_word?

Constructor Details

This class inherits a constructor from Chutney::Linter

Instance Method Details

#lintObject



8
9
10
11
12
13
14
15
# File 'lib/chutney/linter/invalid_file_name.rb', line 8

def lint
  feature do |f|
    base = File.basename(filename, '.*')
    if base != base.downcase || base =~ /[ -]/
      add_issue(I18n.t('linters.invalid_file_name', recommended_name: recommend(filename)), f)
    end
  end
end

#recommend(filename) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/chutney/linter/invalid_file_name.rb', line 17

def recommend(filename)
  File.basename(filename, '.*').gsub('::', '/')
      .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
      .gsub(/([a-z\d])([A-Z])/, '\1_\2')
      .tr('-', '_')
      .tr(' ', '_')
      .downcase << '.feature'
end