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

DebugPrintRule #1314

Merged
merged 14 commits into from
May 31, 2022
Merged

DebugPrintRule #1314

merged 14 commits into from
May 31, 2022

Conversation

nulls
Copy link
Member

@nulls nulls commented May 27, 2022

Which rule and warnings did you add?

Detect println and print in code -- assumption that it's a debug logging

This pull request closes #954

Actions checklist

  • Implemented Rule, added Warnings
  • Added tests on checks
  • Added tests on fixers
  • Updated diktat-analysis.yml
  • Updated available-rules.md

Fixme

nulls added 3 commits May 27, 2022 19:01
### What's done:
* initial changes
### What's done:
* supported detection of print\println
### What's done:
* fixed diktat findings
@codecov
Copy link

codecov bot commented May 30, 2022

Codecov Report

Merging #1314 (51e1b65) into master (8aae73e) will increase coverage by 0.02%.
The diff coverage is 86.11%.

@@             Coverage Diff              @@
##             master    #1314      +/-   ##
============================================
+ Coverage     82.01%   82.03%   +0.02%     
- Complexity     2538     2561      +23     
============================================
  Files           105      106       +1     
  Lines          7239     7275      +36     
  Branches       2071     2085      +14     
============================================
+ Hits           5937     5968      +31     
  Misses          354      354              
- Partials        948      953       +5     
Flag Coverage Δ
unittests 82.03% <86.11%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...fn/diktat/ruleset/rules/chapter3/DebugPrintRule.kt 85.29% <85.29%> (ø)
...tlin/org/cqfn/diktat/ruleset/constants/Warnings.kt 98.07% <100.00%> (+0.01%) ⬆️
...cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt 97.01% <100.00%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8aae73e...51e1b65. Read the comment docs.

@nulls nulls marked this pull request as ready for review May 30, 2022 09:04
@nulls nulls enabled auto-merge (squash) May 30, 2022 09:40
| Chap | Standard | Rule name | Description | Fix | Config | FixMe |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw - why do we see changes here? Line ending again?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like, also IDEA adds additional - to header.
Will look at it

@@ -136,6 +136,7 @@ enum class Warnings(
FILE_NAME_MATCH_CLASS(true, "3.1.2", "file name is incorrect - it should match with the class described in it if there is the only one class declared"),
COLLAPSE_IF_STATEMENTS(true, "3.16.1", "avoid using redundant nested if-statements, which could be collapsed into a single one"),
CONVENTIONAL_RANGE(true, "3.17.1", "use conventional rule for range case"),
DEBUG_PRINT(false, "3.18.1", "avoid using print()/println() or console.log() for debug logging"),
Copy link
Member

@orchestr7 orchestr7 May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please also add a description to a code style (chapter 3).
Something like:

Try to avoid the usage of print methods directly, use loggers instead, blabla

) {
override fun logic(node: ASTNode) {
// check kotlin.io.print()/kotlin.io.println()
if (node.elementType == ElementType.CALL_EXPRESSION) {
Copy link
Member

@orchestr7 orchestr7 May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we will have when by elementType?
And move logic in these branches of when to separate methods - method for console and method for print?

Sorry for this note, depends on you

@@ -136,6 +136,7 @@ enum class Warnings(
FILE_NAME_MATCH_CLASS(true, "3.1.2", "file name is incorrect - it should match with the class described in it if there is the only one class declared"),
COLLAPSE_IF_STATEMENTS(true, "3.16.1", "avoid using redundant nested if-statements, which could be collapsed into a single one"),
CONVENTIONAL_RANGE(true, "3.17.1", "use conventional rule for range case"),
DEBUG_PRINT(false, "3.18.1", "avoid using print()/println() or console.log() for debug logging"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could reword the message: don't mention particular method names (they will be available when the whole warning text is generated) and instead suggest to use a dedicated logging library

@orchestr7
Copy link
Member

Lgtm

@nulls nulls merged commit 9423868 into master May 31, 2022
@nulls nulls deleted the feature/debug_print#954 branch May 31, 2022 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detection of debug prints
3 participants