Class: LearnLinter

Inherits:
Object
  • Object
show all
Defined in:
lib/learn-tool/learn-lint.rb

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ LearnLinter

Returns a new instance of LearnLinter.



2
3
4
5
# File 'lib/learn-tool/learn-lint.rb', line 2

def initialize(filepath)
    @learn_error = LearnError.new
    @filepath = filepath
end

Instance Method Details

#contributing_lintObject



48
49
50
51
52
53
54
# File 'lib/learn-tool/learn-lint.rb', line 48

def contributing_lint
  if self.has_file?("CONTRIBUTING.md")
    @learn_error.contributing_error[:present_contributing] = true
    @learn_error.present_contributing = {message: "present CONTRIBUTING.md", color: :green}
    ContributingLinter.parse_file("#{@filepath}/CONTRIBUTING.md", @learn_error)
  end
end

#has_file?(file) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/learn-tool/learn-lint.rb', line 11

def has_file?(file)
  Dir.entries(@filepath).include?(file) || Dir.entries(@filepath).include?(file.upcase) || Dir.entries(@filepath).include?(file.downcase)
end

#license_lintObject



32
33
34
35
36
37
38
# File 'lib/learn-tool/learn-lint.rb', line 32

def license_lint
  if self.has_file?("LICENSE.md")
    @learn_error.license_error[:present_license] = true
    @learn_error.present_license = {message: "present LICENSE.md", color: :green}
    LicenseLinter.parse_file("#{@filepath}/LICENSE.md", @learn_error)
  end
end

#lint_directoryObject



15
16
17
18
19
20
21
22
# File 'lib/learn-tool/learn-lint.rb', line 15

def lint_directory
  self.yaml_lint
  self.license_lint
  self.readme_lint
  self.contributing_lint
  @learn_error.result_output
  @learn_error.total_errors
end

#readme_lintObject



40
41
42
43
44
45
46
# File 'lib/learn-tool/learn-lint.rb', line 40

def readme_lint
  if self.has_file?("README.md")
    @learn_error.readme_error[:present_readme] = true
    @learn_error.present_readme = {message: "present README.md", color: :green}
    ReadmeLinter.parse_file("#{@filepath}/README.md", @learn_error)
  end
end

#result_messageObject



7
8
9
# File 'lib/learn-tool/learn-lint.rb', line 7

def result_message
  @learn_error.result_message
end

#yaml_lintObject



24
25
26
27
28
29
30
# File 'lib/learn-tool/learn-lint.rb', line 24

def yaml_lint
  if self.has_file?(".learn")
    @learn_error.yaml_error[:present_dotlearn] = true
    @learn_error.present_learn = {message: "present .learn file", color: :green}
    YamlLint.parse_file("#{@filepath}/.learn", @learn_error)
  end
end