Skip to content

Commit

Permalink
Adjust to Amplified house style
Browse files Browse the repository at this point in the history
* Rebuild `Makefile`
* Adjust `README.md` development section
* Copy `.credo.exs` style configuration
* Copy `.github/workflows/elixir.yml` build configuration
* Copy `.tool-versions` Elixir and Erlang upgrades
* Copy `.editorconfig`
* Copy `.vscode` settings and extension recommendations
* Remove `elixir-lang/ex_doc#1169` workaround
* Use `@external_resource` to keep `mix docs` in sync
* Reorganise `mix.exs`, filling it out more comprehensively
* _Downgrade_ `ExDoc`
* Include `test/support` in the archive for `TestDevice`
* Remove lint
* Add a shorter example for fixing the device only
  • Loading branch information
garthk committed Aug 16, 2020
1 parent ed0901e commit a7f5bfd
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 98 deletions.
46 changes: 37 additions & 9 deletions .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
configs: [
%{
#
# Run any exec using `mix credo -C <name>`. If no exec name is given
# Run any config using `mix credo -C <name>`. If no config name is given
# "default" is used.
#
name: "default",
Expand All @@ -21,10 +21,23 @@
# You can give explicit globs or simply directories.
# In the latter case `**/*.{ex,exs}` will be used.
#
included: ["lib/", "src/", "test/", "web/", "apps/"],
included: [
"lib/",
"src/",
"test/",
"web/",
"apps/*/lib/",
"apps/*/src/",
"apps/*/test/",
"apps/*/web/"
],
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.
#
Expand All @@ -35,6 +48,10 @@
#
strict: false,
#
# 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:
#
Expand All @@ -51,7 +68,7 @@
#
## Consistency Checks
#
{Credo.Check.Consistency.ExceptionNames, []},
{Credo.Check.Consistency.ExceptionNames, false},
{Credo.Check.Consistency.LineEndings, []},
{Credo.Check.Consistency.ParameterPatternMatching, []},
{Credo.Check.Consistency.SpaceAroundOperators, []},
Expand All @@ -70,7 +87,7 @@
# 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.TagTODO, false},
{Credo.Check.Design.TagFIXME, []},

#
Expand All @@ -93,6 +110,7 @@
{Credo.Check.Readability.StringSigils, []},
{Credo.Check.Readability.TrailingBlankLine, []},
{Credo.Check.Readability.TrailingWhiteSpace, []},
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
{Credo.Check.Readability.VariableNames, []},

#
Expand All @@ -107,12 +125,8 @@
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, []},
{Credo.Check.Refactor.PipeChainStart,
[
excluded_argument_types: [:atom, :binary, :fn, :keyword, :number],
excluded_functions: []
]},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.WithClauses, []},

#
## Warnings
Expand All @@ -122,6 +136,7 @@
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
{Credo.Check.Warning.LazyLogging, false},
{Credo.Check.Warning.MixEnv, false},
{Credo.Check.Warning.OperationOnSameValues, []},
{Credo.Check.Warning.OperationWithConstantResult, []},
{Credo.Check.Warning.RaiseInsideRescue, []},
Expand All @@ -133,18 +148,31 @@
{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.Readability.StrictModuleLayout, ignore: [:module_attribute]},
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
{Credo.Check.Consistency.UnusedVariableNames, false},
{Credo.Check.Design.DuplicatedCode, false},
{Credo.Check.Readability.AliasAs, false},
{Credo.Check.Readability.MultiAlias, false},
{Credo.Check.Readability.Specs, false},
{Credo.Check.Readability.SinglePipe, []},
{Credo.Check.Readability.WithCustomTaggedTuple, false},
{Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.AppendSingleItem, false},
{Credo.Check.Refactor.DoubleBooleanNegation, false},
{Credo.Check.Refactor.ModuleDependencies, false},
{Credo.Check.Refactor.NegatedIsNil, false},
{Credo.Check.Refactor.PipeChainStart, []},
{Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Warning.LeakyEnvironment, false},
{Credo.Check.Warning.MapGetUnsafePass, false},
{Credo.Check.Warning.UnsafeToAtom, false}

Expand Down
4 changes: 0 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8

[*.{md,py}]
indent_style = space
indent_size = 4

[*.{ex,exs,json}]
indent_style = space
indent_size = 2
Expand Down
30 changes: 17 additions & 13 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
# Modifying the actions? Don't like pushing to GitHub to find out whether your changes worked?
# Consider act: https://github.com/nektos/act
#
# WARNING: you'll need the 18.2GB GitHub-compatible Docker image:
# act -P ubuntu-18.04=nektos/act-environments-ubuntu:18.04

name: Elixir CI

