Giter Club home page Giter Club logo

diktat's People

Contributors

0x6675636b796f75676974687562 avatar agebhar1 avatar aktsay6 avatar akuleshov7 avatar animeshz avatar arrgentum avatar cheshiriks avatar dependabot[bot] avatar diphtongue avatar dralexd avatar github-actions[bot] avatar goooler avatar icemachined avatar kentr0w avatar kgevorkyan avatar marcospereira avatar maugagneur avatar nulls avatar petertrr avatar philipdukhov avatar portlek avatar renovate[bot] avatar sanyavertolet avatar unix-junkie avatar vtchem avatar yegor256 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

diktat's Issues

[Formatting rules] Add support for checking and fixing copyright date in the Kdoc

If your code has a copyright and it's actual year differs from the current year - it should be fixed (or warning should be raised).
For example if current year is 2020, this code

/** 
* Copyright (c) Ivanoff Technologies Co., Ltd. 1992-2017. All rights reserved
*/

should be changed to this one:

/** 
* Copyright (c) Ivanoff Technologies Co., Ltd. 1992-2020. All rights reserved
*/

Bugs with identifiers naming checks

  • toUpperCase incorrectly convert names like iAmConstant
  • I_AM_CONSTANT1 - Incorrectly raises warning when sees digit in the name
  • STRANGE_name - incorrect case fixing

Special handling of methods in tests

  • No need to check method name for case and length, if it is in back ticks and consists of multiple words
  • Do not force KDoc even if test method is public

Method is considered from tests if one of the following is true:

  • Annotated with @Test
  • Located in src/test
  • File name ends with test

Rule 3.5: Use spaces for indentation, indenting is equal to 4 spaces

May be you can look if it is already done in ktlint-standard? If yes - simply inherit it with customizations

Only spaces are allowed for indentation and each indentation should equal to 4 spaces (tabs are not allowed).
In case you prefer using tabs - just simply configure auto change of tabs to spaces in your IDE.
Exceptions:

  1. When breaking parameter list of a method/class constructor it can be aligned with 8 spaces or a parameter that was moved to a newline can be on the same level as the previous argument:
