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

Issue 116 Name and Reuse Repeating Conditions #131

Merged
merged 24 commits into from
May 28, 2019
Merged

Conversation

GulderBone
Copy link
Contributor

fixes #116

Copy link

@sonarcloud sonarcloud bot left a comment

Choose a reason for hiding this comment

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

SonarQube analysis found issues:
Bug Bugs: 0
Vulnerability Vulnerabilities: 0
Code Smell Code Smells: 24

See all issues in SonarCloud

Copy link

@sonarcloud sonarcloud bot left a comment

Choose a reason for hiding this comment

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

SonarQube analysis found issues:
Bug Bugs: 0
Vulnerability Vulnerabilities: 0
Code Smell Code Smells: 24

See all issues in SonarCloud

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 97.078% when pulling add2194 on issue-116 into d323652 on master.

@coveralls
Copy link

coveralls commented Oct 30, 2018

Coverage Status

Coverage increased (+0.08%) to 95.559% when pulling a8b8904 on issue-116 into 45acc12 on master.

# Conflicts:
#	src/test/java/com/cognifide/aemrules/htl/HtlProfileTest.java
Copy link

@sonarcloud sonarcloud bot left a comment

Choose a reason for hiding this comment

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

SonarQube analysis found issues:
Bug Bugs: 0
Vulnerability Vulnerabilities: 0
Code Smell Code Smells: 8

See all issues in SonarCloud

@@ -0,0 +1,25 @@
Always Place HTL Attributes After the Ones that are Part of the Markup
Copy link
Contributor

Choose a reason for hiding this comment

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

This description is actually for different rule!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to: Always try to re-use existing conditions, so the code is more readable.

@chutch chutch added this to In progress in AEM Rules Nov 5, 2018
README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@michaltobiasz michaltobiasz left a comment

Choose a reason for hiding this comment

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

Please check comments

@chutch
Copy link
Contributor

chutch commented Nov 7, 2018

I think that the previous implementation was better and needed a tweak. It's hard to understand current approach.


@Override
public void startHtlElement(List<Expression> expressions, TagNode node) {
if (isConditionReused(expressions, node)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This time also, the method name is misleading since "reused" has a positive connotation whereas in your case reused means "the same condition used couple of times needlessly".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Conditions inverted and method name changed to isConditionReusedCorrectly().

private Set<String> namedConditions = new HashSet<>();

@Override
public void startHtlElement(List<Expression> expressions, TagNode node) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This API has to be rewritten as it decouples expression from the attribute.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@piotr-wilczynski You should take a look at this :)

Copy link
Contributor

Choose a reason for hiding this comment

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

this method is giving You all of the expressions that exists in node, but if You want the have relation between attribute and expresion You can always check if there is any expression in the attribute and proceed somehow. There is a method called htlExpression default void htlExpression(Expression expression, Node node) It is probably what You are looking for @chutch ?

@GulderBone GulderBone self-assigned this May 10, 2019
private boolean isConditionReused(List<Expression> expressions, TagNode node) {
String condition = expressions.stream()
.map(Expression::getRawText)
.map(text -> text.replaceAll("[${}]", ""))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please extract 'getRawText' and 'text.replaceAll("[${}]", "")' to method and reuse it in '103' line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted
private Set<String> clearExpressions(List<Expression> expressions){ return expressions.stream() .map(Expression::getRawText) .map(text -> text.replaceAll("[${}]", "")) .collect(Collectors.toSet()); }

.filter(text -> text.contains(SLY_TEST))
.findFirst();
if (condition.isPresent() && !condition.get().equals(SLY_TEST)) {
condition = Optional.of(condition.get().substring(14));
Copy link
Contributor

Choose a reason for hiding this comment

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

what is 14?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

<!--/* Bad - the same condition is evaluated multiple times */-->
<span class="uber-mode__top-bar" data-sly-test="${uberModeHelper.uberModeEnabled || forceUberMode}">
<div class="my-component">
Blah blah blah
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe ... ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

private Set<String> namedConditions = new HashSet<>();

@Override
public void startHtlElement(List<Expression> expressions, TagNode node) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this method is giving You all of the expressions that exists in node, but if You want the have relation between attribute and expresion You can always check if there is any expression in the attribute and proceed somehow. There is a method called htlExpression default void htlExpression(Expression expression, Node node) It is probably what You are looking for @chutch ?

@ParsingErrorRule
public class NamingAndReusingConditionsCheck extends AbstractHtlCheck {

static final String RULE_KEY = "HTL-4";
Copy link
Collaborator

Choose a reason for hiding this comment

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

You define HTL-4 rule key, but doc file is named HTL-5, why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

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

Successfully merging this pull request may close these issues.

Name and Reuse Repeating Conditions
7 participants