Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vereis committed Mar 4, 2024
0 parents commit 55c942f
Show file tree
Hide file tree
Showing 19 changed files with 560 additions and 0 deletions.
145 changes: 145 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
alias Credo.Check

%{
configs: [
%{
name: "default",
files: %{
included: [
"lib/",
"src/",
"web/",
"apps/*/lib/",
"apps/*/src/",
"apps/*/web/"
],
excluded: [~r"/tests/", ~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
},
plugins: [],
requires: [],
strict: true,
parse_timeout: 5000,
color: true,
checks: %{
enabled: [
## Consistency Checks ------------------------------------------------
{Check.Consistency.ExceptionNames, []},
{Check.Consistency.LineEndings, []},
{Check.Consistency.ParameterPatternMatching, []},
{Check.Consistency.SpaceAroundOperators, []},
{Check.Consistency.SpaceInParentheses, []},
{Check.Consistency.TabsOrSpaces, []},

## Design Checks -----------------------------------------------------
{Check.Design.AliasUsage, if_nested_deeper_than: 2},

## Readability Checks ------------------------------------------------
{Check.Readability.AliasOrder, []},
{Check.Readability.FunctionNames, []},
{Check.Readability.LargeNumbers, []},
{Check.Readability.MaxLineLength, priority: :low, max_length: 120},
{Check.Readability.ModuleAttributeNames, []},
{Check.Readability.ModuleDoc, []},
{Check.Readability.ModuleNames, []},
{Check.Readability.ParenthesesInCondition, []},
{Check.Readability.ParenthesesOnZeroArityDefs, []},
{Check.Readability.PipeIntoAnonymousFunctions, []},
{Check.Readability.PredicateFunctionNames, []},
{Check.Readability.PreferImplicitTry, []},
{Check.Readability.RedundantBlankLines, []},
{Check.Readability.Semicolons, []},
{Check.Readability.SpaceAfterCommas, []},
{Check.Readability.StringSigils, []},
{Check.Readability.TrailingBlankLine, []},
{Check.Readability.TrailingWhiteSpace, []},
{Check.Readability.UnnecessaryAliasExpansion, []},
{Check.Readability.VariableNames, []},
{Check.Readability.WithSingleClause, []},

## Refactoring Opportunities -----------------------------------------
{Check.Refactor.Apply, []},
{Check.Refactor.CondStatements, []},
{Check.Refactor.CyclomaticComplexity, []},
{Check.Refactor.FunctionArity, []},
{Check.Refactor.LongQuoteBlocks, []},
{Check.Refactor.MatchInCondition, []},
{Check.Refactor.MapJoin, []},
{Check.Refactor.NegatedConditionsInUnless, []},
{Check.Refactor.NegatedConditionsWithElse, []},
{Check.Refactor.Nesting, []},
{Check.Refactor.UnlessWithElse, []},
{Check.Refactor.WithClauses, []},
{Check.Refactor.FilterFilter, []},
{Check.Refactor.RejectReject, []},
{Check.Refactor.RedundantWithClauseResult, []},

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

## Checks which should always be on for consistency-sake IMO ---------
{Check.Consistency.MultiAliasImportRequireUse, []},
{Check.Consistency.UnusedVariableNames, force: :meaningful},
{Check.Design.DuplicatedCode, []},
{Check.Design.SkipTestWithoutComment, []},
{Check.Readability.ImplTrue, []},
{Check.Readability.MultiAlias, []},
{Check.Readability.NestedFunctionCalls, []},
{Check.Readability.SeparateAliasRequire, []},
{Check.Readability.SingleFunctionToBlockPipe, []},
{Check.Readability.SinglePipe, []},
{Check.Readability.StrictModuleLayout, []},
{Check.Readability.WithCustomTaggedTuple, []},
{Check.Refactor.ABCSize, [max_size: 80]},
{Check.Refactor.DoubleBooleanNegation, []},
{Check.Refactor.FilterReject, []},
{Check.Refactor.MapMap, []},
{Check.Refactor.NegatedIsNil, []},
{Check.Refactor.PipeChainStart, []},
{Check.Refactor.RejectFilter, []},
{Check.Refactor.VariableRebinding, []},
{Check.Warning.LeakyEnvironment, []},
{Check.Warning.MapGetUnsafePass, []},
{Check.Warning.MixEnv, []},
{Check.Warning.UnsafeToAtom, []},

## Causes Issues with Phoenix ----------------------------------------
{Check.Readability.Specs, []},
{Check.Refactor.ModuleDependencies, [max_deps: 19]},

## Optional (move to `disabled` based on app domain) -----------------
{Check.Refactor.IoPuts, []}
],
disabled: [
## Checks which are overly limiting ----------------------------------
{Check.Design.TagTODO, exit_status: 2},
{Check.Design.TagFIXME, []},
{Check.Readability.BlockPipe, []},
{Check.Readability.AliasAs, []},
{Check.Refactor.AppendSingleItem, []},

## Incompatible with modern versions of Elixir -----------------------
{Check.Refactor.MapInto, []},
{Check.Warning.LazyLogging, []}
]
}
}
]
}
4 changes: 4 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
name: EctoModel | CI checks

on:
pull_request:
branches:
- main
push:
branches:
- main

concurrency:
group: ci-${{github.ref}}
cancel-in-progress: true

jobs:
lint-and-test:
runs-on: ubuntu-latest
name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
strategy:
matrix:
include:
- otp: "26.1"
elixir: "1.15.7"
- otp: "24.2"
elixir: "1.13.4"
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ecto_model_repo
POSTGRES_PORT: 5432
steps:
- name: Checkout Github repo
uses: actions/checkout@v3.0.2
- name: Setup BEAM Env
uses: erlef/setup-beam@v1.15
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- name: Setup Cache
uses: actions/cache@v3.0.4
id: mix-cache
with:
path: |
deps
_build
priv/plts
key: ${{ hashFiles('mix.lock') }}-${{ matrix.elixir }}-${{ matrix.otp }}
- if: steps.mix-cache.outputs.cache-hit != 'true'
run: mkdir -p priv/plts; mix deps.get; mix deps.compile
- run: docker-compose up -d
- run: mix lint
- run: MIX_ENV=test mix do ecto.create, ecto.migrate, test
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tags
.elixir_ls/
.env
.envrc
_build/
erl_crash.dump
deps/
cover/
apps/**/cover/
priv/plts/
doc/
.direnv/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Vetspire

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# EctoModel

EctoModel is a library that aims to overhaul your Ecto.Schemas with additional functionality.

See the [official documentation for EctoModel](https://hexdocs.pm/ecto_model/).

## Installation

This package can be installed by adding `ecto_model` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:ecto_model, "~> 0.1.0"}
]
end
```
9 changes: 9 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Config

config :ecto_model, ecto_repos: [EctoModel.Repo], table_schema: "public"

config :ecto_model, EctoModel.Repo,
database: System.fetch_env!("POSTGRES_DB"),
username: System.fetch_env!("POSTGRES_USER"),
password: System.fetch_env!("POSTGRES_PASSWORD"),
hostname: "localhost"
25 changes: 25 additions & 0 deletions coveralls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"default_stop_words": [
"defmodule",
"defrecord",
"defimpl",
"defexception",
"defprotocol",
"defstruct",
"def.+(.+\\\\.+).+do",
"^\\s+use\\s+"
],

"custom_stop_words": [
],

"coverage_options": {
"treat_no_relevant_lines_as_covered": true,
"output_dir": "cover/",
"minimum_coverage": 100
},

"terminal_options": {
"file_column_width": 40
}
}
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.9"
services:
db:
image: postgres
environment:
- POSTGRES_USER
- POSTGRES_DB
- POSTGRES_PASSWORD
ports:
- ${POSTGRES_PORT}:5432
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };

# `sha256` can be programmatically obtained via running the following:
# `nix-prefetch-url --unpack https://github.com/elixir-lang/elixir/archive/v${version}.tar.gz`
elixir_1_15_7 = (pkgs.beam.packagesWith pkgs.erlangR26).elixir_1_15.override {
version = "1.15.7";
sha256 = "0yfp16fm8v0796f1rf1m2r0m2nmgj3qr7478483yp1x5rk4xjrz8";
};
in
with pkgs; {
devShells.default = mkShell {
buildInputs = [ elixir_1_15_7 inotify-tools docker-compose ];
env = {
POSTGRES_PORT="5432";
POSTGRES_USER = "postgres";
POSTGRES_PASSWORD = "postgres";
POSTGRES_DB = "ecto_model_repo";
};
};
}
);
}
Loading

0 comments on commit 55c942f

Please sign in to comment.