Skip to content

Commit

Permalink
Introduce Code Formatting (#44)
Browse files Browse the repository at this point in the history
* Add Java code formatting configuration
* Format Java code
* Add prettier for formatting client-side JavaScript code
* Apply prettier formatting
* Restore minified handlebars library
* Fix RAT
* Manual formatting fixes
  • Loading branch information
herzog31 committed Jun 12, 2019
1 parent db66f51 commit 401dd4a
Show file tree
Hide file tree
Showing 68 changed files with 1,175 additions and 694 deletions.
13 changes: 13 additions & 0 deletions README.md
Expand Up @@ -68,6 +68,19 @@ npm test

Karma will test with Chrome and Firefox. Make sure you have both browsers installed.

## Code Formatting
### Java
You can find the code formatting rules in the `eclipse-formatter.xml` file. The code formatting is automatically checked for each build. To automatically format your code, please run:
```bash
mvn clean install -Pformat-code
```

### JavaScript & CSS
For formatting JavaScript and CSS we use [prettier](https://prettier.io/). The formatting is automatically checked when running `npm test` in the `ui.apps` project. To automatically format your code, please run the following command in `ui.apps`:
```bash
npm run prettier-fix
```

## Contributing

Contributions are welcomed! Read the [Contributing Guide](.github/CONTRIBUTING.md) for more information.
Expand Down
11 changes: 11 additions & 0 deletions bundles/core/pom.xml
Expand Up @@ -56,6 +56,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jacoco.data.file>${project.build.directory}/jacoco.exec</jacoco.data.file>
<formatter.config>../../eclipse-formatter.xml</formatter.config>
</properties>

<build>
Expand Down Expand Up @@ -98,6 +99,16 @@
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

Expand Down
Expand Up @@ -27,7 +27,7 @@
@Model(adaptables = SlingHttpServletRequest.class, adapters = HeroImage.class, resourceType = HeroImageImpl.RESOURCE_TYPE)
public class HeroImageImpl implements HeroImage {

protected static final String RESOURCE_TYPE="venia/components/content/heroimage/v1/heroimage";
protected static final String RESOURCE_TYPE = "venia/components/content/heroimage/v1/heroimage";
private static final String PN_FULL_WIDTH = "useFullWidth";

@Self
Expand Down Expand Up @@ -66,7 +66,7 @@ public String getImageSrc() {
return image.getSrc();
}
com.adobe.cq.wcm.core.components.models.Image image = request.adaptTo(com.adobe.cq.wcm.core.components.models.Image.class);
if(image != null) {
if (image != null) {
this.image = new CifHeroImage(image.getSrc());
}
return this.image.getSrc();
Expand Down
Expand Up @@ -14,13 +14,13 @@

package com.adobe.cq.commerce.core.components.internal.models.v1;

import javax.annotation.Nullable;
import java.text.NumberFormat;
import java.util.Currency;
import java.util.Locale;

import javax.annotation.Nullable;

import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -39,15 +39,14 @@ public class Utils {
*/
static final String PN_NAV_ROOT = "navRoot";

private Utils() {
}
private Utils() {}

/**
* Builds a NumberFormat instance used for formatting prices based on the given
* locale and currency code. If the given currency code is not valid in respect to
* ISO 4217, the default currency for the given locale is used.
*
* @param locale Price locale
* @param locale Price locale
* @param currencyCode Additional currency code
* @return Price formatter
*/
Expand Down Expand Up @@ -99,7 +98,7 @@ public static Page getSearchResultsPage(Page page) {
*
* @param page the page
*
* @return the navigation root page if found, otherwise {@code null}
* @return the navigation root page if found, otherwise {@code null}
*/
@Nullable
public static Page getNavigationRootPage(Page page) {
Expand Down Expand Up @@ -138,7 +137,8 @@ private static Page getGenericPage(String pageTypeProperty, Page page) {
}
return categoryPage;
}
public static String constructUrlfromSlug(String pagePath, String slug){

public static String constructUrlfromSlug(String pagePath, String slug) {
return String.format("%s.%s.html", pagePath, slug);
}

Expand Down
Expand Up @@ -21,29 +21,26 @@
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Source;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.ScriptVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.cq.commerce.core.components.internal.models.v1.Utils;
import com.adobe.cq.commerce.core.components.models.header.Header;
import com.adobe.xfa.ut.StringUtils;
import com.day.cq.wcm.api.Page;
import com.drew.lang.StringUtil;

/**
* Concrete implementation of the Sling Model API for the Header component
*
* @see Header
*/
@Model(adaptables = SlingHttpServletRequest.class,
adapters = Header.class,
resourceType = HeaderImpl.RESOURCE_TYPE)
@Model(
adaptables = SlingHttpServletRequest.class,
adapters = Header.class,
resourceType = HeaderImpl.RESOURCE_TYPE)
public class HeaderImpl implements Header {
private static final Logger LOGGER = LoggerFactory.getLogger(HeaderImpl.class);

static final String RESOURCE_TYPE = "venia/components/structure/header/v1/header" ;
static final String RESOURCE_TYPE = "venia/components/structure/header/v1/header";
static final String MINICART_NODE_NAME = "minicart";

@Inject
Expand All @@ -52,7 +49,7 @@ public class HeaderImpl implements Header {
@Inject
private Resource resource;

@Inject
@Inject
private String minicartNodeName;

private Page searchResultsPage;
Expand All @@ -64,7 +61,7 @@ public String getSearchResultsPageUrl() {
searchResultsPage = Utils.getSearchResultsPage(currentPage);
}

return searchResultsPage.getPath()+".html";
return searchResultsPage.getPath() + ".html";
}

@Override
Expand Down
Expand Up @@ -39,9 +39,9 @@
import com.day.cq.wcm.api.PageManager;

@Model(
adaptables = SlingHttpServletRequest.class,
adapters = Navigation.class,
resourceType = NavigationImpl.RESOURCE_TYPE)
adaptables = SlingHttpServletRequest.class,
adapters = Navigation.class,
resourceType = NavigationImpl.RESOURCE_TYPE)
public class NavigationImpl implements Navigation {
private static final Logger LOGGER = LoggerFactory.getLogger(NavigationImpl.class);
static final String PN_MAGENTO_ROOT_CATEGORY_ID = "magentoRootCategoryId";
Expand Down Expand Up @@ -107,7 +107,7 @@ private boolean shouldExpandCatalogRoot(Page page) {

private void expandCatalogRoot(Page catalogPage, List<NavigationItem> pages) {
Page categoryPage = Utils.getCategoryPage(currentPage);
if (categoryPage == null){
if (categoryPage == null) {
return;
}

Expand Down
Expand Up @@ -32,31 +32,35 @@ public class AssetImpl implements Asset {

private String path;

@Override public String getLabel() {
@Override
public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

@Override public Integer getPosition() {
@Override
public Integer getPosition() {
return position;
}

public void setPosition(Integer position) {
this.position = position;
}

@Override public String getType() {
@Override
public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

@Override public String getPath() {
@Override
public String getPath() {
return path;
}

Expand Down
Expand Up @@ -98,7 +98,7 @@ private void initModel() {

// Get MagentoGraphqlClient from the resource.
magentoGraphqlClient = MagentoGraphqlClient.create(resource);

// Fetch product data
if (magentoGraphqlClient != null) {
product = fetchProduct(slug);
Expand Down Expand Up @@ -274,8 +274,7 @@ public ProductInterfaceQueryDefinition generateProductQuery() {
.variants(v -> v
.attributes(a -> a
.code()
.valueIndex()
)
.valueIndex())
.product(generateSimpleProductQuery())));
}

Expand Down Expand Up @@ -384,7 +383,8 @@ private ProductInterface fetchProduct(String slug) {
List<ProductInterface> products = rootQuery.getProducts().getItems();

// TODO WORKAROUND
// we need a temporary detour and use storeconfig to get the base media url since the product media gallery only returns the images file names but no full URLs
// we need a temporary detour and use storeconfig to get the base media url since the product media gallery only returns the images
// file names but no full URLs
mediaBaseUrl = rootQuery.getStoreConfig().getSecureBaseMediaUrl();

// Return first product in list
Expand Down
Expand Up @@ -14,11 +14,11 @@

package com.adobe.cq.commerce.core.components.internal.models.v1.product;

import java.util.List;

import com.adobe.cq.commerce.core.components.models.product.VariantAttribute;
import com.adobe.cq.commerce.core.components.models.product.VariantValue;

import java.util.List;

public class VariantAttributeImpl implements VariantAttribute {

private String label;
Expand All @@ -27,23 +27,26 @@ public class VariantAttributeImpl implements VariantAttribute {

private List<VariantValue> values;

@Override public String getLabel() {
@Override
public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

@Override public String getId() {
@Override
public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

@Override public List<VariantValue> getValues() {
@Override
public List<VariantValue> getValues() {
return values;
}

Expand Down

0 comments on commit 401dd4a

Please sign in to comment.