Skip to content

Commit

Permalink
chore: sync files with stordco/common-config-elixir (#23)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Blake Kostner <[email protected]>
  • Loading branch information
3 people authored Aug 1, 2023
1 parent d43b381 commit a1360fd
Show file tree
Hide file tree
Showing 20 changed files with 388 additions and 146 deletions.
192 changes: 192 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
# This file is synced with stordco/common-config-elixir. Any changes will be overwritten.

# This file contains the configuration for Credo and you are probably reading
# this after creating it with `mix credo.gen.config`.
#
# If you find anything wrong or unclear in this file, please report an
# issue on GitHub: https://github.com/rrrene/credo/issues
#
%{
#
# You can have as many configs as you like in the `configs:` field.
configs: [
%{
#
# Run any config using `mix credo -C <name>`. If no config name is given
# "default" is used.
#
name: "default",
#
# These are the files included in the analysis:
files: %{
#
# You can give explicit globs or simply directories.
# In the latter case `**/*.{ex,exs}` will be used.
#
included: ["lib/", "priv/", "test/"],
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
},
#
# Load and configure plugins here:
#
plugins: [],
#
# If you create your own checks, you must specify the source files for
# them here, so they can be loaded by Credo before running the analysis.
#
requires: [],
#
# If you want to enforce a style guide and need a more traditional linting
# experience, you can change `strict` to `true` below:
#
strict: true,
#
# To modify the timeout for parsing files, change this value:
#
parse_timeout: 5000,
#
# If you want to use uncolored output by default, you can change `color`
# to `false` below:
#
color: true,
#
# You can customize the parameters of any check by adding a second element
# to the tuple.
#
# To disable a check put `false` as second element:
#
# {Credo.Check.Design.DuplicatedCode, false}
#
checks: [
#
## Database Migration Checks
#
{ExcellentMigrations.CredoCheck.MigrationsSafety, []},

#
## Consistency Checks
#
{Credo.Check.Consistency.ExceptionNames, []},
{Credo.Check.Consistency.LineEndings, []},
{Credo.Check.Consistency.ParameterPatternMatching, []},
{Credo.Check.Consistency.SpaceAroundOperators, []},
{Credo.Check.Consistency.SpaceInParentheses, []},
{Credo.Check.Consistency.TabsOrSpaces, []},

#
## Design Checks
#
# You can customize the priority of any check
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage, [priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 2]},
# You can also customize the exit_status of each check.
# If you don't want TODO comments to cause `mix credo` to fail, just
# set this value to 0 (zero).
#
{Credo.Check.Design.TagTODO, [exit_status: 2]},
{Credo.Check.Design.TagFIXME, []},

#
## Readability Checks
#
{Credo.Check.Readability.AliasOrder, []},
{Credo.Check.Readability.FunctionNames, []},
{Credo.Check.Readability.LargeNumbers, [trailing_digits: 2]},
{Credo.Check.Readability.MaxLineLength, false},
{Credo.Check.Readability.ModuleAttributeNames, []},
{Credo.Check.Readability.ModuleDoc, false},
{Credo.Check.Readability.ModuleNames, []},
{Credo.Check.Readability.ParenthesesInCondition, []},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{Credo.Check.Readability.PredicateFunctionNames, []},
{Credo.Check.Readability.PreferImplicitTry, []},
{Credo.Check.Readability.RedundantBlankLines, []},
{Credo.Check.Readability.Semicolons, []},
{Credo.Check.Readability.SpaceAfterCommas, []},
{Credo.Check.Readability.StringSigils, []},
{Credo.Check.Readability.TrailingBlankLine, []},
{Credo.Check.Readability.TrailingWhiteSpace, []},
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
{Credo.Check.Readability.VariableNames, []},
{Credo.Check.Readability.NestedFunctionCalls, []},

#
## Refactoring Opportunities
#
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.CyclomaticComplexity, []},
{Credo.Check.Refactor.FunctionArity, []},
{Credo.Check.Refactor.LongQuoteBlocks, []},
# {Credo.Check.Refactor.MapInto, []},
{Credo.Check.Refactor.MatchInCondition, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, []},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.WithClauses, []},

#
## Warnings
#
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
{Credo.Check.Warning.BoolOperationOnSameValues, []},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
# {Credo.Check.Warning.LazyLogging, []},
{Credo.Check.Warning.MixEnv, []},
{Credo.Check.Warning.OperationOnSameValues, []},
{Credo.Check.Warning.OperationWithConstantResult, []},
{Credo.Check.Warning.RaiseInsideRescue, []},
{Credo.Check.Warning.UnusedEnumOperation, []},
{Credo.Check.Warning.UnusedFileOperation, []},
{Credo.Check.Warning.UnusedKeywordOperation, []},
{Credo.Check.Warning.UnusedListOperation, []},
{Credo.Check.Warning.UnusedPathOperation, []},
{Credo.Check.Warning.UnusedRegexOperation, []},
{Credo.Check.Warning.UnusedStringOperation, []},
{Credo.Check.Warning.UnusedTupleOperation, []},
{Credo.Check.Warning.UnsafeExec, []},

#
# Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`)

#
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
#
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
{Credo.Check.Consistency.UnusedVariableNames, false},
{Credo.Check.Design.DuplicatedCode, false},
{Credo.Check.Readability.AliasAs, false},
{Credo.Check.Readability.BlockPipe, []},
{Credo.Check.Readability.ImplTrue, []},
{Credo.Check.Readability.MultiAlias, false},
{Credo.Check.Readability.SeparateAliasRequire, []},
{Credo.Check.Readability.SinglePipe, []},
{Credo.Check.Readability.Specs, false},
{Credo.Check.Readability.StrictModuleLayout,
[
order:
~w(moduledoc behaviour use import require alias module_attribute defstruct callback macrocallback optional_callback)a,
ignore: [:type]
]},
{Credo.Check.Readability.WithCustomTaggedTuple, []},
{Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.AppendSingleItem, []},
{Credo.Check.Refactor.DoubleBooleanNegation, []},
{Credo.Check.Refactor.ModuleDependencies, false},
{Credo.Check.Refactor.NegatedIsNil, []},
{Credo.Check.Refactor.PipeChainStart, []},
{Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Warning.LeakyEnvironment, []},
{Credo.Check.Warning.MapGetUnsafePass, []},
{Credo.Check.Warning.UnsafeToAtom, []}

#
# Custom checks can be created using `mix credo.gen.check`.
#
]
}
]
}
8 changes: 6 additions & 2 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Used by "mix format"
# This file is synced with stordco/common-config-elixir. Any changes will be overwritten.

