Skip to content

chore(style): add editorconfig for easier configuration #1098

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
tab_width = 4
trim_trailing_whitespace = true

ij_continuation_indent_size = 8

[*.md]
max_line_length = off
trim_trailing_whitespace = false

# Following the rules of the Google Java Style Guide.
# See https://google.github.io/styleguide/javaguide.html
[*.java]
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to get a linter in CI which applies these same requirements? I'd prefer to not rely on someone's editor obeying this config for style correctness.

Copy link
Member Author

Choose a reason for hiding this comment

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

There is still checkstyle in place, which enforces proper styling, but it reduces the pain for new contributors if they have a different code style setup in IntelliJ. For example I see regular people changing to star imports with auto-formatting - which does not need to be the case.

max_line_length = 120

ij_java_do_not_wrap_after_single_annotation_in_parameter = true
ij_java_insert_inner_class_imports = false
ij_java_class_count_to_use_import_on_demand = 999
ij_java_names_count_to_use_import_on_demand = 999
ij_java_packages_to_use_import_on_demand = unset
ij_java_imports_layout = $*,|,*
ij_java_doc_align_param_comments = true
ij_java_doc_align_exception_comments = true
ij_java_doc_add_p_tag_on_empty_lines = false
ij_java_doc_do_not_wrap_if_one_line = true
ij_java_doc_keep_empty_parameter_tag = false
ij_java_doc_keep_empty_throws_tag = false
ij_java_doc_keep_empty_return_tag = false
ij_java_doc_preserve_line_breaks = true
ij_java_doc_indent_on_continuation = true
ij_java_keep_control_statement_in_one_line = false
ij_java_keep_blank_lines_in_code = 1
ij_java_align_multiline_parameters = false
ij_java_align_multiline_resources = false
ij_java_align_multiline_for = true
ij_java_space_before_array_initializer_left_brace = true
ij_java_call_parameters_wrap = normal
ij_java_method_parameters_wrap = normal
ij_java_extends_list_wrap = normal
ij_java_throws_keyword_wrap = normal
ij_java_method_call_chain_wrap = normal
ij_java_binary_operation_wrap = normal
ij_java_binary_operation_sign_on_next_line = true
ij_java_ternary_operation_wrap = normal
ij_java_ternary_operation_signs_on_next_line = true
ij_java_keep_simple_methods_in_one_line = true
ij_java_keep_simple_lambdas_in_one_line = true
ij_java_keep_simple_classes_in_one_line = true
ij_java_for_statement_wrap = normal
ij_java_array_initializer_wrap = normal
ij_java_wrap_comments = true
ij_java_if_brace_force = always
ij_java_do_while_brace_force = always
ij_java_while_brace_force = always
ij_java_for_brace_force = always
ij_java_space_after_closing_angle_bracket_in_type_argument = false

[{*.json,*.json5}]
indent_size = 2
tab_width = 2
ij_smart_tabs = false

[*.yaml]
indent_size = 2
tab_width = 2
2 changes: 1 addition & 1 deletion src/main/java/dev/openfeature/sdk/AbstractStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.HashMap;
import java.util.Map;

