mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
Rename location's factory method 'of' to 'from'
This commit is contained in:
@@ -10,7 +10,7 @@ interface Config {
|
||||
fun <T : Any> valueOrDefault(key: String, default: () -> T): T
|
||||
|
||||
class InvalidConfigurationError(msg: String = "Provided configuration file is invalid:" +
|
||||
" Structure must be of type Map<String,Any>!") : RuntimeException(msg)
|
||||
" Structure must be from type Map<String,Any>!") : RuntimeException(msg)
|
||||
|
||||
companion object {
|
||||
val EMPTY: Config = YamlConfig(mapOf())
|
||||
|
||||
@@ -35,7 +35,7 @@ data class Location(val source: SourceLocation,
|
||||
companion object {
|
||||
|
||||
fun from(startElement: PsiElement, endElementExclusively: PsiElement?): Location {
|
||||
if (endElementExclusively == null) return of(startElement)
|
||||
if (endElementExclusively == null) return from(startElement)
|
||||
val start = startLineAndColumn(startElement)
|
||||
val sourceLocation = SourceLocation(start.line, start.column)
|
||||
val textLocation = TextLocation(startElement.startOffset, endElementExclusively.startOffset - 1)
|
||||
@@ -43,7 +43,7 @@ data class Location(val source: SourceLocation,
|
||||
startElement.getTextWithLocation(), startElement.containingFile.name)
|
||||
}
|
||||
|
||||
fun of(element: PsiElement): Location {
|
||||
fun from(element: PsiElement): Location {
|
||||
val start = startLineAndColumn(element)
|
||||
val sourceLocation = SourceLocation(start.line, start.column)
|
||||
val textLocation = TextLocation(element.startOffset, element.endOffset)
|
||||
|
||||
@@ -14,7 +14,7 @@ class DetektSpec : Spek({
|
||||
|
||||
val detekt = Detekt(path)
|
||||
|
||||
it("should detect findings of more than one provider") {
|
||||
it("should detect findings from more than one provider") {
|
||||
assertTrue { detekt.run().size >= 1 }
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class CommentOverPrivateMethod(config: Config = Config.EMPTY) : CodeSmellRule("C
|
||||
val modifierList = function.modifierList
|
||||
if (modifierList != null && function.docComment != null) {
|
||||
if (modifierList.hasModifier(KtTokens.PRIVATE_KEYWORD)) {
|
||||
addFindings(CodeSmell(id, Location.of(function.docComment!!)))
|
||||
addFindings(CodeSmell(id, Location.from(function.docComment!!)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class CommentOverPrivateProperty(config: Config = Config.EMPTY) : CodeSmellRule(
|
||||
val modifierList = property.modifierList
|
||||
if (modifierList != null && property.docComment != null) {
|
||||
if (modifierList.hasModifier(KtTokens.PRIVATE_KEYWORD)) {
|
||||
addFindings(CodeSmell(id, Location.of(property.docComment!!)))
|
||||
addFindings(CodeSmell(id, Location.from(property.docComment!!)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class ComplexMethod(config: Config = Config.EMPTY, threshold: Int = 10) : CodeSm
|
||||
override fun visitNamedFunction(function: KtNamedFunction) {
|
||||
val mcc = MccVisitor().visit(function)
|
||||
if (mcc > threshold) {
|
||||
addFindings(ThresholdedCodeSmell(id, Location.of(function), mcc, threshold))
|
||||
addFindings(ThresholdedCodeSmell(id, Location.from(function), mcc, threshold))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class LargeClass(config: Config = Config.EMPTY, threshold: Int = 70) : CodeSmell
|
||||
incHead() // for class body
|
||||
super.visitClassOrObject(classOrObject)
|
||||
if (locStack.pop() > threshold) {
|
||||
addFindings(CodeSmell(id, Location.of(classOrObject)))
|
||||
addFindings(CodeSmell(id, Location.from(classOrObject)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class LongMethod(config: Config = Config.EMPTY, threshold: Int = 20) : CodeSmell
|
||||
val body: KtBlockExpression? = function.bodyExpression.asBlockExpression()
|
||||
body?.let {
|
||||
val size = body.statements.size
|
||||
if (size > threshold) addFindings(CodeSmell(id, Location.of(function)))
|
||||
if (size > threshold) addFindings(CodeSmell(id, Location.from(function)))
|
||||
}
|
||||
super.visitNamedFunction(function)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class LongParameterList(config: Config = Config.EMPTY, threshold: Int = 5) : Cod
|
||||
|
||||
override fun visitParameterList(list: KtParameterList) {
|
||||
if (list.parameters.size > threshold) {
|
||||
addFindings(CodeSmell(id, Location.of(list)))
|
||||
addFindings(CodeSmell(id, Location.from(list)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,13 +23,13 @@ class NamingConventionViolation(config: Config = Config.EMPTY) : Rule("NamingCon
|
||||
declaration.nameIdentifier?.parent?.javaClass?.let {
|
||||
val name = declaration.nameAsSafeName.asString()
|
||||
if (declaration is KtVariableDeclaration && !name.matches(variablePattern)) {
|
||||
addFindings(CodeSmell(id, Location.of(declaration)))
|
||||
addFindings(CodeSmell(id, Location.from(declaration)))
|
||||
}
|
||||
if (declaration is KtNamedFunction && !name.matches(methodPattern)) {
|
||||
addFindings(CodeSmell(id, Location.of(declaration)))
|
||||
addFindings(CodeSmell(id, Location.from(declaration)))
|
||||
}
|
||||
if (declaration is KtClassOrObject && !name.matches(classPattern)) {
|
||||
addFindings(CodeSmell(id, Location.of(declaration)))
|
||||
addFindings(CodeSmell(id, Location.from(declaration)))
|
||||
}
|
||||
}
|
||||
super.visitNamedDeclaration(declaration)
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.psi.KtWhenExpression
|
||||
class NoElseInWhenExpression(config: Config = Config.EMPTY) : Rule("NoElseInWhenExpression", Severity.Defect, config) {
|
||||
|
||||
override fun visitWhenExpression(expression: KtWhenExpression) {
|
||||
if (expression.elseExpression == null) addFindings(CodeSmell(id, Location.of(expression)))
|
||||
if (expression.elseExpression == null) addFindings(CodeSmell(id, Location.from(expression)))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,11 +24,11 @@ class UselessSemicolon(config: Config = Config.EMPTY) : TokenRule("UselessSemico
|
||||
val psi = node.psi
|
||||
if (psi.isNoErrorElement() && psi.isNotPartOfEnum() && psi.isNotPartOfString()) {
|
||||
if (psi.isDoubleSemicolon()) {
|
||||
addFindings(CodeSmell(id, Location.of(psi)))
|
||||
addFindings(CodeSmell(id, Location.from(psi)))
|
||||
} else if (psi.isSemicolon()) {
|
||||
val nextLeaf = PsiTreeUtil.nextLeaf(psi)
|
||||
if (isSemicolonOrEOF(nextLeaf) || nextTokenHasSpaces(nextLeaf)) {
|
||||
addFindings(CodeSmell(id, Location.of(psi)))
|
||||
addFindings(CodeSmell(id, Location.from(psi)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class WildcardImport(config: Config = Config.EMPTY) : Rule("WildcardImport", Sev
|
||||
override fun visitImportDirective(importDirective: KtImportDirective) {
|
||||
val import = importDirective.importPath?.pathStr
|
||||
if (import != null && import.contains("*")) {
|
||||
addFindings(CodeSmell(id, Location.of(importDirective)))
|
||||
addFindings(CodeSmell(id, Location.from(importDirective)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
4
gradlew
vendored
4
gradlew
vendored
@@ -78,14 +78,14 @@ if [ -n "$JAVA_HOME" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
location from your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
location from your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
|
||||
6
gradlew.bat
vendored
6
gradlew.bat
vendored
@@ -27,7 +27,7 @@ echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo location from your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
@@ -41,7 +41,7 @@ echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo location from your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
@@ -79,7 +79,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead from
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
Reference in New Issue
Block a user