class Class(propertiesFileName: String,
            otherName: String) {

or

fun visit(
        node: ASTNode,
        autoCorrect: Boolean,
        params: KtLint.Params,
        emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit
) {
  1. Operators like +/-/*/e.t.c can be indented with 8 spaces:
val abcdef = "my splitted" +
                " string"

Move it to Maven Central

Now it's hosted on Artipie. I don't see why can't we host it on Maven Central under org.cqfn domain.

False trigger of identifier naming rule at underscores

Underscores should be allowed for ignored parameters

[INFO]    [ktlint] C:\Users\pwx5333130\Documents\diKTat\diktat-rules\src\test\kotlin\org\cqfn\diktat\ruleset\utils\TestUtils.kt:23:31: [9] variable name should be in camel case (correct: checkIpConfig, incorrect: CheckIPConfig) should contain only latin (ASCII) letters or numbers and should start from lower letter: _

Validate diktat-analysis.yml before start of analysis

If there are issues with user's json config, we should report it asap and fail without start of analysis. Possible issues:

  • wrong warning names
    * wrong fields in configuration moved to #395
    * wrong values in configuration (e.g. numbers in wrong format) same

Improvements for diktat check

  • Add maven cache to github workflow
  • In release workflow, when new version of diktat is released, create pull request with updated version in diktat check (antrun plugin) #91 for this
  • Ideally, resolve #69

Rule 3.4 For non-empty blocks and block structures, the opening brace is placed at the end of the line

Rule 3.4 For non-empty blocks and block structures, the opening brace is placed at the end of the line

For non-empty code blocks with braces, they should follow the K&R style (1TBS or OTBS style):

  • The opening brace is on the same same line with the first line of the code block
  • The closing brace is on it's new line
  • The closing brace can be followed by a new line or else, finally or catch keywords

Good example:

       return () -> {
           while (condition()) {
               method()
           }
       }

       return MyClass() {
           @Override
             fun method() {
               if (condition()) {
                   try {
                       something()
                   } catch (ProblemException e) {
                       recover()
                   }
               } else if (otherCondition()) {
                   somethingElse()
               } else {
                   lastThing()
               }
           }
       }

Smoke tests for diktat rules

  • Create verbose examples for expected diktat behavior, when many warnings are applied simultaneously.
  • Try to make them 'real-world' examples for common use cases.
  • Probably, use TestEntry from diktat-test-framework?

Automate documentation generation

Currently we write all new warnings with description, list of tests and fixmes into a table manually. What could be automated:

  • Get list of warnings from Warnings.kt
  • Create mechanism to store descriptions in code
  • Get descriptions from code
  • Get list of tests from names of @Test methods

diKTat should not fail on missing configuration. It should raise a warning in this case

[DEBUG] Internal Error (diktat-ruleset:package-naming)
com.pinterest.ktlint.core.RuleExecutionException: java.util.NoSuchElementException: Key domainName is missing in the map.
at com.pinterest.ktlint.core.KtLint$lint$1.invoke(KtLint.kt:177)
at com.pinterest.ktlint.core.KtLint$lint$1.invoke(KtLint.kt:43)
at com.pinterest.ktlint.core.KtLint$visitor$2$1.invoke(KtLint.kt:246)
at com.pinterest.ktlint.core.KtLint$visitor$2$1.invoke(KtLint.kt:43)
at com.pinterest.ktlint.core.KtLint.visit(KtLint.kt:572)
at com.pinterest.ktlint.core.KtLint.access$visit(KtLint.kt:43)
at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:244)
at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:43)
at com.pinterest.ktlint.core.KtLint.lint(KtLint.kt:162)
at com.pinterest.ktlint.internal.FileUtilsKt.lintFile(FileUtils.kt:51)

False positive triggering of FUNCTION_BOOLEAN_PREFIX

[INFO]    [ktlint] C:\Users\pwx5333130\Documents\diKTat\diktat-rules\src\main\kotlin\org\cqfn\diktat\ruleset\rules\kdoc\KdocFormatting.kt:298:25: [17] functions that return the value of Boolean type should have <is> or <has> prefix: hasEmptyLineAfter
[INFO]    [ktlint] C:\Users\pwx5333130\Documents\diKTat\diktat-rules\src\main\kotlin\org\cqfn\diktat\ruleset\utils\FunctonASTNodeUtils.kt:21:13: [17] functions that return the value of Boolean type should have <is> or <has> prefix: hasParametersKDoc
[INFO]    [ktlint] C:\Users\pwx5333130\Documents\diKTat\diktat-rules\src\main\kotlin\org\cqfn\diktat\ruleset\utils\KDocUtils.kt:20:23: [17] functions that return the value of Boolean type should have <is> or <has> prefix: hasKnownKDocTag
[INFO]    [ktlint] C:\Users\pwx5333130\Documents\diKTat\diktat-rules\src\main\kotlin\org\cqfn\diktat\ruleset\utils\StringUtils.kt:23:12: [17] functions that return the value of Boolean type should have <is> or <has> prefix: isASCIILettersAndDigits

Probably because this is an extension function.

Add usage instruction with gradle to README

Gradle is really popular in kotlin community, also ktlint has good integration with gradle. We should add instructions on how to add artipie and our dependencies in build.gradle and how to use diktat with ktlint plugin.

[Formatting rules] Improve analysis of KDocs for functions

In addition to rule 2.5:

  • Do not force KDocs for methods with name "(get|set).*" and single line of body
  • Do not force @return, @param tag for getters/setters at all.
  • The following KDocs are considered useless: if they start with words return/get/set and contains one or two more words
  • Do not force KDoc for standard methods like toString, equals and hashCode

Error on argument with function type

On

fun ASTNode.findChildrenMatching(elementType: IElementType? = null, predicate: (ASTNode) -> Boolean): List<ASTNode> =

diktat fails with

[INFO]    [ktlint] C:\Users\pwx5333130\Documents\diKTat\diktat-rules\src\main\kotlin\org\cqfn\diktat\ruleset\utils\AstNodeUtils.kt:182:81: Internal Error (diktat-ruleset:identifier-naming). Please create a ticket at https://github.com/pinterest/ktlint/issues (if possible, provide the source code that triggered an error) (cannot be auto-corrected)

Offset corresponds to opening parentheses at (ASTNode)

[Rule 3.3] Braces

Rule 3.3 Braces must be used in conditional statements and loop blocks

In if, else, when, for, do, and while statements, even if the program body is empty or contains only one statement, braces should be used.

Exception: Only The only exception is ternary operator in Kotlin (it is a single line if () <> else <> )
When the entire expression can be

Bad example:

val value = if (string.isEmpty())  // WRONG!
                0
            else
                1

Valid example:

val value = if (string.isEmpty()) 0 else 1  // Okay
if (condition) {
    println("test")
} else {
    println(0)
}

Add it to Homebrew

I can install KTlint through Homebrew, but can't do the same for diKTat. Would be great if you can make it possible.

Recommendation 3.1 - recommended ordering of imports

The following snippet can be a starting point for implementation inside FileStructureRule.kt:

private val recommendedComparator = Comparator<ASTNode> { import1, import2 ->
        require(import1.elementType == IMPORT_DIRECTIVE && import2.elementType == IMPORT_DIRECTIVE) { "This comparator is for sorting imports" }
        val pathSegments1 = (import1.psi as KtImportDirective).importPath!!.fqName.pathSegments()
        val pathSegments2 = (import2.psi as KtImportDirective).importPath!!.fqName.pathSegments()

        return@Comparator 0
    }

IdentifierNaming#checkObjectNaming throws NPE on checking companion object

   [ktlint] Caused by: kotlin.KotlinNullPointerException
   [ktlint] 	at org.cqfn.diktat.ruleset.rules.IdentifierNaming.checkObjectNaming(IdentifierNaming.kt:185)
   [ktlint] 	at org.cqfn.diktat.ruleset.rules.IdentifierNaming.visit(IdentifierNaming.kt:69)
   [ktlint] 	at com.pinterest.ktlint.core.KtLint$lint$1.invoke(KtLint.kt:167)
   [ktlint] 	... 20 more

Same occurs on anonymous objects

object : Rule("astnode-utils-test") {
                                    override fun visit(node: ASTNode,

Recommendation 3.2: The declaration part of a class-like code structures (class/interface/e.t.c) should be in the proper order

Notes:

  • There should be no blank lines between properties without comments;
  • Properties with comments/Kdoc should be separated by a newline before the comment/Kdoc

The declaration part of a class or interface should be in the following order:

  • compile-time constants (for objects)
  • Properties
  • late-init class properties
  • init-blocks
  • constructors
  • methods or nested classes. Put nested classes next to the code that uses those classes. If the classes are intended to be used externally and aren't referenced inside the class, put them in the end, after the companion object.
  • companion object
  • Exception: All variants of a private val logger should be placed in the beginning of the class (private val log/LOG/logger/e.t.c)

Fix KdocMethods#addKdocTemplate

KDocs added by KDocMethods rule are not properly indented by IndentationRule. This is probably because KDoc template is added as LeafPsiElement, while it should be a CompositeElement.
Example of CompositeElement construction can be found in KdocUtils: ASTNode.insertTagBefore.
Once this is fixed, one should try applying KDocMethods and IndentationRule simultaneously. Such case should also be added in #50 .

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.