<commit_before>Path = require 'path'
{CompositeDisposable, Emitter} = require 'atom'
LinterViews = require './linter-views'
EditorLinter = require './editor-linter'
Helpers = require './helpers'

class Linter
  constructor: ->
    # Public Stuff
    @lintOnFly = true # A default art value, to be immediately replaced by the observe config below
    @views = new LinterViews this # Used by editor-linter to trigger views.render

    # Private Stuff
    @_subscriptions = new CompositeDisposable
    @_emitter = new Emitter
    @_editorLinters = new Map
    @_messagesProject = new Map # Values set in editor-linter and consumed in views.render
    @linters = new Set # Values are pushed here from Main::consumeLinter

    @_subscriptions.add atom.config.observe 'linter.showErrorInline', (showBubble) =>
      @views.setShowBubble(showBubble)
    @_subscriptions.add atom.config.observe 'linter.lintOnFly', (value) =>
      @lintOnFly = value
    @_subscriptions.add atom.workspace.onDidChangeActivePaneItem (editor) =>
      # Exceptions thrown here prevent switching tabs
      try
        @getEditorLinter(editor)?.lint(false)
        @views.render()
      catch error
        atom.notifications.addError error.message, {detail: error.stack, dismissable: true}
    @_subscriptions.add atom.workspace.observeTextEditors (editor) =>
      currentEditorLinter = new EditorLinter @, editor
      @_editorLinters.set editor, currentEditorLinter
      @_emitter.emit 'linters-observe', currentEditorLinter
      currentEditorLinter.lint false
      editor.onDidDestroy =>
        currentEditorLinter.destroy()
        @_editorLinters.delete currentEditorLinter

  getProjectMessages: ->
    @_messagesProject

  setProjectMessages: (linter, messages) ->
    @_messagesProject.set(linter, Helpers.validateResults(messages))

  deleteProjectMessages: (linter) ->
    @_messagesProject.delete(linter)

  getActiveEditorLinter: ->
    return @getEditorLinter atom.workspace.getActiveTextEditor()<commit_msg>:new: Add addLinter, deleteLinter and getLinters to linter-plus<commit_after>Path = require 'path'
{CompositeDisposable, Emitter} = require 'atom'
LinterViews = require './linter-views'
EditorLinter = require './editor-linter'
Helpers = require './helpers'

class Linter
  constructor: ->
    # Public Stuff
    @lintOnFly = true # A default art value, to be immediately replaced by the observe config below
    @views = new LinterViews this # Used by editor-linter to trigger views.render

    # Private Stuff
    @_subscriptions = new CompositeDisposable
    @_emitter = new Emitter
    @_editorLinters = new Map
    @_messagesProject = new Map # Values set in editor-linter and consumed in views.render
    @linters = new Set # Values are pushed here from Main::consumeLinter

    @_subscriptions.add atom.config.observe 'linter.showErrorInline', (showBubble) =>
      @views.setShowBubble(showBubble)
    @_subscriptions.add atom.config.observe 'linter.lintOnFly', (value) =>
      @lintOnFly = value
    @_subscriptions.add atom.workspace.onDidChangeActivePaneItem (editor) =>
      # Exceptions thrown here prevent switching tabs
      try
        @getEditorLinter(editor)?.lint(false)
        @views.render()
      catch error
        atom.notifications.addError error.message, {detail: error.stack, dismissable: true}
    @_subscriptions.add atom.workspace.observeTextEditors (editor) =>
      currentEditorLinter = new EditorLinter @, editor
      @_editorLinters.set editor, currentEditorLinter
      @_emitter.emit 'linters-observe', currentEditorLinter
      currentEditorLinter.lint false
      editor.onDidDestroy =>
        currentEditorLinter.destroy()
        @_editorLinters.delete currentEditorLinter

  addLinter: (linter) ->
    @linters.add(linter)

  deleteLinter: (linter) ->
    @linters.delete(linter)

  getLinters: ->
    @linters

  getProjectMessages: ->
    @_messagesProject

  setProjectMessages: (linter, messages) ->
    @_messagesProject.set(linter, Helpers.validateResults(messages))

  deleteProjectMessages: (linter) ->
    @_messagesProject.delete(linter)

  getActiveEditorLinter: ->
    return @getEditorLinter atom.workspace.getActiveTextEditor()
{'fraction_non_alphanumeric': 0.09357841967056577, 'fraction_numerical': 0.0, 'mean_word_length': 3.872093023255814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '6163495', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1216, 'n_words': 296}