<commit_before>package io.gitlab.arturbosch.detekt.api

import org.jetbrains.kotlin.com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.preprocessor.typeReferenceName
import org.jetbrains.kotlin.psi.KtAnnotated
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtFile

/**
 * @author <NAME>
 */

/**
 * Checks if this psi element is suppressed by @Suppress or @SuppressWarnings annotations.
 * If this element cannot have annotations, the first annotative parent is searched.
 */
fun KtElement.isSuppressedBy(id: String)
		= this is KtAnnotated && this.isSuppressedBy(id) || findAnnotatedSuppressedParent(id)

private fun KtElement.findAnnotatedSuppressedParent(id: String): Boolean {
	val parent = PsiTreeUtil.getParentOfType(this, KtAnnotated::class.java, true)

	var suppressed = false
	if (parent != null && parent !is KtFile) {
		suppressed = if (parent.isSuppressedBy(id)) {
			true
		} else {
			parent.findAnnotatedSuppressedParent(id)
		}
	}

	return suppressed
}

/**
 * Checks if this kt element is suppressed by @Suppress or @SuppressWarnings annotations.
 */
fun KtAnnotated.isSuppressedBy(id: String): Boolean {
	val valid = listOf(id, "ALL", "all")
	return annotationEntries.find { it.typeReferenceName.let { it == "Suppress" || it == "SuppressWarnings" } }
			?.valueArguments
			?.map { it.getArgumentExpression()?.text }
			?.map { it?.replace(Regex("(?i)detekt([.:])"), "") }
			?.map { it?.replace("\"", "") }
			?.find { it in valid } != null
}
<commit_msg>extract regexes<commit_after>package io.gitlab.arturbosch.detekt.api

import org.jetbrains.kotlin.com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.preprocessor.typeReferenceName
import org.jetbrains.kotlin.psi.KtAnnotated
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtFile

/**
 * @author <NAME>
 */

/**
 * Checks if this psi element is suppressed by @Suppress or @SuppressWarnings annotations.
 * If this element cannot have annotations, the first annotative parent is searched.
 */
fun KtElement.isSuppressedBy(id: String)
		= this is KtAnnotated && this.isSuppressedBy(id) || findAnnotatedSuppressedParent(id)

private fun KtElement.findAnnotatedSuppressedParent(id: String): Boolean {
	val parent = PsiTreeUtil.getParentOfType(this, KtAnnotated::class.java, true)

	var suppressed = false
	if (parent != null && parent !is KtFile) {
		suppressed = if (parent.isSuppressedBy(id)) {
			true
		} else {
			parent.findAnnotatedSuppressedParent(id)
		}
	}

	return suppressed
}

private val detektSuppresionPrefixRegex = Regex("(?i)detekt([.:])")
private const val QUOTES = "\""

/**
 * Checks if this kt element is suppressed by @Suppress or @SuppressWarnings annotations.
 */
fun KtAnnotated.isSuppressedBy(id: String): Boolean {
	val valid = listOf(id, "ALL", "all")
	return annotationEntries.find { it.typeReferenceName.let { it == "Suppress" || it == "SuppressWarnings" } }
			?.valueArguments
			?.map { it.getArgumentExpression()?.text }
			?.map { it?.replace(detektSuppresionPrefixRegex, "") }
			?.map { it?.replace(QUOTES, "") }
			?.find { it in valid } != null
}

{'fraction_non_alphanumeric': 0.12967103161929097, 'fraction_numerical': 0.0, 'mean_word_length': 4.694545454545454, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1118162', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1041, 'n_words': 237}