Class: DocktorRails::Checks::ShellScriptsCrlf

Inherits:
BaseCheck
  • Object
show all
Defined in:
lib/docktor_rails/checks/shell_scripts_crlf.rb

Constant Summary collapse

DEFAULT_IGNORES =
[
  "/.git/",
  "/node_modules/",
  "/vendor/",
  "/tmp/",
  "/log/"
].freeze

Instance Method Summary collapse

Methods inherited from BaseCheck

#name

Instance Method Details

#idObject



16
17
18
# File 'lib/docktor_rails/checks/shell_scripts_crlf.rb', line 16

def id
  "fs.shell_crlf"
end

#run(ctx) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/docktor_rails/checks/shell_scripts_crlf.rb', line 20

def run(ctx)
  root = ctx.fetch(:root)
  offenders = []

  Dir.glob(File.join(root, "**", "*.sh"), File::FNM_DOTMATCH).each do |path|
    next unless File.file?(path)
    next if ignored?(path)

    offenders << rel(path, root) if File.binread(path).include?("\r\n")
  end

  if offenders.empty?
    pass("No CRLF line endings in .sh files")
  else
    fail(
      "CRLF line endings found in shell scripts",
      files: offenders.sort,
      hint: "Convert to LF (e.g. with git) and enforce via .gitattributes: *.sh text eol=lf"
    )
  end
end