on:
push:
branches: [trunk]
branches: [ main ]
pull_request:
branches: [trunk]
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
name: Elixir ${{matrix.elixir}} on OTP ${{matrix.otp}}
strategy:
matrix:
otp: ["21.3", "22.3"]
otp: ["21.3", "22.3", "23.0"]
elixir: ["1.8", "1.9", "1.10"]
steps:
- uses: actions/[email protected]
- uses: gleam-lang/[email protected]
with:
otp-version: ${{matrix.otp}}
- uses: actions/[email protected]
- uses: actions/checkout@v2
- name: Set up Elixir
uses: actions/setup-elixir@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- name: Cache deps
uses: actions/[email protected]
otp-version: ${{matrix.otp}}
- name: Restore dependencies cache
uses: actions/cache@v2
env:
cache-name: deps
with:
Expand Down Expand Up @@ -58,7 +62,7 @@ jobs:
env:
MIX_ENV: test
- name: mix test
run: mix coveralls --trace
run: mix test --trace
- name: mix format
run: |
mix format --check-formatted --dry-run --check-equivalent
Expand Down
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.10.3-otp-22
erlang 22.1.8.1
elixir 1.10.4-otp-23
erlang 23.0.3
5 changes: 2 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"recommendations": [
"EditorConfig.EditorConfig",
"davidanson.vscode-markdownlint",
"jakebecker.elixir-ls"
"editorconfig.editorconfig",
"elixir-lsp.elixir-ls"

This comment has been minimized.

Copy link
@tylerbarker

tylerbarker Aug 17, 2020

@garthk I think this should be JakeBecker.elixir-ls. It's confusing as, but mentioned here

]
}
17 changes: 10 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@
"editor.rulers": [
98
],
"editor.formatOnSave": true,
"[elixir]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "JakeBecker.elixir-ls"
},
"workbench.colorCustomizations": {
"activityBar.activeBorder": "#f9bd85",
"activityBar.background": "#ad68f8",
"activityBar.activeBorder": "#f9bd85",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#f9bd85",
"activityBarBadge.foreground": "#15202b",
"statusBar.background": "#9337f6",
"statusBar.foreground": "#e7e7e7",
"statusBarItem.hoverBackground": "#ad68f8",
"titleBar.activeBackground": "#9337f6",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#9337f699",
"titleBar.inactiveForeground": "#e7e7e799"
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveForeground": "#e7e7e799",
"statusBar.background": "#9337f6",
"statusBarItem.hoverBackground": "#ad68f8",
"statusBar.foreground": "#e7e7e7"
},
"peacock.affectActivityBar": true,
"peacock.color": "#9337f6",
Expand Down
29 changes: 20 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
# https://tech.davis-hansson.com/p/make/
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules

SOURCE := $(shell find lib -name \*.ex)
TEST := $(shell find test -name \*.ex)

.PHONY: check clean

check: deps lib/pretty.ex
mix format --check-formatted --dry-run --check-equivalent
mix compile --warnings-as-errors
mix coveralls.html
mix credo --strict
check: _build/dev _build/test
mix test
mix credo
mix dialyzer
mix docs
mix format
@echo "OK"

mix.lock: mix.exs
mix.lock deps: mix.exs
mix deps.get
mix deps.unlock --unused
mix deps.clean --unused
touch $@

deps: mix.lock
mix deps.get
_build/dev: deps $(SOURCE)
MIX_ENV=dev mix compile --warnings-as-errors
touch $@

lib/pretty.ex: README.md
_build/test: deps $(SOURCE) $(TEST)
MIX_ENV=test mix compile --warnings-as-errors
touch $@

clean:
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ end
* `mix do deps.get, deps.unlock --unused, deps.clean --unused` if you change dependencies
* `mix compile --warnings-as-errors` for a stricter compile
* `mix coveralls.html` to check for test coverage
* `mix credo --strict` to suggest more idiomatic style for your code
* `mix credo` to suggest more idiomatic style for your code
* `mix dialyzer` to find problems typing might reveal… albeit *slowly*
* `touch lib/pretty.ex && mix docs` to generate documentation
* `mix docs` to generate documentation

<!-- MDOC -->
<!-- INCLUDE -->
Expand Down Expand Up @@ -210,11 +210,18 @@ handler and write to it explicitly from inside the handler:
```elixir
device = Process.group_leader()
handler = fn name, m10s, m6a, nil ->
IO.inspect(device, {name, m10s, m6a}, label: "Ecto")
IO.inspect(device, {name, m10s, m6a}, label: "Ecto")
end
:telemetry.attach(self(), [:my_app, :repo, :query], handler, nil)
```

You can _almost_ get it down to a one-liner if you lose the label:

```elixir
dev = Process.group_leader()
:telemetry.attach(self(), [:my_app, :repo, :query], &IO.inspect(&4, {&1, &2, &3}, []), dev)
```

### The Case of the Missing Colors

Trying to read pages of data structures without syntax coloring is hard. Where'd the colors go?
Expand Down
3 changes: 2 additions & 1 deletion lib/pretty.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
defmodule Pretty do
@external_resource "README.md"

@moduledoc "README.md"
|> File.read!()
|> String.split("<!-- MDOC -->")
|> Enum.filter(&(&1 =~ ~R{<!\-\-\ INCLUDE\ \-\->}))
|> Enum.join("\n")
# strip comments https://github.com/elixir-lang/ex_doc/issues/1169
|> (&Regex.replace(~R{<!\-\-.*?\-\->}, &1, "")).()
# compensate for anchor id differences between ExDoc and GitHub
|> (&Regex.replace(~R{\(\#\K(?=[a-z][a-z0-9-]+\))}, &1, "module-")).()
Expand Down
Loading

0 comments on commit a7f5bfd

Please sign in to comment.