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

Suppress remove curly braces from template #157 #263

Conversation

AleksandrSl
Copy link
Contributor

No description provided.

@AleksandrSl
Copy link
Contributor Author

Hi! What about this one, should I modify something?

@AleksandrSl
Copy link
Contributor Author

Hi @shashachu, is this issue still needed to be done? If so I can resolve merge conflicts, otherwise I think it's time to close PR and issue)

@shashachu
Copy link
Contributor

Hi, sorry about that. Can you resolve the conflicts and then I or someone else here will take a look.

Copy link
Contributor

@NightlyNexus NightlyNexus left a comment

Choose a reason for hiding this comment

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

looks good after conflicts are resolved

@AleksandrSl AleksandrSl force-pushed the feature/suppress-remove-curly-braces-from-template branch from 611efb7 to c66826e Compare May 3, 2019 13:00
@AleksandrSl
Copy link
Contributor Author

@NightlyNexus I think all work is done, any other comments?

@AleksandrSl
Copy link
Contributor Author

Hi, sorry to bother you again) Is there a reason that prevents PR from being merged?

@shashachu
Copy link
Contributor

Hi, sorry to bother you again) Is there a reason that prevents PR from being merged?

Hi! No, this PR just fell through the cracks.

@shashachu
Copy link
Contributor

Hi, sorry to bother you again) Is there a reason that prevents PR from being merged?

Hi! No, this PR just fell through the cracks.

Can you rebase and just make sure the build still passes? I can merge after.

@AleksandrSl AleksandrSl force-pushed the feature/suppress-remove-curly-braces-from-template branch from fa3f64b to 68866bd Compare August 31, 2019 07:32
@@ -490,6 +515,12 @@ object KtLint {
comment.replace(Regex("\\s"), " ").replace(" {2,}", " ").split(" ")

private fun <T> List<T>.tail() = this.subList(1, this.size)

private val suppressAnnotationRuleMap = mapOf(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this map could be moved to some config file, to ease addition of new suppression
rules

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure about having this mapping:

  • "RemoveCurlyBracesFromTemplate" just becomes an alias to "string-template" rule
  • This alias is detached from the rule itself
  • Overall this PR goes into direction of adding another way for suppress rules

To be consistent, I would propose to use following approach:

@Suppress("ktlint-string-template")

to disable rule for the block of code and remove this map.

Copy link
Contributor Author

@AleksandrSl AleksandrSl Nov 6, 2019

Choose a reason for hiding this comment

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

I agree that this map looks weird, however original purpose for this PR was to respect annotations like @Suppress("RemoveCurlyBracesFromTemplate") to disable both IntellijIDEA and ktlint checks at the same time. Otherwise we will have to add both annotations

@Suppress("ktlint-string-template")
@Suppress("RemoveCurlyBracesFromTemplate")
println("Not found: ${notFound}")

and this way all sense in introduction of support for @Suppress annotation seems lost to me, cause it becomes specific for ktlint, and as you mentioned we already have ways to suppress ktlint checks

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree that this map looks weird, however original purpose for this PR was to respect annotations like @Suppress("RemoveCurlyBracesFromTemplate") to disable both IntellijIDEA and ktlint checks at the same time.

Sorry, missed that. Then, as intermediate step, having this map looks ok. In the future would be better that rule provides a list of suppress names aliases.

@AleksandrSl
Copy link
Contributor Author

Done!

Comment on lines 473 to 493
// Extract all Suppress annotations and create SuppressionHints
val psi = node.psi
if (psi is KtAnnotated) {
psi.annotationEntries
.filter {
it.calleeExpression?.constructorReferenceExpression
?.getReferencedName() in suppressAnnotations
}.flatMap(KtAnnotationEntry::getValueArguments)
.mapNotNull { it.getArgumentExpression()?.text?.removeSurrounding("\"") }
.mapNotNull(suppressAnnotationRuleMap::get)
.let { suppressedRules ->
if (suppressedRules.isNotEmpty()) {
result.add(
SuppressionHint(
IntRange(psi.startOffset, psi.endOffset),
suppressedRules.toSet()
)
)
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: could you move this to some private method for better readability?

@@ -490,6 +515,12 @@ object KtLint {
comment.replace(Regex("\\s"), " ").replace(" {2,}", " ").split(" ")

private fun <T> List<T>.tail() = this.subList(1, this.size)

private val suppressAnnotationRuleMap = mapOf(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure about having this mapping:

  • "RemoveCurlyBracesFromTemplate" just becomes an alias to "string-template" rule
  • This alias is detached from the rule itself
  • Overall this PR goes into direction of adding another way for suppress rules

To be consistent, I would propose to use following approach:

@Suppress("ktlint-string-template")

to disable rule for the block of code and remove this map.

AleksandrSl and others added 11 commits November 7, 2019 10:01
Try top down approach. I need line numbers for suppression, it's not
so trivial. Why not use offset for suppression?
Current flow is that all string-template errors are suppressed by
RemoveCurlyBracesFromTemplate.
It turned out that @Suppress with arrayOf and [] are
compile errors, and can be used only with destructuring.
Add more test for different annotations use sites.
Shame on me, forgot to remove "debugging" code
Distinct is redundant, cause toSet is called on the list
afterwards.
@AleksandrSl AleksandrSl force-pushed the feature/suppress-remove-curly-braces-from-template branch from 68866bd to 4ee8253 Compare November 7, 2019 07:02
Copy link
Collaborator

@Tapchicoma Tapchicoma left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!

@Tapchicoma Tapchicoma merged commit baac14c into pinterest:master Nov 11, 2019
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.

4 participants