Skip to content

Commit f0a41e2

Browse files
authored
Merge pull request #18 from athonet-open/athonet
Library review and improvements
2 parents 7927e3b + 06cc796 commit f0a41e2

34 files changed

+1026
-1675
lines changed

.credo.exs

Lines changed: 4 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -1,188 +1,14 @@
1-
# This file contains the configuration for Credo and you are probably reading
2-
# this after creating it with `mix credo.gen.config`.
3-
#
4-
# If you find anything wrong or unclear in this file, please report an
5-
# issue on GitHub: https://github.com/rrrene/credo/issues
6-
#
71
%{
8-
#
9-
# You can have as many configs as you like in the `configs:` field.
102
configs: [
113
%{
12-
#
13-
# Run any config using `mix credo -C <name>`. If no config name is given
14-
# "default" is used.
15-
#
164
name: "default",
17-
#
18-
# These are the files included in the analysis:
195
files: %{
20-
#
21-
# You can give explicit globs or simply directories.
22-
# In the latter case `**/*.{ex,exs}` will be used.
23-
#
24-
included: [
25-
"lib/",
26-
"src/",
27-
"test/",
28-
"web/",
29-
"apps/*/lib/",
30-
"apps/*/src/",
31-
"apps/*/test/",
32-
"apps/*/web/"
33-
],
34-
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
6+
included: ["lib", "test"]
357
},
36-
#
37-
# Load and configure plugins here:
38-
#
39-
plugins: [],
40-
#
41-
# If you create your own checks, you must specify the source files for
42-
# them here, so they can be loaded by Credo before running the analysis.
43-
#
44-
requires: [],
45-
#
46-
# If you want to enforce a style guide and need a more traditional linting
47-
# experience, you can change `strict` to `true` below:
48-
#
49-
strict: false,
50-
#
51-
# To modify the timeout for parsing files, change this value:
52-
#
53-
parse_timeout: 5000,
54-
#
55-
# If you want to use uncolored output by default, you can change `color`
56-
# to `false` below:
57-
#
58-
color: true,
59-
#
60-
# You can customize the parameters of any check by adding a second element
61-
# to the tuple.
62-
#
63-
# To disable a check put `false` as second element:
64-
#
65-
# {Credo.Check.Design.DuplicatedCode, false}
66-
#
678
checks: [
68-
#
69-
## Consistency Checks
70-
#
71-
{Credo.Check.Consistency.ExceptionNames, []},
72-
{Credo.Check.Consistency.LineEndings, []},
73-
{Credo.Check.Consistency.ParameterPatternMatching, []},
74-
{Credo.Check.Consistency.SpaceAroundOperators, []},
75-
{Credo.Check.Consistency.SpaceInParentheses, []},
76-
{Credo.Check.Consistency.TabsOrSpaces, []},
77-
78-
#
79-
## Design Checks
80-
#
81-
# You can customize the priority of any check
82-
# Priority values are: `low, normal, high, higher`
83-
#
84-
{Credo.Check.Design.AliasUsage,
85-
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
86-
# You can also customize the exit_status of each check.
87-
# If you don't want TODO comments to cause `mix credo` to fail, just
88-
# set this value to 0 (zero).
89-
#
90-
{Credo.Check.Design.TagTODO, [exit_status: 2]},
91-
{Credo.Check.Design.TagFIXME, []},
92-
93-
#
94-
## Readability Checks
95-
#
96-
{Credo.Check.Readability.AliasOrder, []},
97-
{Credo.Check.Readability.FunctionNames, []},
98-
{Credo.Check.Readability.LargeNumbers, []},
99-
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
100-
{Credo.Check.Readability.ModuleAttributeNames, []},
101-
{Credo.Check.Readability.ModuleDoc, []},
102-
{Credo.Check.Readability.ModuleNames, []},
103-
{Credo.Check.Readability.ParenthesesInCondition, []},
104-
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
105-
{Credo.Check.Readability.PredicateFunctionNames, []},
106-
{Credo.Check.Readability.PreferImplicitTry, []},
107-
{Credo.Check.Readability.RedundantBlankLines, []},
108-
{Credo.Check.Readability.Semicolons, []},
109-
{Credo.Check.Readability.SpaceAfterCommas, []},
110-
{Credo.Check.Readability.StringSigils, []},
111-
{Credo.Check.Readability.TrailingBlankLine, []},
112-
{Credo.Check.Readability.TrailingWhiteSpace, []},
113-
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
114-
{Credo.Check.Readability.VariableNames, []},
115-
116-
#
117-
## Refactoring Opportunities
118-
#
119-
{Credo.Check.Refactor.CondStatements, []},
120-
{Credo.Check.Refactor.CyclomaticComplexity, []},
121-
{Credo.Check.Refactor.FunctionArity, []},
122-
{Credo.Check.Refactor.LongQuoteBlocks, []},
123-
# {Credo.Check.Refactor.MapInto, []},
124-
{Credo.Check.Refactor.MatchInCondition, []},
125-
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
126-
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
127-
{Credo.Check.Refactor.Nesting, []},
128-
{Credo.Check.Refactor.UnlessWithElse, []},
129-
{Credo.Check.Refactor.WithClauses, []},
130-
131-
#
132-
## Warnings
133-
#
134-
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
135-
{Credo.Check.Warning.BoolOperationOnSameValues, []},
136-
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
137-
{Credo.Check.Warning.IExPry, []},
138-
{Credo.Check.Warning.IoInspect, []},
139-
# {Credo.Check.Warning.LazyLogging, []},
140-
{Credo.Check.Warning.MixEnv, false},
141-
{Credo.Check.Warning.OperationOnSameValues, []},
142-
{Credo.Check.Warning.OperationWithConstantResult, []},
143-
{Credo.Check.Warning.RaiseInsideRescue, []},
144-
{Credo.Check.Warning.UnusedEnumOperation, []},
145-
{Credo.Check.Warning.UnusedFileOperation, []},
146-
{Credo.Check.Warning.UnusedKeywordOperation, []},
147-
{Credo.Check.Warning.UnusedListOperation, []},
148-
{Credo.Check.Warning.UnusedPathOperation, []},
149-
{Credo.Check.Warning.UnusedRegexOperation, []},
150-
{Credo.Check.Warning.UnusedStringOperation, []},
151-
{Credo.Check.Warning.UnusedTupleOperation, []},
152-
{Credo.Check.Warning.UnsafeExec, []},
153-
154-
#
155-
# Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`)
156-
157-
#
158-
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
159-
#
160-
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
161-
{Credo.Check.Consistency.UnusedVariableNames, false},
162-
{Credo.Check.Design.DuplicatedCode, false},
163-
{Credo.Check.Readability.AliasAs, false},
164-
{Credo.Check.Readability.BlockPipe, false},
165-
{Credo.Check.Readability.ImplTrue, false},
166-
{Credo.Check.Readability.MultiAlias, false},
167-
{Credo.Check.Readability.SeparateAliasRequire, false},
168-
{Credo.Check.Readability.SinglePipe, false},
169-
{Credo.Check.Readability.Specs, false},
170-
{Credo.Check.Readability.StrictModuleLayout, false},
171-
{Credo.Check.Readability.WithCustomTaggedTuple, false},
172-
{Credo.Check.Refactor.ABCSize, false},
173-
{Credo.Check.Refactor.AppendSingleItem, false},
174-
{Credo.Check.Refactor.DoubleBooleanNegation, false},
175-
{Credo.Check.Refactor.ModuleDependencies, false},
176-
{Credo.Check.Refactor.NegatedIsNil, false},
177-
{Credo.Check.Refactor.PipeChainStart, false},
178-
{Credo.Check.Refactor.VariableRebinding, false},
179-
{Credo.Check.Warning.LeakyEnvironment, false},
180-
{Credo.Check.Warning.MapGetUnsafePass, false},
181-
{Credo.Check.Warning.UnsafeToAtom, false}
182-
183-
#
184-
# Custom checks can be created using `mix credo.gen.check`.
185-
#
9+
{Credo.Check.Refactor.RedundantWithClauseResult, false},
10+
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, false},
11+
{Credo.Check.Design.AliasUsage, false}
18612
]
18713
}
18814
]

.formatter.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Used by "mix format"
21
[
32
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
43
]

.github/workflows/elixir.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ jobs:
4343
otp-version: "25.2"
4444
elixir-version: "1.14.3"
4545
- run: mix deps.get
46-
- run: mix muzak --min-coverage 95.0
4746

4847
# Linit and type checking
4948
analyze:

CHANGELOG

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# 2.0.0
2+
- Bugfix - ADD behaviour is now compliant with RFC (insert or update)
3+
- Bugfix - allow usage of nil values, previous implementation used `Map.get` with default `nil` to detect if a key was not present
4+
- Change - COPY operation to be based on ADD operation (as per RFC)
5+
- Change - MOVE operation to be based on COPY+REMOVE operation (as per RFC)
6+
- Change - REPLACE operation to be based on REMOVE+ADD operation (as per RFC)
7+
- Change - `Jsonpatch.apply_patch()` signature changes:
8+
- patches can be defined as `Jsonpatch.Operation.Add/Copy/Remove/...` structs or with plain map conforming to the jsonpatch schema
9+
- error reason is now defined with a `{:error, %Jsonpatch.Error{}}` tuple.
10+
%Jsonpatch.Error{patch_index: _, path: _, reason: _} reports the patch index, the path and the reason that caused the error.
11+
- Removed - `Jsonpatch.Mapper` module, in favour of new Jsonpatch.apply_patch signature
12+
- Removed - `Jsonpatch.Operation` protocol
13+
- Feature - introduced new `Jsonpatch.apply_patch()` option `keys: {:custom, convert_fn}` to convert path fragments with a user specific logic
14+
- Improvements - increased test coverage
15+
116
# 1.0.1
217
- Escape remaining keys before comparing them to the (already escaped) keys from earlier in the diffing process when determining Remove operations
318

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ check:
66
mix test
77
mix dialyzer
88
mix credo --strict
9-
MIX_ENV=mutation mix muzak --min-coverage 95.0
109
MIX_ENV=test mix coveralls

README.md

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Jsonpatch
2+
23
![Elixir CI](https://github.com/corka149/jsonpatch/workflows/Elixir%20CI/badge.svg)
34
[![Coverage Status](https://coveralls.io/repos/github/corka149/jsonpatch/badge.svg?branch=master)](https://coveralls.io/github/corka149/jsonpatch?branch=master)
45
[![Generic badge](https://img.shields.io/badge/Mutation-Tested-success.svg)](https://shields.io/)
@@ -7,21 +8,18 @@
78

89
An implementation of [RFC 6902](https://tools.ietf.org/html/rfc6902) in pure Elixir.
910

10-
1111
Features:
1212

13-
1. Creating a patch by comparing to maps and structs
14-
2. Apply patches to maps and structs - supports operations:
13+
- Creating a patch by comparing to maps and lists
14+
- Apply patches to maps and lists - supports operations:
1515
- add
1616
- replace
1717
- remove
1818
- copy
1919
- move
2020
- test
21-
3. De/Encoding and mapping
22-
4. Escaping of "`/`" (by "`~1`") and "`~`" (by "`~0`")
23-
5. Allow usage of `-` for appending things to list (Add and Copy operation)
24-
21+
- Escaping of "`/`" (by "`~1`") and "`~`" (by "`~0`")
22+
- Allow usage of `-` for appending things to list (Add and Copy operation)
2523

2624
## Getting started
2725

@@ -54,24 +52,6 @@ iex> Jsonpatch.diff(source, destination)
5452
]}
5553
```
5654

57-
### Mapping for de- and encoding
58-
59-
Map a JSON patch struct to a regular map.
60-
61-
```elixir
62-
iex> add_patch_map = %Jsonpatch.Operation.Add{path: "/name", value: "Alice"}
63-
iex> Jsonpatch.Mapper.to_map(add_patch_map)
64-
%{op: "add", path: "/name", value: "Alice"}
65-
```
66-
67-
Map a regular map to a JSON patch struct.
68-
69-
```elixir
70-
iex> add_patch_map = %{"op" => "add", "path" => "/name", "value" => "Alice"}
71-
iex> Jsonpatch.Mapper.from_map(add_patch_map)
72-
%Jsonpatch.Operation.Add{path: "/name", value: "Alice"}
73-
```
74-
7555
### Apply patches
7656

7757
```elixir
@@ -87,28 +67,6 @@ iex> Jsonpatch.apply_patch(patch, target)
8767
{:ok, %{"name" => "Bob", "married" => true, "hobbies" => ["Elixir!"], "age" => 33}}
8868
```
8969

90-
### In an `exs` script
91-
92-
With `Mix.install` small scripts can be written to create JSON patches.
93-
```elixir
94-
Mix.install([:jsonpatch, :poison])
95-
96-
source =
97-
File.read!("foo.json")
98-
|> Poison.Parser.parse!(%{})
99-
100-
destination =
101-
File.read!("bar.json")
102-
|> Poison.Parser.parse!(%{})
103-
104-
patch =
105-
source
106-
|> Jsonpatch.diff(destination)
107-
|> Jsonpatch.Mapper.to_map()
108-
109-
IO.inspect(patch, label: :patch)
110-
```
111-
11270
## Important sources
11371
- [Official RFC 6902](https://tools.ietf.org/html/rfc6902)
11472
- [Inspiration: python-json-patch](https://github.com/stefankoegl/python-json-patch)

coveralls.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
{
22
"skip_files": ["test/support/"],
3-
"default_stop_words": [
4-
"defdelegate",
5-
"defmodule",
6-
"defevent",
7-
"defrecord",
8-
"defstruct",
9-
"defimpl",
10-
"def.+(.+//.+).+do"
11-
],
123
"coverage_options": {
4+
"html_filter_full_covered": true,
135
"treat_no_relevant_lines_as_covered": true,
14-
"minimum_coverage": 85
6+
"minimum_coverage": 100
157
}
168
}

0 commit comments

Comments
 (0)