code: def report_pyflakes(document):
      
      # Run pyflakes on input.
      reporter = _FlakesReporter()
      pyflakes.api.check(document.text, '', reporter=reporter)
  
      def format_flake_message(message):
          return [
              ('class:flakemessage.prefix', 'pyflakes:'),
              ('', ' '),
              ('class:flakemessage', message.message % message.message_args)
          ]
  
      def message_to_reporter_error(message):
          """ Turn pyflakes message into ReporterError. """
          start_index = document.translate_row_col_to_index(message.lineno - 1, message.col)
          end_index = start_index
          while end_index < len(document.text) and document.text[end_index] in WORD_CHARACTERS:
              end_index += 1
  
          return ReporterError(lineno=message.lineno - 1,
                               start_column=message.col,
                               end_column=message.col + end_index - start_index,
                               formatted_text=format_flake_message(message))
  
      # Construct list of ReporterError instances.
      return [message_to_reporter_error(m) for m in reporter.messages]
docs: Run pyflakes on document and return list of ReporterError instances.