<commit_before>/**
 *   Copyright 2012 Foursquare Labs, Inc.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package org.psywerx.hairyfotr

import scala.collection.mutable
import scala.tools.nsc.Global

object Utils {
  var linterOptions = LinterOptions()
  val nowarnPositions = mutable.HashSet[Global#Position]()
  val nowarnMergeNestedIfsPositions = mutable.HashSet[Global#Position]() //TODO: hack

  def warn(tree: Global#Tree, warning: Warning)(implicit unit: Global#CompilationUnit): Unit = {
    warn(tree.pos, warning)(unit)
  }
  def warn(tree: Global#Position, warning: Warning)(implicit unit: Global#CompilationUnit): Unit = {
    val checkSep = "([+:]|[,] )"
    val partSep = "[ :]"
    val checkReg = "[A-Z][a-zA-Z]+"
    if((linterOptions.disabledWarningNames contains warning.name)
    || (tree.pos.lineContent matches s".*// *linter${partSep}(nowarn|ignore|disable)(${partSep}(${checkReg}${checkSep})*${warning.name}(${checkSep}${checkReg})*)? *(//.*)?")
    || (nowarnPositions contains tree.pos)) {
      // skip
    } else {
      // scalastyle:off regex
      unit.warning(tree.pos, if (linterOptions.printWarningNames) s"[${warning.name}] ${warning.message}" else warning.message)
      // scalastyle:on regex
    }
  }
  
  def toBang(b: Boolean) = if (b) "!" else ""  
}

// Put only those that need the right global here:
class Utils[G <: Global](val global: G) {
  import global._
  global.definitions.init

  def isUsed(t: Tree, name: String, filter: String = ""): Boolean = {
    val tree = t.asInstanceOf[Tree]
    var used = 0
    for (Ident(id) <- tree; if id.toString == name) used += 1<commit_msg>Missing public type<commit_after>/**
 *   Copyright 2012 Foursquare Labs, Inc.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package org.psywerx.hairyfotr

import scala.collection.mutable
import scala.tools.nsc.Global

object Utils {
  var linterOptions = LinterOptions()
  val nowarnPositions = mutable.HashSet[Global#Position]()
  val nowarnMergeNestedIfsPositions = mutable.HashSet[Global#Position]() //TODO: hack

  def warn(tree: Global#Tree, warning: Warning)(implicit unit: Global#CompilationUnit): Unit = {
    warn(tree.pos, warning)(unit)
  }
  def warn(tree: Global#Position, warning: Warning)(implicit unit: Global#CompilationUnit): Unit = {
    val checkSep = "([+:]|[,] )"
    val partSep = "[ :]"
    val checkReg = "[A-Z][a-zA-Z]+"
    if((linterOptions.disabledWarningNames contains warning.name)
    || (tree.pos.lineContent matches s".*// *linter${partSep}(nowarn|ignore|disable)(${partSep}(${checkReg}${checkSep})*${warning.name}(${checkSep}${checkReg})*)? *(//.*)?")
    || (nowarnPositions contains tree.pos)) {
      // skip
    } else {
      // scalastyle:off regex
      unit.warning(tree.pos, if (linterOptions.printWarningNames) s"[${warning.name}] ${warning.message}" else warning.message)
      // scalastyle:on regex
    }
  }
  
  def toBang(b: Boolean): String = if (b) "!" else ""  
}

// Put only those that need the right global here:
class Utils[G <: Global](val global: G) {
  import global._
  global.definitions.init

  def isUsed(t: Tree, name: String, filter: String = ""): Boolean = {
    val tree = t.asInstanceOf[Tree]
    var used = 0
    for (Ident(id) <- tree; if id.toString == name) used += 1
{'fraction_non_alphanumeric': 0.13617511520737327, 'fraction_numerical': 0.004608294930875576, 'mean_word_length': 3.7287581699346406, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1523069', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1341, 'n_words': 394}