<commit_before>package lert.core

import java.io.File
import java.lang.reflect.{Field, ParameterizedType}
import java.nio.file.{Files, Paths}

import lert.core.config.{Config, Description}

import scala.util.Try

class ConfigDocumentation extends BaseSpec {
  it should "generate config docs" in {
    ConfigDocumentation.main(Array())
  }
}

object ConfigDocumentation extends App {
  val sb = new StringBuilder
  generateForClass(classOf[Config], sb, 0)

  Files.write(Paths.get("./docs/config.md"),
    s"""
       |# Configuration
       |
      |${sb.toString()}
    """.stripMargin.getBytes)

  def generateForClass(cls: Class[_], sb: StringBuilder, level: Int): Unit = {
    cls.getDeclaredFields.foreach { f =>
      val description = f.getAnnotationsByType(classOf[Description]).headOption.map(_.value()).getOrElse("")
      val indent = (0 until level).map(_ => "\t").mkString("")
      sb.append(s"$indent* `${f.getName}` (${f.getType.getSimpleName}) - $description \n")

      val genericClass = getGenericClass(f)
      val nestedClass = if (genericClass != null) genericClass else f.getType

      if (nestedClass.getPackage == classOf[Config].getPackage) {<commit_msg>Config doc generator :: test fix<commit_after>package lert.core

import java.io.File
import java.lang.reflect.{Field, ParameterizedType}
import java.nio.file.{Files, Paths}

import lert.core.config.{Config, Description}

import scala.util.Try

class ConfigDocumentation extends BaseSpec {
  it should "generate config docs" in {
    if (System.getenv("SKIP_DOC_GENERATION") == null) {
      ConfigDocumentation.main(Array())
    }
  }
}

object ConfigDocumentation extends App {
  val sb = new StringBuilder
  generateForClass(classOf[Config], sb, 0)

  Seq("./docs/config.md", "../docs/config.md")
    .map(Paths.get(_))
    .find(Files.exists(_))
    .foreach { p =>
      Files.write(p,
        s"""
           |# Configuration
           |
      |${sb.toString()}
    """.stripMargin.getBytes)
      println("Done!!!")
    }

  def generateForClass(cls: Class[_], sb: StringBuilder, level: Int): Unit = {
    cls.getDeclaredFields.foreach { f =>
      val description = f.getAnnotationsByType(classOf[Description]).headOption.map(_.value()).getOrElse("")
      val indent = (0 until level).map(_ => "\t").mkString("")
      sb.append(s"$indent* `${f.getName}` (${f.getType.getSimpleName}) - $description \n")

      val genericClass = getGenericClass(f)
      val nestedClass = if (genericClass != null) genericClass else f.getType

      if (nestedClass.getPackage == classOf[Config].getPackage) {
{'fraction_non_alphanumeric': 0.1470019342359768, 'fraction_numerical': 0.0015473887814313346, 'mean_word_length': 3.667870036101083, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '4551407', 'n_tokens_mistral': 807, 'n_tokens_neox': 802, 'n_words': 174}