Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a linter to the project #5198

Open
shankarpriyank opened this issue Apr 1, 2023 · 12 comments · May be fixed by #5615
Open

Add a linter to the project #5198

shankarpriyank opened this issue Apr 1, 2023 · 12 comments · May be fixed by #5615

Comments

@shankarpriyank
Copy link
Contributor

What is the user problem or growth opportunity you want to see solved?

If we start using a linter, maintaining the code style in the project will be easier. Also this will save some time for too, the maintainers wont have to look out for styling issues in pr's the contributors to will have a easy time following the code style of the project

How do you know that this problem exists today? Why is this important?

I made a few pr's and there was need to fix the styling issues in them, by using a linter we can cut down on the to and fro

Who will benefit from it?

The developers/contributors and even the maintainers

Anything else you would like to add?

There are quite a few options we can look at, but I would suggest using ktlint

@nicolas-raoul
Copy link
Member

nicolas-raoul commented Apr 3, 2023

If I understand correctly the linter would perform a check on pull requests, like is currently done for unit tests as seen in the example below?
Screenshot 2023-04-03 at 15 17 08

This project has such a thing configured:
Screenshot 2023-04-03 at 15 24 15

Ideally it should also be runnable locally, maybe even in IDEs.

@shankarpriyank
Copy link
Contributor Author

Yup, we can add the linting checks in the same workflow file.
And ktlint works well locally , runs smoothly with the IDE's too, and it does not have anything to do specifically with the IDE's we can run it locally via the terminal

@shankarpriyank
Copy link
Contributor Author

If possible, I would like to work on this issue.

@shankarpriyank
Copy link
Contributor Author

shankarpriyank commented Apr 6, 2023

I am trying to add ktlint to the project, and I am running into a error
My guess is that the error is cause because
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
Investigating it right now

@neeldoshii
Copy link
Contributor

Hello @shankarpriyank,

I noticed that the issue assigned to you is now over a year old, and I was wondering about the current status of the associated PR. If, for any reason, you're unable to continue working on it, would it be possible for me to take over this PR? I'm keen to contribute and help move this forward 😊.

Thanks

@shankarpriyank shankarpriyank removed their assignment Mar 7, 2024
@shankarpriyank
Copy link
Contributor Author

Hey @neeldoshii, please feel free to work on this.
I don't think I have the time work on this anytime soon

@neeldoshii
Copy link
Contributor

Did an inspection on ktlint library mentioned by @shankarpriyank klint (Pintrest). I believe integrating ktlint with our GitHub Actions could significantly improve our development workflow, especially for Kotlin code.

As of 8th March 2024, our codebase composition stands at 55% Java and 44% Kotlin. Since ktlint is designed specifically for Kotlin, it unfortunately does not support our Java codebase. To ensure both parts of our codebase are equally maintained and follow best practices, I propose we integrate both klint for Kotlin and Checkstyle for Java.

In future when the code base is permanently migrated to kotlin codebase we can remove the Checkstyle.

What's your opinion over this @nicolas-raoul @RitikaPahwa4444?

@shankarpriyank
Copy link
Contributor Author

shankarpriyank commented Mar 8, 2024

Hi @neeldoshii, just a suggestion, it would be better if you could first introduce the library in the project and focus on elevating the developer experience. I assume would you would have to mark baseline files too cause we would most likely not want to change existing code.
Best of luck

@neeldoshii
Copy link
Contributor

Thanks for your feedback @shankarpriyank,

I assume would you would have to mark baseline files too cause we would most likely not want to change existing code.

My plan for now is to run ktlint only on recently edited changes (addition & deletion) of the files. So my plan is to add it in the Github Action which will check it & test code quality when the contributor will commit just like our Run test & Generate AP.

We would most likely not want to change existing code.

You are right this will lead to many refactoring because of lint errors. For this local ktlint check I plan to perform it via Git Pre-commit Hook which will make sure to perform gradle ktlintcheck & format only to staging commit files.

For now I plan to introduce ktlint first and later on checkstyle or any good library which is better for java codebase based on the feedback from other contributors which is better.
What do you think? @shankarpriyank.

@shankarpriyank
Copy link
Contributor Author