[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
import_deps: [],
inputs: ["*.{ex,exs}", "{config,lib,priv,test}/**/*.{ex,exs}"],
line_length: 120,
plugins: []
]
11 changes: 8 additions & 3 deletions .github/workflows/pr.yml → .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
# This file is synced with stordco/common-config-elixir. Any changes will be overwritten.

name: PR

on:
merge_group:
pull_request:
types:
- edited
Expand All @@ -11,6 +13,7 @@ on:

jobs:
title:
if: github.event_name == 'pull_request'
name: Check Title
runs-on: ubuntu-latest

Expand All @@ -25,6 +28,8 @@ jobs:
hint: |
You can pass the following formats:
feat: some title of the PR
fix: some title of the PR
fix: [OR-123] some title of the PR
feat: [OR-1234] some title of the PR
chore: update some action
Note: Adding ! (i.e. `feat!:`) represents a breaking change and will result in a SemVer major.
23 changes: 23 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file is synced with stordco/common-config-elixir. Any changes will be overwritten.

name: Release

on:
push:
branches:
- main

jobs:
Please:
runs-on: ubuntu-latest

steps:
- id: release
name: Release
uses: google-github-actions/release-please-action@v3
with:
command: manifest
config-file: .release-please-config.json
manifest-file: .release-please-manifest.json
release-type: elixir
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
20 changes: 0 additions & 20 deletions .github/workflows/release.yml

This file was deleted.

39 changes: 39 additions & 0 deletions .release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"$comment": "This file is synced with stordco/common-config-elixir. Any changes will be overwritten.",
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"changelog-sections": [
{
"type": "feat",
"section": "Features",
"hidden": false
},
{
"type": "fix",
"section": "Bug Fixes",
"hidden": false
},
{
"type": "chore",
"section": "Miscellaneous",
"hidden": false
}
],
"draft": false,
"draft-pull-request": false,
"packages": {
".": {
"extra-files": [
"README.md"
],
"release-type": "elixir"
}
},
"plugins": [
{
"type": "sentence-case"
}
],
"prerelease": false,
"pull-request-header": "An automated release has been created for you.",
"separate-pull-requests": true
}
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "1.2.0"
}
11 changes: 5 additions & 6 deletions lib/datadog/data_streams/aggregator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ defmodule Datadog.DataStreams.Aggregator do

use GenServer

alias Datadog.DataStreams.{Aggregator, Config, Payload, Transport}

require Logger

alias Datadog.DataStreams.{Aggregator, Config, Payload, Transport}

@send_interval 10_000

@doc """
Expand Down Expand Up @@ -77,8 +77,8 @@ defmodule Datadog.DataStreams.Aggregator do
iex> :ok = Aggregator.flush()
"""
@spec flush() :: :ok
def flush() do
@spec flush :: :ok
def flush do
Process.send(__MODULE__, :send, [])
end

Expand Down Expand Up @@ -131,8 +131,7 @@ defmodule Datadog.DataStreams.Aggregator do
def handle_cast({:add, %Aggregator.Offset{} = offset}, state) do
new_ts_type_current_buckets =
Aggregator.Bucket.upsert(state.ts_type_current_buckets, offset.timestamp, fn bucket ->
type_key =
if offset.type == :commit, do: :latest_commit_offsets, else: :latest_produce_offsets
type_key = if offset.type == :commit, do: :latest_commit_offsets, else: :latest_produce_offsets

new_offsets = bucket |> Map.get(:type_key, []) |> Aggregator.Offset.upsert(offset)
Map.put(bucket, type_key, new_offsets)
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/data_streams/aggregator/offset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule Datadog.DataStreams.Aggregator.Offset do
end)

if is_nil(matching_index) do
offsets ++ [upsert_offset]
[upsert_offset | offsets]
else
List.replace_at(offsets, matching_index, upsert_offset)
end
Expand Down
12 changes: 6 additions & 6 deletions lib/datadog/data_streams/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ defmodule Datadog.DataStreams.Config do
"unnamed-elixir-service"
"""
@spec service() :: String.t()
def service() do
@spec service :: String.t()
def service do
otel_service_name =
:opentelemetry
|> Application.get_env(:resource, [])
Expand Down Expand Up @@ -70,8 +70,8 @@ defmodule Datadog.DataStreams.Config do
""
"""
@spec env() :: String.t()
def env() do
@spec env :: String.t()
def env do
otel_service_env =
:opentelemetry
|> Application.get_env(:resource, [])
Expand Down Expand Up @@ -105,8 +105,8 @@ defmodule Datadog.DataStreams.Config do
""
"""
@spec primary_tag() :: String.t()
def primary_tag() do
@spec primary_tag :: String.t()
def primary_tag do
:data_streams
|> Application.get_env(:metadata, [])
|> Keyword.get(:primary_tag, "")
Expand Down
Loading

0 comments on commit a1360fd

Please sign in to comment.