@SuppressWarnings({ "PMD.BeanMembersShouldSerialize", "checkstyle:MissingJavadocType" })
@SuppressWarnings({"PMD.BeanMembersShouldSerialize", "checkstyle:MissingJavadocType"})
abstract class AbstractStructure implements Structure {

protected final Map<String, Value> attributes;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/dev/openfeature/sdk/BaseEvaluation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,42 @@

/**
* This is a common interface between the evaluation results that providers return and what is given to the end users.
*
* @param <T> The type of flag being evaluated.
*/
public interface BaseEvaluation<T> {
/**
* Returns the resolved value of the evaluation.
*
* @return {T} the resolve value
*/
T getValue();

/**
* Returns an identifier for this value, if applicable.
*
* @return {String} value identifier
*/
String getVariant();

/**
* Describes how we came to the value that we're returning.
*
* @return {Reason}
*/
String getReason();

/**
* The error code, if applicable. Should only be set when the Reason is ERROR.
*
* @return {ErrorCode}
*/
ErrorCode getErrorCode();

/**
* The error message (usually from exception.getMessage()), if applicable.
* Should only be set when the Reason is ERROR.
*
* @return {String}
*/
String getErrorMessage();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/openfeature/sdk/BooleanHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
* to the lifecycle of flag evaluation.
*
*
* @see Hook
*/
public interface BooleanHook extends Hook<Boolean> {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/dev/openfeature/sdk/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ public interface Client extends Features, EventBus<Client> {

/**
* Return an optional client-level evaluation context.
*
* @return {@link EvaluationContext}
*/
EvaluationContext getEvaluationContext();

/**
* Set the client-level evaluation context.
*
* @param ctx Client level context.
*/
Client setEvaluationContext(EvaluationContext ctx);
Expand All @@ -30,12 +32,14 @@ public interface Client extends Features, EventBus<Client> {

/**
* Fetch the hooks associated to this client.
*
* @return A list of {@link Hook}s.
*/
List<Hook> getHooks();

/**
* Returns the current state of the associated provider.
*
* @return the provider state
*/
ProviderState getProviderState();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/openfeature/sdk/DoubleHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
* to the lifecycle of flag evaluation.
*
*
* @see Hook
*/
public interface DoubleHook extends Hook<Double> {
Expand All @@ -12,4 +12,4 @@ public interface DoubleHook extends Hook<Double> {
default boolean supportsFlagValueType(FlagValueType flagValueType) {
return FlagValueType.DOUBLE == flagValueType;
}
}
}
26 changes: 13 additions & 13 deletions src/main/java/dev/openfeature/sdk/EventBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,57 @@
* Interface for attaching event handlers.
*/
public interface EventBus<T> {

/**
* Add a handler for the {@link ProviderEvent#PROVIDER_READY} event.
* Shorthand for {@link #on(ProviderEvent, Consumer)}
*
*
* @param handler behavior to add with this event
* @return this
*/
T onProviderReady(Consumer<EventDetails> handler);

/**
* Add a handler for the {@link ProviderEvent#PROVIDER_CONFIGURATION_CHANGED} event.
* Shorthand for {@link #on(ProviderEvent, Consumer)}
*
*
* @param handler behavior to add with this event
* @return this
*/
T onProviderConfigurationChanged(Consumer<EventDetails> handler);

/**
* Add a handler for the {@link ProviderEvent#PROVIDER_STALE} event.
* Shorthand for {@link #on(ProviderEvent, Consumer)}
*
*
* @param handler behavior to add with this event
* @return this
*/
T onProviderError(Consumer<EventDetails> handler);

/**
* Add a handler for the {@link ProviderEvent#PROVIDER_ERROR} event.
* Shorthand for {@link #on(ProviderEvent, Consumer)}
*
*
* @param handler behavior to add with this event
* @return this
*/
T onProviderStale(Consumer<EventDetails> handler);

/**
* Add a handler for the specified {@link ProviderEvent}.
*
* @param event event type
*
* @param event event type
* @param handler behavior to add with this event
* @return this
*/
T on(ProviderEvent event, Consumer<EventDetails> handler);

/**
* Remove the previously attached handler by reference.
* If the handler doesn't exists, no-op.
*
* @param event event type
*
* @param event event type
* @param handler to be removed
* @return this
*/
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/dev/openfeature/sdk/EventSupport.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dev.openfeature.sdk;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -13,6 +11,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import lombok.extern.slf4j.Slf4j;

/**
* Util class for storing and running handlers.
Expand All @@ -35,7 +34,7 @@ class EventSupport {
/**
* Run all the event handlers associated with this domain.
* If the domain is null, handlers attached to unnamed clients will run.
*
*
* @param domain the domain to run event handlers for, or null
* @param event the event type
* @param eventDetails the event details
Expand All @@ -54,7 +53,7 @@ public void runClientHandlers(String domain, ProviderEvent event, EventDetails e

/**
* Run all the API (global) event handlers.
*
*
* @param event the event type
* @param eventDetails the event details
*/
Expand All @@ -67,10 +66,10 @@ public void runGlobalHandlers(ProviderEvent event, EventDetails eventDetails) {

/**
* Add a handler for the specified domain, or all unnamed clients.
*
* @param domain the domain to add handlers for, or else unnamed
* @param event the event type
* @param handler the handler function to run
*
* @param domain the domain to add handlers for, or else unnamed
* @param event the event type
* @param handler the handler function to run
*/
public void addClientHandler(String domain, ProviderEvent event, Consumer<EventDetails> handler) {
final String name = Optional.ofNullable(domain)
Expand All @@ -88,11 +87,11 @@ public void addClientHandler(String domain, ProviderEvent event, Consumer<EventD

/**
* Remove a client event handler for the specified event type.
*
* @param domain the domain of the client handler to remove, or null to remove
* from unnamed clients
* @param event the event type
* @param handler the handler ref to be removed
*
* @param domain the domain of the client handler to remove, or null to remove
* from unnamed clients
* @param event the event type
* @param handler the handler ref to be removed
*/
public void removeClientHandler(String domain, ProviderEvent event, Consumer<EventDetails> handler) {
domain = Optional.ofNullable(domain)
Expand All @@ -102,7 +101,7 @@ public void removeClientHandler(String domain, ProviderEvent event, Consumer<Eve

/**
* Add a global event handler of the specified event type.
*
*
* @param event the event type
* @param handler the handler to be added
*/
Expand All @@ -112,7 +111,7 @@ public void addGlobalHandler(ProviderEvent event, Consumer<EventDetails> handler

/**
* Remove a global event handler for the specified event type.
*
*
* @param event the event type
* @param handler the handler ref to be removed
*/
Expand All @@ -122,7 +121,7 @@ public void removeGlobalHandler(ProviderEvent event, Consumer<EventDetails> hand

/**
* Get all domain names for which we have event handlers registered.
*
*
* @return set of domain names
*/
public Set<String> getAllDomainNames() {
Expand All @@ -131,7 +130,7 @@ public Set<String> getAllDomainNames() {

/**
* Run the passed handler on the taskExecutor.
*
*
* @param handler the handler to run
* @param eventDetails the event details
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package dev.openfeature.sdk;

import dev.openfeature.sdk.exceptions.OpenFeatureError;
import lombok.Getter;

import java.util.concurrent.atomic.AtomicBoolean;
import lombok.Getter;

class FeatureProviderStateManager implements EventProviderListener {
private final FeatureProvider delegate;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/dev/openfeature/sdk/Features.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface Features {
FlagEvaluationDetails<Boolean> getBooleanDetails(String key, Boolean defaultValue, EvaluationContext ctx);

FlagEvaluationDetails<Boolean> getBooleanDetails(String key, Boolean defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options);
FlagEvaluationOptions options);

String getStringValue(String key, String defaultValue);

Expand All @@ -29,7 +29,7 @@ FlagEvaluationDetails<Boolean> getBooleanDetails(String key, Boolean defaultValu
FlagEvaluationDetails<String> getStringDetails(String key, String defaultValue, EvaluationContext ctx);

FlagEvaluationDetails<String> getStringDetails(String key, String defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options);
FlagEvaluationOptions options);

Integer getIntegerValue(String key, Integer defaultValue);

Expand All @@ -42,7 +42,7 @@ FlagEvaluationDetails<String> getStringDetails(String key, String defaultValue,
FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValue, EvaluationContext ctx);

FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options);
FlagEvaluationOptions options);

Double getDoubleValue(String key, Double defaultValue);

Expand All @@ -55,7 +55,7 @@ FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValu
FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx);

FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options);
FlagEvaluationOptions options);

Value getObjectValue(String key, Value defaultValue);

Expand Down
Loading
Loading