My plan for now is to run ktlint only on recently edited changes (addition & deletion) of the files.

I think to do this on CI, would be tough.

For this local ktlint check I plan to perform it via Git Pre-commit Hook which will make sure to perform gradle ktlintcheck & format only to staging commit files

Its a good idea to run format on recently staged file, but I am not really sure about adding a pre-commit hook, as the ktlintCheck will take quite some time to execute and I am not sure its worth it to make this trade-off.
Again I am not sure, but as far I know its easy to run format only on staged files but for check you will have to make mark/generate baseline files

But anyways, please go ahead and feel free to open a pr

@neeldoshii
Copy link
Contributor

neeldoshii commented Mar 8, 2024

Progress Update : @nicolas-raoul @shankarpriyank
Implemented Ktlint in the repo, this is the number of errors we have ./gradlew ktlintCheck

No of errors Count : 119 (which is way less as its a small refactor)
We can add this as good first issue for newcomers or get this solved before adding ktlint to the main(I am okay with refactoring this chore task and get it done). Once this is done we can add the github CI/CD pipeline which will enhance developer experience.

Again I am not sure, but as far I know its easy to run format only on staged files but for check you will have to make mark/generate baseline files

You are right about ktlint check!! We can plan to add ./gradlew ktlintFormat which will fix bad indentation on commits.
Need your take guys.

Below is the results of ./gradlew ktlintCheck

