<commit_before>/* @flow */

import { CompositeDisposable, Emitter } from 'sb-event-kit'
import type { Disposable } from 'sb-event-kit'
import { sortMessages } from './helpers'
import type { Message, MessageLegacy } from './types'

export default class Commands {
  emitter: Emitter;
  subscriptions: CompositeDisposable;

  constructor() {
    this.emitter = new Emitter()
    this.subscriptions = new CompositeDisposable()

    this.subscriptions.add(this.emitter)
    this.subscriptions.add(atom.commands.add('atom-text-editor:not([mini])', {
      'linter-ui-default:next-error': () => this.move(true),
      'linter-ui-default:previous-error': () => this.move(),
    }))
  }
  move(forward: boolean = false) {
    const messages = sortMessages(this.requestMessages())
    const expectedValue = forward ? -1 : 1
    const currentPosition = atom.workspace.getActiveTextEditor().getCursorBufferPosition()
    if (!forward) {
      messages.reverse()
    }
    for (let i = 0, length = messages.length, message; i < length; i++) {
      message = messages[i]
      const messageFile = message.version === 1 ? message.filePath : message.location.file
      const messageRange = message.version === 1 ? message.range : message.location.position
      console.log('messageRange', messageRange)
      if (messageRange && currentPosition.compare(messageRange.start) === expectedValue) {
        atom.workspace.open(messageFile, { searchAllPanes: true }).then(function() {
          const textEditor = atom.workspace.getActiveTextEditor()
          if (textEditor && textEditor.getPath() === messageFile) {
            textEditor.setCursorBufferPosition(messageRange.start)
          }
        })
        break
      }
    }
  }
  requestMessages(): Array<Message | MessageLegacy> {
    const filePath = atom.workspace.getActiveTextEditor().getPath()
    const event = { messages: [], filePath }
    this.emitter.emit('should-provide-messages', event)
    return event.messages
  }
  onShouldProvideMessages(callback: Function): Disposable {
    return this.emitter.on('should-provide-messages', callback)
  }
  dispose() {
    this.subscriptions.dispose()
  }
}<commit_msg>:fire: Remove a console.log<commit_after>/* @flow */

import { CompositeDisposable, Emitter } from 'sb-event-kit'
import type { Disposable } from 'sb-event-kit'
import { sortMessages } from './helpers'
import type { Message, MessageLegacy } from './types'

export default class Commands {
  emitter: Emitter;
  subscriptions: CompositeDisposable;

  constructor() {
    this.emitter = new Emitter()
    this.subscriptions = new CompositeDisposable()

    this.subscriptions.add(this.emitter)
    this.subscriptions.add(atom.commands.add('atom-text-editor:not([mini])', {
      'linter-ui-default:next-error': () => this.move(true),
      'linter-ui-default:previous-error': () => this.move(),
    }))
  }
  move(forward: boolean = false) {
    const messages = sortMessages(this.requestMessages())
    const expectedValue = forward ? -1 : 1
    const currentPosition = atom.workspace.getActiveTextEditor().getCursorBufferPosition()
    if (!forward) {
      messages.reverse()
    }
    for (let i = 0, length = messages.length, message; i < length; i++) {
      message = messages[i]
      const messageFile = message.version === 1 ? message.filePath : message.location.file
      const messageRange = message.version === 1 ? message.range : message.location.position
      if (messageRange && currentPosition.compare(messageRange.start) === expectedValue) {
        atom.workspace.open(messageFile, { searchAllPanes: true }).then(function() {
          const textEditor = atom.workspace.getActiveTextEditor()
          if (textEditor && textEditor.getPath() === messageFile) {
            textEditor.setCursorBufferPosition(messageRange.start)
          }
        })
        break
      }
    }
  }
  requestMessages(): Array<Message | MessageLegacy> {
    const filePath = atom.workspace.getActiveTextEditor().getPath()
    const event = { messages: [], filePath }
    this.emitter.emit('should-provide-messages', event)
    return event.messages
  }
  onShouldProvideMessages(callback: Function): Disposable {
    return this.emitter.on('should-provide-messages', callback)
  }
  dispose() {
    this.subscriptions.dispose()
  }
}
{'fraction_non_alphanumeric': 0.13272896327289632, 'fraction_numerical': 0.0023245002324500234, 'mean_word_length': 3.482291666666667, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1495608', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1219, 'n_words': 251}