Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit34e5880

Browse files
committed
chore: fix credo warnings
1 parent143be1c commit34e5880

File tree

9 files changed

+332
-30
lines changed

9 files changed

+332
-30
lines changed

‎.check.exs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[
2+
## all available options with default values (see `mix check` docs for description)
3+
# parallel: true,
4+
# skipped: true,
5+
6+
## list of tools (see `mix check` docs for defaults)
7+
tools:[
8+
## curated tools may be disabled (e.g. the check for compilation warnings)
9+
# {:compiler, false},
10+
11+
## ...or adjusted (e.g. use one-line formatter for more compact credo output)
12+
# {:credo, "mix credo --format oneline"},
13+
14+
{:ex_unit,
15+
command:
16+
ifSystem.get_env("ASH_CI")=="true"do
17+
"mix coveralls.github"
18+
else
19+
"mix test"
20+
end}
21+
22+
## custom new tools may be added (mix tasks or arbitrary commands)
23+
# {:my_mix_task, command: "mix release", env: %{"MIX_ENV" => "prod"}},
24+
# {:my_arbitrary_tool, command: "npm test", cd: "assets"},
25+
# {:my_arbitrary_script, command: ["my_script", "argument with spaces"], cd: "scripts"}
26+
]
27+
]

‎.credo.exs‎

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
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+
#
7+
%{
8+
#
9+
# You can have as many configs as you like in the `configs:` field.
10+
configs:[
11+
%{
12+
#
13+
# Run any config using `mix credo -C <name>`. If no config name is given
14+
# "default" is used.
15+
#
16+
name:"default",
17+
#
18+
# These are the files included in the analysis:
19+
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/"]
35+
},
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+
#
67+
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,[max_complexity:12]},
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.BoolOperationOnSameValues,[]},
135+
{Credo.Check.Warning.ExpensiveEmptyEnumCheck,[]},
136+
{Credo.Check.Warning.IExPry,[]},
137+
{Credo.Check.Warning.IoInspect,[]},
138+
{Credo.Check.Warning.LazyLogging,[]},
139+
{Credo.Check.Warning.MixEnv,false},
140+
{Credo.Check.Warning.OperationOnSameValues,[]},
141+
{Credo.Check.Warning.OperationWithConstantResult,[]},
142+
{Credo.Check.Warning.RaiseInsideRescue,[]},
143+
{Credo.Check.Warning.UnusedEnumOperation,[]},
144+
{Credo.Check.Warning.UnusedFileOperation,[]},
145+
{Credo.Check.Warning.UnusedKeywordOperation,[]},
146+
{Credo.Check.Warning.UnusedListOperation,[]},
147+
{Credo.Check.Warning.UnusedPathOperation,[]},
148+
{Credo.Check.Warning.UnusedRegexOperation,[]},
149+
{Credo.Check.Warning.UnusedStringOperation,[]},
150+
{Credo.Check.Warning.UnusedTupleOperation,[]},
151+
{Credo.Check.Warning.UnsafeExec,[]},
152+
153+
#
154+
# Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`)
155+
156+
#
157+
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
158+
#
159+
{Credo.Check.Readability.StrictModuleLayout,false},
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.MultiAlias,false},
165+
{Credo.Check.Readability.Specs,false},
166+
{Credo.Check.Readability.SinglePipe,false},
167+
{Credo.Check.Readability.WithCustomTaggedTuple,false},
168+
{Credo.Check.Refactor.ABCSize,false},
169+
{Credo.Check.Refactor.AppendSingleItem,false},
170+
{Credo.Check.Refactor.DoubleBooleanNegation,false},
171+
{Credo.Check.Refactor.ModuleDependencies,false},
172+
{Credo.Check.Refactor.NegatedIsNil,false},
173+
{Credo.Check.Refactor.PipeChainStart,false},
174+
{Credo.Check.Refactor.VariableRebinding,false},
175+
{Credo.Check.Warning.LeakyEnvironment,false},
176+
{Credo.Check.Warning.MapGetUnsafePass,false},
177+
{Credo.Check.Warning.UnsafeToAtom,false}
178+
179+
#
180+
# Custom checks can be created using `mix credo.gen.check`.
181+
#
182+
]
183+
}
184+
]
185+
}

‎.github/workflows/elixir.yml‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name:Elixir CI
2+
3+
on:
4+
push:
5+
branches:[master]
6+
tags-ignore:["v*"]
7+
pull_request:
8+
branches:[master]
9+
create:
10+
tags:["v*"]
11+
jobs:
12+
build:
13+
runs-on:ubuntu-latest
14+
name:OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
15+
strategy:
16+
matrix:
17+
otp:["23"]
18+
elixir:["1.10.0"]
19+
env:
20+
GITHUB_TOKEN:${{ secrets.GITHUB_TOKEN }}
21+
ASH_CI:true
22+
steps:
23+
-run:sudo apt-get install --yes erlang-dev
24+
-uses:actions/checkout@v2
25+
-uses:actions/setup-elixir@v1
26+
with:
27+
otp-version:${{matrix.otp}}
28+
elixir-version:${{matrix.elixir}}
29+
-uses:actions/cache@v1
30+
id:cache-deps
31+
with:
32+
path:deps
33+
key:otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
34+
restore-keys:otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-deps-
35+
-uses:actions/cache@v1
36+
id:cache-build
37+
with:
38+
path:_build
39+
key:otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-build-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
40+
restore-keys:otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-build-
41+
-run:mix deps.get
42+
-run:mix check
43+
-run:mix hex.publish --yes
44+
if:startsWith(github.ref, 'refs/tags/v')
45+
env:
46+
HEX_API_KEY:${{ secrets.HEX_API_KEY }}

