is there a way to disable some code inspections fo...
# intellij
c
is there a way to disable some code inspections for the test root? for example “Property could be private” is something I don’t care about in unit tests.
m
put
@Suppress("MemberVisibilityCanBePrivate")
on your test class?
w
m
Or do you want this for all tests?
c
i think it would be a great default for all tests
@wasyl thats great, is there a way to specify it in the gradle file? currently i have my whole .idea directory in .gitignore
Test cases don’t export an api, and test cases usually also don’t rely on each other, so visibility modifiers are not needed imo and just add verbosity
w
I don’t think so. I never cared because for codestyle I use KtLint/Detekt anyway, IntelliJ intentions are difficult to run on CI
c
can i configure that in ktlint?
w
And I strongly believe such code style stuff must be enforced by CI. If it’s not then the effort to enforce it is not worth it 😉
c
it should probably not only be enforced but even automated
👌 1
w
can i configure that in ktlint?
You’d have to define test roots somehow. So I’d guess you could take
/test/
directory under consideration, but it might not be 100% consistent with what you configure in Gradle, like if you add another test source directory
c
i think there was one kotlin linter that disallowed * imports thats why i did not investigate further
but maybe it wasnt ktlint and maybe thats better now.
w
Might be, it wasn’t configurable at all back then. Now I think you should be able to use star imports
in Android projects I like Android Lint, it’s a bit heavier than KtLint and Detekt, but is very powerful
c
for non android would you recommend ktlint and detekt or just one? I think the idea-plugin-template project uses ktlint and detekt, and i wondered why it needs 2 linters
w
But if you want to just make sure there’s no
private
keyword anywhere under
src/test/
KtLint should do the job. Maybe you can even configure it to only use custom rules? Not sure
c
if I use it i will probably also want it to autoformat the sourcecode
w
You can have autoformatting for custom rules too
c
and then i just turn off autoformatting and checks in idea? or can i run ktlint via a plugin?
w
KtLint -> intended to check pure codestyle like naming, using keywords, spaces around tokens etc. Detekt -> more sophisticated and now also uses types for checking. It has stuff like complexity checks, checks for unused members, using
if
vs
when
.
and then i just turn off autoformatting and checks in idea? or can i run ktlint via a plugin?
🤔 We don’t use many custom rules and our codestyle.xml is consistent with KtLint’s rules. So what we do is run
./gradlew formatKotlin
locally to fix issues, and
./gradlew lintKotlin
on CI. The checks aren’t integrated in IDE
c
I think i want just the default kotlin style with star imports and no private in tests root
not too much bike shedding 🙂
w
well, some bikeshedding 😄 I suppose you should just try ktlint and see if it works for you
But the API to create custom rules has some learning curve, if you haven’t worked with Psi before. I recommend
PsiViewer
plugin
c
thanks!
👍 1