<commit_before>_ = require('lodash')
_plus = require('underscore-plus')
Promise = require('bluebird')
Languages = require('../languages/')
path = require('path')
logger = require('../logger')(__filename)
{EventEmitter} = require 'events'

# Lazy loaded dependencies
extend = null
Analytics = null
fs = null
strip = null
yaml = null
editorconfig = null

# Misc
{allowUnsafeEval} = require 'loophole'
allowUnsafeEval ->
  Analytics = require("analytics-node")
pkg = require("../../package.json")

# Analytics
analyticsWriteKey = "<KEY>"

###
Register all supported beautifiers
###
module.exports = class Beautifiers extends EventEmitter
  ###
    List of beautifier names

    To register a beautifier add its name here
  ###
  beautifierNames : [
    'uncrustify'
    'autopep8'
    'coffee-formatter'
    'coffee-fmt'
    'clang-format'
    'dfmt'
    'elm-format'
    'htmlbeautifier'
    'csscomb'
    'gherkin'
    'gofmt'
    'latex-beautify'
    'fortran-beautifier'
    'js-beautify'
    'jscs'
    'perltidy'
    'php-cs-fixer'
    'phpcbf'
    'prettydiff'
    'puppet-fix'
    'remark'
    'rubocop'
    'ruby-beautify'
    'rustfmt'
    'sqlformat'
    'stylish-haskell'
    'tidy-markdown'
    'typescript-formatter'
    'yapf'
    'erl_tidy'
  ]

  ###
    List of loaded beautifiers

    Autogenerated in `constructor` from `beautifierNames`
  ###
  beautifiers : null

  ###
    All beautifier options

    Autogenerated in `constructor`
  ###
  options : null

  ###
    Languages
  ###
  languages : new Languages()

  ###
    Constructor
  ###
  constructor : ->

    # Load beautifiers
    @beautifiers = _.map( @beautifierNames, (name) ->
      Beautifier = require("./#{name}")
      new Beautifier()
    )


    # Build options from @beautifiers and @languages
    @options = @buildOptionsForBeautifiers( @beautifiers)


  buildOptionsForBeautifiers : (beautifiers) ->

    # Get all Options for Languages
    langOptions = {}
    languages = {} # Hash map of languages with their names
    for lang in @languages.languages
      langOptions[lang.name] ?= {}
      languages[lang.name] ?= lang
      options = langOptions[lang.name]


      # Init field for supported beautifiers
      lang.beautifiers = []


      # Process all language options
      for field, op of lang.options
        if not op.title?
          op.title = _plus.uncamelcase(field).split('.')
          .map(_plus.capitalize).join(' ')
        op.title = "#{lang.name} - #{op.title}"


        # Init field for supported beautifiers
        op.beautifiers = []

        # Remember Option's Key
        op.key =  field

        # Remember Option's Language
        op.language = lang

        # Add option
        options[field] = op

    # Find supported beautifiers for each language
    for beautifier in beautifiers
      beautifierName = beautifier.name


      # Iterate over supported languages
      for languageName, options of beautifier.options
        laOp = langOptions[languageName]


        # Is a valid Language name
        if typeof options is "boolean"

          # Enable / disable all options
          # Add Beautifier support to Language
          languages[languageName]?.beautifiers.push(beautifierName)


          # Check for beautifier's options support<commit_msg>Fixes #879. Fix circular structure in JSON config/settings<commit_after>_ = require('lodash')
_plus = require('underscore-plus')
Promise = require('bluebird')
Languages = require('../languages/')
path = require('path')
logger = require('../logger')(__filename)
{EventEmitter} = require 'events'

# Lazy loaded dependencies
extend = null
Analytics = null
fs = null
strip = null
yaml = null
editorconfig = null

# Misc
{allowUnsafeEval} = require 'loophole'
allowUnsafeEval ->
  Analytics = require("analytics-node")
pkg = require("../../package.json")

# Analytics
analyticsWriteKey = "<KEY>"

###
Register all supported beautifiers
###
module.exports = class Beautifiers extends EventEmitter
  ###
    List of beautifier names

    To register a beautifier add its name here
  ###
  beautifierNames : [
    'uncrustify'
    'autopep8'
    'coffee-formatter'
    'coffee-fmt'
    'clang-format'
    'dfmt'
    'elm-format'
    'htmlbeautifier'
    'csscomb'
    'gherkin'
    'gofmt'
    'latex-beautify'
    'fortran-beautifier'
    'js-beautify'
    'jscs'
    'perltidy'
    'php-cs-fixer'
    'phpcbf'
    'prettydiff'
    'puppet-fix'
    'remark'
    'rubocop'
    'ruby-beautify'
    'rustfmt'
    'sqlformat'
    'stylish-haskell'
    'tidy-markdown'
    'typescript-formatter'
    'yapf'
    'erl_tidy'
  ]

  ###
    List of loaded beautifiers

    Autogenerated in `constructor` from `beautifierNames`
  ###
  beautifiers : null

  ###
    All beautifier options

    Autogenerated in `constructor`
  ###
  options : null

  ###
    Languages
  ###
  languages : new Languages()

  ###
    Constructor
  ###
  constructor : ->

    # Load beautifiers
    @beautifiers = _.map( @beautifierNames, (name) ->
      Beautifier = require("./#{name}")
      new Beautifier()
    )


    # Build options from @beautifiers and @languages
    @options = @buildOptionsForBeautifiers( @beautifiers)


  buildOptionsForBeautifiers : (beautifiers) ->

    # Get all Options for Languages
    langOptions = {}
    languages = {} # Hash map of languages with their names
    for lang in @languages.languages
      langOptions[lang.name] ?= {}
      languages[lang.name] ?= lang
      options = langOptions[lang.name]


      # Init field for supported beautifiers
      lang.beautifiers = []


      # Process all language options
      for field, op of lang.options
        if not op.title?
          op.title = _plus.uncamelcase(field).split('.')
          .map(_plus.capitalize).join(' ')
        op.title = "#{lang.name} - #{op.title}"


        # Init field for supported beautifiers
        op.beautifiers = []

        # Remember Option's Key
        op.key =  field

        # Remember Option's Language
        op.language = {
          name: lang.name,
          namespace: lang.namespace
        }

        # Add option
        options[field] = op

    # Find supported beautifiers for each language
    for beautifier in beautifiers
      beautifierName = beautifier.name


      # Iterate over supported languages
      for languageName, options of beautifier.options
        laOp = langOptions[languageName]


        # Is a valid Language name
        if typeof options is "boolean"

          # Enable / disable all options
          # Add Beautifier support to Language
          languages[languageName]?.beautifiers.push(beautifierName)


          # Check for beautifier's options support
{'fraction_non_alphanumeric': 0.11036339165545088, 'fraction_numerical': 0.0007477194556602363, 'mean_word_length': 2.5937667920472864, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '2202099', 'n_tokens_mistral': 2101, 'n_tokens_neox': 2024, 'n_words': 519}