‎README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,14 @@
1212
- Need to figure out how to only fetch config one time in the configuration of the repo.
1313
Right now, we are calling the`installed_extensions()` function in both`supervisor` and
1414
`runtime` but that could mean checking the system environment variables every time (is that bad?)
15+
- Figure out heuristics for when to left join/right join (alternatively, make it configurable via the query language)
16+
For instance, if a relationship has a non-nil predicate applied to it in all`ors` or a single`and` then we should
17+
be able to inner join.
18+
I have learned from experience that no single approach here
19+
will be a one-size-fits-all. We need to either use complexity metrics,
20+
hints from the interface, or some other heuristic to do our best to
21+
make queries perform well. For now, I'm just choosing the most naive approach
22+
possible: left join to relationships that appear in`or` conditions, inner
23+
join to conditions that are constant the query (dont do this yet, but it will be a good optimization)
24+
Realistically, in my experience, joins don't actually scale very well, especially
25+
when calculated attributes are added.

‎lib/ash_postgres.ex‎

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ defmodule AshPostgres do
3232
@repoopts[:repo]
3333
@tableopts[:table]
3434

35-
defrepo()do
35+
defrepodo
3636
@repo
3737
end
3838

39-
defpostgres_table()do
39+
defpostgres_tabledo
4040
@table||@name
4141
end
4242
end
@@ -205,15 +205,6 @@ defmodule AshPostgres do
205205
end)
206206
end
207207

208-
# TODO: I have learned from experience that no single approach here
209-
# will be a one-size-fits-all. We need to either use complexity metrics,
210-
# hints from the interface, or some other heuristic to do our best to
211-
# make queries perform well. For now, I'm just choosing the most naive approach
212-
# possible: left join to relationships that appear in `or` conditions, inner
213-
# join to conditions that are constant the query (dont do this yet, but it will be a good optimization)
214-
# Realistically, in my experience, joins don't actually scale very well, especially
215-
# when calculated attributes are added.
216-
217208
@impltrue
218209
deffilter(query,filter,_resource)do
219210
new_query=
@@ -237,17 +228,9 @@ defmodule AshPostgres do
237228
Map.put_new(query,:__ash_bindings__,%{current:Enum.count(query.joins)+1,bindings:%{}})
238229

239230
Enum.reduce(filter.relationships,query,fn{name,relationship_filter},query->
240-
# TODO: This can be smarter. If the same relationship exists in all `ors`,
241-
# we can inner join it, (unless the filter is only for fields being null)
242231
join_type=:left
243232

244233
case{join_type,relationship_filter}do
245-
# TODO: We can't actually do this
246-
# {:left, %{impossible?: true}} ->
247-
# query
248-
249-
# {:inner, %{impossible?: true}} ->
250-
# from(row in query, where: false)
251234
{join_type,relationship_filter}->
252235
relationship=Ash.relationship(filter.resource,name)
253236

@@ -256,19 +239,23 @@ defmodule AshPostgres do
256239
joined_query=join_relationship(query,current_path,join_type)
257240

258241
joined_query_with_distinct=
259-
ifrelationship.cardinality==:manyandjoin_type==:left&&!joined_query.distinctdo
260-
from(rowinjoined_query,
261-
distinct:^Ash.primary_key(filter.resource)
262-
)
263-
else
264-
joined_query
265-
end
242+
join_and_add_distinct(relationship,join_type,joined_query,filter)
266243

267244
join_all_relationships(joined_query_with_distinct,relationship_filter,current_path)
268245
end
269246
end)
270247
end
271248

249+
defpjoin_and_add_distinct(relationship,join_type,joined_query,filter)do
250+
ifrelationship.cardinality==:manyandjoin_type==:left&&!joined_query.distinctdo
251+
from(rowinjoined_query,
252+
distinct:^Ash.primary_key(filter.resource)
253+
)
254+
else
255+
joined_query
256+
end
257+
end
258+
272259
defpjoin_relationship(query,path,join_type)do
273260
path_names=Enum.map(path,&&1.name)
274261

‎lib/predicates/trigram.ex‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
defmoduleAshPostgres.Predicates.Trigramdo
2+
@moduledoc"""
3+
A filter predicate that filters based on trigram similarity.
4+
5+
See the postgres docs on [https://www.postgresql.org/docs/9.6/pgtrgm.html](trigram) for more information.
6+
7+
Requires the pg_trgm extension. Configure which extensions you have installed in your `AshPostgres.Repo`
8+
9+
# Example
10+
11+
filter(query, name: [trigram: [text: "geoff", greater_than: 0.4]])
12+
"""
13+
14+
aliasAsh.Error.Filter.InvalidFilterValue
215
defstruct[:text,:greater_than,:less_than,:equals]
316

417
defnew(_resource,attr_name,attr_type,opts)do
@@ -12,7 +25,7 @@ defmodule AshPostgres.Predicates.Trigram do
1225
else
1326
_->
1427
{:error,
15-
Ash.Error.Filter.InvalidFilterValue.exception(
28+
InvalidFilterValue.exception(
1629
filter:%__MODULE__{
1730
text:opts[:text],
1831
less_than:opts[:less_than],

‎lib/repo.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule AshPostgres.Repo do
99
adapter:Ecto.Adapters.Postgres,
1010
otp_app:otp_app
1111

12-
definstalled_extensions()do
12+
definstalled_extensionsdo
1313
[]
1414
end
1515

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp