Class: ERBLint::CLI
- Inherits:
-
Object
- Object
- ERBLint::CLI
- Includes:
- Utils::SeverityLevels
- Defined in:
- lib/erb_lint/cli.rb
Defined Under Namespace
Classes: ExitWithFailure, ExitWithSuccess
Constant Summary collapse
- DEFAULT_CONFIG_FILENAME =
".erb-lint.yml"
- DEFAULT_LINT_ALL_GLOB =
"**/*.html{+*,}.erb"
Constants included from Utils::SeverityLevels
Utils::SeverityLevels::SEVERITY_CODE_TABLE, Utils::SeverityLevels::SEVERITY_NAMES
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #run(args = ARGV) ⇒ Object
Methods included from Utils::SeverityLevels
Constructor Details
Instance Method Details
#run(args = ARGV) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/erb_lint/cli.rb', line 30 def run(args = ARGV) dupped_args = args.dup (dupped_args) if cache? && autocorrect? failure!("cannot run autocorrect mode with cache") end @files = @options[:stdin] || dupped_args load_config cache_dir = @options[:cache_dir] @cache = Cache.new(@config, cache_dir) if cache? || clear_cache? if clear_cache? if cache.cache_dir_exists? cache.clear success!("cache directory cleared") else failure!("cache directory doesn't exist, skipping deletion.") end end if !@files.empty? && lint_files.empty? if allow_no_files? success!("no files found...\n") else failure!("no files found...\n") end elsif lint_files.empty? failure!("no files found or given, specify files or config...\n#{option_parser}") end ensure_files_exist(lint_files) if enabled_linter_classes.empty? failure!("no linter available with current configuration") end @options[:format] ||= :multiline @options[:fail_level] ||= severity_level_for_name(:refactor) @options[:disable_inline_configs] ||= false @stats.files = lint_files.size @stats.linters = enabled_linter_classes.size @stats.autocorrectable_linters = enabled_linter_classes.count(&:support_autocorrect?) reporter = Reporter.create_reporter(@options[:format], @stats, autocorrect?) reporter.preview runner = ERBLint::Runner.new(file_loader, @config, @options[:disable_inline_configs]) file_content = nil lint_files.each do |filename| runner.clear_offenses begin file_content = run_on_file(runner, filename) rescue => e @stats.exceptions += 1 puts "Exception occurred when processing: #{relative_filename(filename)}" puts "If this file cannot be processed by erb-lint, "\ "you can exclude it in your configuration file." puts e. puts Rainbow(e.backtrace.join("\n")).red puts end end cache&.close reporter.show if stdin? && autocorrect? # When running from stdin, we only lint a single file puts "================ #{lint_files.first} ==================\n" puts file_content end @stats.found == 0 && @stats.exceptions == 0 rescue OptionParser::InvalidOption, OptionParser::InvalidArgument, ExitWithFailure => e warn(Rainbow(e.).red) false rescue ExitWithSuccess => e puts e. true rescue => e warn(Rainbow("#{e.class}: #{e.}\n#{e.backtrace.join("\n")}").red) false end |