def lint_files(files = nil, inline_mode: false, fail_on_error: false, additional_swiftlint_args: '', no_comment: false, &select_block)
      # Fails if swiftlint isn't installed
      raise 'swiftlint is not installed' unless swiftlint.installed?

      config_file_path = if config_file
                           config_file
                         elsif File.file?('.swiftlint.yml')
                           File.expand_path('.swiftlint.yml')
                         end
      log "Using config file: #{config_file_path}"

      dir_selected = directory ? File.expand_path(directory) : Dir.pwd
      log "Swiftlint will be run from #{dir_selected}"

      # Get config
      config = load_config(config_file_path)

      # Extract excluded paths
      excluded_paths = format_paths(config['excluded'] || [], config_file_path)

      log "Swiftlint will exclude the following paths: #{excluded_paths}"

      # Extract included paths
      included_paths = format_paths(config['included'] || [], config_file_path)

      log "Swiftlint includes the following paths: #{included_paths}"

      # Extract swift files (ignoring excluded ones)
      files = find_swift_files(dir_selected, files, excluded_paths, included_paths)
      log "Swiftlint will lint the following files: #{files.join(', ')}"

      # Prepare swiftlint options
      options = {
        # Make sure we don't fail when config path has spaces
        config: config_file_path ? Shellwords.escape(config_file_path) : nil,
        reporter: 'json',
        quiet: true,
        pwd: dir_selected,
        force_exclude: true
      }
      log "linting with options: #{options}"

      # Lint each file and collect the results
      issues = run_swiftlint(files, lint_all_files, options, additional_swiftlint_args)
      @issues = issues
      other_issues_count = 0
      unless @max_num_violations.nil? || no_comment
        other_issues_count = issues.count - @max_num_violations if issues.count > @max_num_violations
        issues = issues.take(@max_num_violations)
      end
      log "Received from Swiftlint: #{issues}"
      
      # filter out any unwanted violations with the passed in select_block
      if select_block && !no_comment
        issues = issues.select { |issue| select_block.call(issue) }
      end

      # Filter warnings and errors
      @warnings = issues.select { |issue| issue['severity'] == 'Warning' }
      @errors = issues.select { |issue| issue['severity'] == 'Error' }
      
      # Early exit so we don't comment
      return if no_comment

      if inline_mode
        # Report with inline comment
        send_inline_comment(warnings, strict ? :fail : :warn)
        send_inline_comment(errors, (fail_on_error || strict) ? :fail : :warn)
        warn other_issues_message(other_issues_count) if other_issues_count > 0
      elsif warnings.count > 0 || errors.count > 0
        # Report if any warning or error
        message = "### SwiftLint found issues\n\n".dup
        message << markdown_issues(warnings, 'Warnings') unless warnings.empty?
        message << markdown_issues(errors, 'Errors') unless errors.empty?
        message << "\n#{other_issues_message(other_issues_count)}" if other_issues_count > 0
        markdown message

        # Fail danger on errors
        should_fail_by_errors = fail_on_error && errors.count > 0
        # Fail danger if any warnings or errors and we are strict
        should_fail_by_strict = strict && (errors.count > 0 || warnings.count > 0)
        if should_fail_by_errors || should_fail_by_strict
          fail 'Failed due to SwiftLint errors'
        end
      end
    end
def lint_files(files = nil, inline_mode: false, fail_on_error: false, additional_swiftlint_args: '', no_comment: false, &select_block)
      # Fails if swiftlint isn't installed
      raise 'swiftlint is not installed' unless swiftlint.installed?

      config_file_path = if config_file
                           config_file
                         elsif File.file?('.swiftlint.yml')
                           File.expand_path('.swiftlint.yml')
                         end
      log "Using config file: #{config_file_path}"

      dir_selected = directory ? File.expand_path(directory) : Dir.pwd
      log "Swiftlint will be run from #{dir_selected}"

      # Get config
      config = load_config(config_file_path)

      # Extract excluded paths
      excluded_paths = format_paths(config['excluded'] || [], config_file_path)

      log "Swiftlint will exclude the following paths: #{excluded_paths}"

      # Extract included paths
      included_paths = format_paths(config['included'] || [], config_file_path)

      log "Swiftlint includes the following paths: #{included_paths}"

      # Extract swift files (ignoring excluded ones)
      files = find_swift_files(dir_selected, files, excluded_paths, included_paths)
      log "Swiftlint will lint the following files: #{files.join(', ')}"

      # Prepare swiftlint options
      options = {
        # Make sure we don't fail when config path has spaces
        config: config_file_path ? Shellwords.escape(config_file_path) : nil,
        reporter: 'json',
        quiet: true,
        pwd: dir_selected,
        force_exclude: true
      }
      log "linting with options: #{options}"

      # Lint each file and collect the results
      issues = run_swiftlint(files, lint_all_files, options, additional_swiftlint_args)
      @issues = issues
      other_issues_count = 0
      unless @max_num_violations.nil? || no_comment
        other_issues_count = issues.count - @max_num_violations if issues.count > @max_num_violations
        issues = issues.take(@max_num_violations)
      end
      log "Received from Swiftlint: #{issues}"
      
      # filter out any unwanted violations with the passed in select_block
      if select_block && !no_comment
        issues = issues.select { |issue| select_block.call(issue) }
      end

      # Filter warnings and errors
      @warnings = issues.select { |issue| issue['severity'] == 'Warning' }
      @errors = issues.select { |issue| issue['severity'] == 'Error' }
      
      # Early exit so we don't comment
      return if no_comment

      if inline_mode
        # Report with inline comment
        send_inline_comment(warnings, strict ? :fail : :warn)
        send_inline_comment(errors, (fail_on_error || strict) ? :fail : :warn)
        warn other_issues_message(other_issues_count) if other_issues_count > 0
      elsif warnings.count > 0 || errors.count > 0
        # Report if any warning or error
        message = "### SwiftLint found issues\n\n".dup
        message << markdown_issues(warnings, 'Warnings') unless warnings.empty?
        message << markdown_issues(errors, 'Errors') unless errors.empty?
        message << "\n#{other_issues_message(other_issues_count)}" if other_issues_count > 0
        markdown message

        # Fail danger on errors
        should_fail_by_errors = fail_on_error && errors.count > 0
        # Fail danger if any warnings or errors and we are strict
        should_fail_by_strict = strict && (errors.count > 0 || warnings.count > 0)
        if should_fail_by_errors || should_fail_by_strict
          fail 'Failed due to SwiftLint errors'
        end
      end
    end
Lints Swift files. Will fail if `swiftlint` cannot be installed correctly.
 Generates a `markdown` list of warnings for the prose in a corpus of
 .markdown and .md files.

 @param   [String] files
          A globbed string which should return the files that you want to
          lint, defaults to nil.
          if nil, modified and added files from the diff will be used.
 @return  [void]