java/fr/free/nrw/commons/AboutActivityTest.kt:130:26 Missing newline after "("
java/fr/free/nrw/commons/AboutActivityTest.kt:130:45 Argument should be on a separate line (unless all arguments can fit a single line)
java/fr/free/nrw/commons/AboutActivityTest.kt:130:45 Missing newline after "("
java/fr/free/nrw/commons/AboutActivityTest.kt:131:55 Missing newline before ")"
java/fr/free/nrw/commons/AboutActivityTest.kt:131:56 Missing newline before ")"
java/fr/free/nrw/commons/AboutActivityTest.kt:131:56 Missing newline before ")"
java/fr/free/nrw/commons/AboutActivityTest.kt:134:1 Needless blank line(s)
java/fr/free/nrw/commons/LoginActivityTest.kt:1:1 File must end with a newline (\n)
java/fr/free/nrw/commons/LoginActivityTest.kt:21:1 Wildcard import (cannot be auto-corrected)
java/fr/free/nrw/commons/MainActivityTest.kt:1:1 File must end with a newline (\n)
java/fr/free/nrw/commons/MainActivityTest.kt:24:1 Wildcard import (cannot be auto-corrected)
java/fr/free/nrw/commons/MainActivityTest.kt:82:55 Argument should be on a separate line (unless all arguments can fit a single line)
java/fr/free/nrw/commons/MainActivityTest.kt:229:1 Unexpected blank line(s) before "}"
java/fr/free/nrw/commons/ProfileActivityTest.kt:7:1 Unused import
java/fr/free/nrw/commons/ProfileActivityTest.kt:64:27 Missing spacing after ","
java/fr/free/nrw/commons/ProfileActivityTest.kt:64:32 Missing spacing after ","
java/fr/free/nrw/commons/ProfileActivityTest.kt:64:36 Missing spacing after ","
java/fr/free/nrw/commons/ProfileActivityTest.kt:64:41 Missing spacing after ","
java/fr/free/nrw/commons/ProfileActivityTest.kt:68:1 Unexpected blank line(s) before "}"
java/fr/free/nrw/commons/ReviewActivityTest.kt:1:1 File must end with a newline (\n)
java/fr/free/nrw/commons/ReviewActivityTest.kt:20:1 Unexpected blank line(s) before "}"
java/fr/free/nrw/commons/SearchActivityTest.kt:1:1 File must end with a newline (\n)
java/fr/free/nrw/commons/SettingsActivityLoggedInTest.kt:1:1 File must end with a newline (\n)
java/fr/free/nrw/commons/SettingsActivityLoggedInTest.kt:64:1 Unexpected blank line(s) before "}"
java/fr/free/nrw/commons/ui/PasteSensitiveTextInputEditTextTest.kt:1:1 File must end with a newline (\n)
java/fr/free/nrw/commons/ui/PasteSensitiveTextInputEditTextTest.kt:26:40 Missing spacing before "{"
java/fr/free/nrw/commons/ui/PasteSensitiveTextInputEditTextTest.kt:28:43 Argument should be on a separate line (unless all arguments can fit a single line)
java/fr/free/nrw/commons/ui/PasteSensitiveTextInputEditTextTest.kt:28:64 Argument should be on a separate line (unless all arguments can fit a single line)
java/fr/free/nrw/commons/ui/PasteSensitiveTextInputEditTextTest.kt:28:87 Missing newline before ")"
java/fr/free/nrw/commons/ui/PasteSensitiveTextInputEditTextTest.kt:28:88 Missing newline before ")"
java/fr/free/nrw/commons/UITestHelper.kt:1:1 File must end with a newline (\n)
java/fr/free/nrw/commons/UITestHelper.kt:13:1 Wildcard import (cannot be auto-corrected)
java/fr/free/nrw/commons/UITestHelper.kt:16:1 Needless blank line(s)
java/fr/free/nrw/commons/UITestHelper.kt:23:17 Missing space after //
java/fr/free/nrw/commons/UITestHelper.kt:32:17 Missing space after //
java/fr/free/nrw/commons/UITestHelper.kt:35:63 Argument should be on a separate line (unless all arguments can fit a single line)
java/fr/free/nrw/commons/UITestHelper.kt:43:68 Argument should be on a separate line (unless all arguments can fit a single line)
java/fr/free/nrw/commons/UITestHelper.kt:60:17 Missing space after //
java/fr/free/nrw/commons/UITestHelper.kt:79:1 Unexpected blank line(s) before "}"
java/fr/free/nrw/commons/UITestHelper.kt:99:64 Argument should be on a separate line (unless all arguments can fit a single line)
java/fr/free/nrw/commons/UITestHelper.kt:111:68 Argument should be on a separate line (unless all arguments can fit a single line)
java/fr/free/nrw/commons/UITestHelper.kt:127:43 Parameter should be on a separate line (unless all parameters can fit a single line)
java/fr/free/nrw/commons/UITestHelper.kt:129:1 First line in a method block should not be empty
java/fr/free/nrw/commons/UITestHelper.kt:139:1 Unexpected indentation (28) (should be 24)
java/fr/free/nrw/commons/UITestHelper.kt:139:29 Line must not begin with "&&"
java/fr/free/nrw/commons/UITestHelper.kt:157:20 Missing { ... }
java/fr/free/nrw/commons/UITestHelper.kt:164:20 Missing { ... }
java/fr/free/nrw/commons/UploadCancelledTest.kt:7:1 Wildcard import (cannot be auto-corrected)
java/fr/free/nrw/commons/UploadCancelledTest.kt:51:1 Unexpected blank line(s) before "}"
java/fr/free/nrw/commons/UploadCancelledTest.kt:51:1 First line in a method block should not be empty
java/fr/free/nrw/commons/UploadCancelledTest.kt:67:1 Unexpected blank line(s) before "}"
java/fr/free/nrw/commons/UploadCancelledTest.kt:67:1 First line in a method block should not be empty
java/fr/free/nrw/commons/UploadCancelledTest.kt:73:1 First line in a method block should not be empty
java/fr/free/nrw/commons/UploadCancelledTest.kt:107:44 Unnecessary trailing comma before ")"
java/fr/free/nrw/commons/UploadCancelledTest.kt:122:58 Unnecessary trailing comma before ")"
java/fr/free/nrw/commons/UploadCancelledTest.kt:178:45 Unnecessary trailing comma before ")"
java/fr/free/nrw/commons/UploadTest.kt:1:1 File must end with a newline (\n)
java/fr/free/nrw/commons/UploadTest.kt:22:1 Wildcard import (cannot be auto-corrected)
java/fr/free/nrw/commons/UploadTest.kt:32:1 Wildcard import (cannot be auto-corrected)
java/fr/free/nrw/commons/UploadTest.kt:45:52 Argument should be on a separate line (unless all arguments can fit a single line)
java/fr/free/nrw/commons/UploadTest.kt:45:52 Missing newline after "("
java/fr/free/nrw/commons/UploadTest.kt:46:1 Unexpected indentation (12) (should be 8)
java/fr/free/nrw/commons/UploadTest.kt:46:52 Missing newline before ")"
java/fr/free/nrw/commons/UploadTest.kt:46:53 Missing newline before ")"
java/fr/free/nrw/commons/UploadTest.kt:64:1 Unexpected blank line(s) before "}"
java/fr/free/nrw/commons/UploadTest.kt:64:1 First line in a method block should not be empty
java/fr/free/nrw/commons/UploadTest.kt:97:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:100:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:102:1 Needless blank line(s)
java/fr/free/nrw/commons/UploadTest.kt:104:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:112:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:118:1 Unexpected indentation (20) (should be 16)
java/fr/free/nrw/commons/UploadTest.kt:123:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:130:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:135:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:142:1 Unexpected indentation (20) (should be 16)
java/fr/free/nrw/commons/UploadTest.kt:143:1 Unexpected indentation (20) (should be 16)
java/fr/free/nrw/commons/UploadTest.kt:170:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:173:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:181:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:187:1 Unexpected indentation (20) (should be 16)
java/fr/free/nrw/commons/UploadTest.kt:192:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:199:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:204:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:230:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:233:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:234:1 Unexpected indentation (24) (should be 16)
java/fr/free/nrw/commons/UploadTest.kt:234:86 Argument should be on a separate line (unless all arguments can fit a single line)
java/fr/free/nrw/commons/UploadTest.kt:234:86 Missing newline after "("
java/fr/free/nrw/commons/UploadTest.kt:235:1 Unexpected indentation (32) (should be 20)
java/fr/free/nrw/commons/UploadTest.kt:235:123 Missing newline before ")"
java/fr/free/nrw/commons/UploadTest.kt:235:124 Missing newline before ")"
java/fr/free/nrw/commons/UploadTest.kt:235:124 Missing newline before ")"
java/fr/free/nrw/commons/UploadTest.kt:235:125 Missing newline before ")"
java/fr/free/nrw/commons/UploadTest.kt:238:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:241:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:242:1 Unexpected indentation (24) (should be 16)
java/fr/free/nrw/commons/UploadTest.kt:242:86 Argument should be on a separate line (unless all arguments can fit a single line)
java/fr/free/nrw/commons/UploadTest.kt:242:86 Missing newline after "("
java/fr/free/nrw/commons/UploadTest.kt:243:1 Unexpected indentation (32) (should be 20)
java/fr/free/nrw/commons/UploadTest.kt:243:118 Missing newline before ")"
java/fr/free/nrw/commons/UploadTest.kt:243:119 Missing newline before ")"
java/fr/free/nrw/commons/UploadTest.kt:243:119 Missing newline before ")"
java/fr/free/nrw/commons/UploadTest.kt:243:120 Missing newline before ")"
java/fr/free/nrw/commons/UploadTest.kt:246:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:254:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:260:1 Unexpected indentation (20) (should be 16)
java/fr/free/nrw/commons/UploadTest.kt:265:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:272:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:277:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:309:1 Unexpected blank line(s) before "}"
java/fr/free/nrw/commons/UploadTest.kt:331:1 Unexpected indentation (20) (should be 16)
java/fr/free/nrw/commons/UploadTest.kt:332:1 Unexpected indentation (20) (should be 16)
java/fr/free/nrw/commons/UploadTest.kt:340:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/UploadTest.kt:344:1 Unexpected indentation (16) (should be 12)
java/fr/free/nrw/commons/util/MyViewAction.kt:1:1 File must end with a newline (\n)
java/fr/free/nrw/commons/util/MyViewAction.kt:62:1 Unexpected blank line(s) before "}"
java/fr/free/nrw/commons/WelcomeActivityTest.kt:1:1 File must end with a newline (\n)
java/fr/free/nrw/commons/WelcomeActivityTest.kt:6:1 Unused import

@neeldoshii neeldoshii linked a pull request Mar 8, 2024 that will close this issue
@nicolas-raoul
Copy link
Member

Created issue: #5662

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants