Skip to content

Commit 962f82e

Browse files
committed
merge in credo fixes
2 parents ce598c6 + 1a5eb55 commit 962f82e

File tree

14 files changed

+362
-206
lines changed

14 files changed

+362
-206
lines changed

config/.credo.exs

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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 exec using `mix credo -C <name>`. If no exec 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: ["lib/"],
25+
excluded: [
26+
~r"/_build/",
27+
~r"/.github/",
28+
~r"/c_src/",
29+
~r"/priv/",
30+
~r"/deps",
31+
~r"/guides/",
32+
~r"/deps/"
33+
]
34+
},
35+
#
36+
# If you create your own checks, you must specify the source files for
37+
# them here, so they can be loaded by Credo before running the analysis.
38+
#
39+
requires: [],
40+
#
41+
# If you want to enforce a style guide and need a more traditional linting
42+
# experience, you can change `strict` to `true` below:
43+
#
44+
strict: false,
45+
#
46+
# If you want to use uncolored output by default, you can change `color`
47+
# to `false` below:
48+
#
49+
color: true,
50+
#
51+
# You can customize the parameters of any check by adding a second element
52+
# to the tuple.
53+
#
54+
# To disable a check put `false` as second element:
55+
#
56+
# {Credo.Check.Design.DuplicatedCode, false}
57+
#
58+
checks: [
59+
#
60+
## Consistency Checks
61+
#
62+
{Credo.Check.Consistency.ExceptionNames},
63+
{Credo.Check.Consistency.LineEndings},
64+
{Credo.Check.Consistency.ParameterPatternMatching},
65+
{Credo.Check.Consistency.SpaceAroundOperators},
66+
{Credo.Check.Consistency.SpaceInParentheses},
67+
{Credo.Check.Consistency.TabsOrSpaces},
68+
69+
#
70+
## Design Checks
71+
#
72+
# You can customize the priority of any check
73+
# Priority values are: `low, normal, high, higher`
74+
#
75+
{Credo.Check.Design.AliasUsage, priority: :low},
76+
# For some checks, you can also set other parameters
77+
#
78+
# If you don't want the `setup` and `test` macro calls in ExUnit tests
79+
# or the `schema` macro in Ecto schemas to trigger DuplicatedCode, just
80+
# set the `excluded_macros` parameter to `[:schema, :setup, :test]`.
81+
#
82+
{Credo.Check.Design.DuplicatedCode, excluded_macros: []},
83+
# You can also customize the exit_status of each check.
84+
# If you don't want TODO comments to cause `mix credo` to fail, just
85+
# set this value to 0 (zero).
86+
#
87+
{Credo.Check.Design.TagTODO, exit_status: 2},
88+
{Credo.Check.Design.TagFIXME},
89+
90+
#
91+
## Readability Checks
92+
#
93+
{Credo.Check.Readability.AliasOrder},
94+
{Credo.Check.Readability.FunctionNames},
95+
{Credo.Check.Readability.LargeNumbers},
96+
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 120},
97+
{Credo.Check.Readability.ModuleAttributeNames},
98+
{Credo.Check.Readability.ModuleDoc},
99+
{Credo.Check.Readability.ModuleNames},
100+
{Credo.Check.Readability.ParenthesesOnZeroArityDefs},
101+
{Credo.Check.Readability.ParenthesesInCondition},
102+
{Credo.Check.Readability.PredicateFunctionNames},
103+
{Credo.Check.Readability.PreferImplicitTry},
104+
{Credo.Check.Readability.RedundantBlankLines},
105+
{Credo.Check.Readability.StringSigils},
106+
{Credo.Check.Readability.TrailingBlankLine},
107+
{Credo.Check.Readability.TrailingWhiteSpace},
108+
{Credo.Check.Readability.VariableNames},
109+
{Credo.Check.Readability.Semicolons},
110+
{Credo.Check.Readability.SpaceAfterCommas},
111+
112+
#
113+
## Refactoring Opportunities
114+
#
115+
{Credo.Check.Refactor.DoubleBooleanNegation},
116+
{Credo.Check.Refactor.CondStatements},
117+
{Credo.Check.Refactor.CyclomaticComplexity},
118+
{Credo.Check.Refactor.FunctionArity},
119+
{Credo.Check.Refactor.LongQuoteBlocks},
120+
{Credo.Check.Refactor.MapInto},
121+
{Credo.Check.Refactor.MatchInCondition},
122+
{Credo.Check.Refactor.NegatedConditionsInUnless},
123+
{Credo.Check.Refactor.NegatedConditionsWithElse},
124+
{Credo.Check.Refactor.Nesting},
125+
{Credo.Check.Refactor.PipeChainStart, false},
126+
{Credo.Check.Refactor.UnlessWithElse},
127+
128+
#
129+
## Warnings
130+
#
131+
{Credo.Check.Warning.BoolOperationOnSameValues},
132+
{Credo.Check.Warning.ExpensiveEmptyEnumCheck},
133+
{Credo.Check.Warning.IExPry},
134+
{Credo.Check.Warning.IoInspect},
135+
{Credo.Check.Warning.LazyLogging},
136+
{Credo.Check.Warning.OperationOnSameValues},
137+
{Credo.Check.Warning.OperationWithConstantResult},
138+
{Credo.Check.Warning.UnusedEnumOperation},
139+
{Credo.Check.Warning.UnusedFileOperation},
140+
{Credo.Check.Warning.UnusedKeywordOperation},
141+
{Credo.Check.Warning.UnusedListOperation},
142+
{Credo.Check.Warning.UnusedPathOperation},
143+
{Credo.Check.Warning.UnusedRegexOperation},
144+
{Credo.Check.Warning.UnusedStringOperation},
145+
{Credo.Check.Warning.UnusedTupleOperation},
146+
{Credo.Check.Warning.RaiseInsideRescue},
147+
148+
#
149+
# Controversial and experimental checks (opt-in, just remove `, false`)
150+
#
151+
{Credo.Check.Refactor.ABCSize, false},
152+
{Credo.Check.Refactor.AppendSingleItem, false},
153+
{Credo.Check.Refactor.VariableRebinding, false},
154+
{Credo.Check.Warning.MapGetUnsafePass, false},
155+
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
156+
157+
#
158+
# Deprecated checks (these will be deleted after a grace period)
159+
#
160+
{Credo.Check.Readability.Specs, false}
161+
162+
#
163+
# Custom checks can be created using `mix credo.gen.check`.
164+
#
165+
]
166+
}
167+
]
168+
}

lib/scenic/component/button.ex

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -51,52 +51,14 @@ defmodule Scenic.Component.Button do
5151
alignment = styles[:alignment] || @default_alignment
5252

5353
# build the graph
54-
graph =
55-
case alignment do
56-
:center ->
57-
Graph.build(font: font, font_size: font_size)
58-
|> rrect({width, height, radius}, fill: theme.background, id: :btn)
59-
|> text(text,
60-
fill: theme.text,
61-
translate: {width / 2, height * 0.7},
62-
text_align: :center,
63-
id: :title
64-
)
65-
66-
:left ->
67-
Graph.build(font: font, font_size: font_size)
68-
|> rrect({width, height, radius}, fill: theme.background, id: :btn)
69-
|> text(
70-
text,
71-
fill: theme.text,
72-
translate: {8, height * 0.7},
73-
text_align: :left,
74-
id: :title
75-
)
76-
77-
:right ->
78-
Graph.build(font: font, font_size: font_size)
79-
|> rrect({width, height, radius}, fill: theme.background, id: :btn)
80-
|> text(text,
81-
fill: theme.text,
82-
translate: {width - 8, height * 0.7},
83-
text_align: :right,
84-
id: :title
85-
)
86-
end
8754

88-
# special case the dark and light themes to show an outline
8955
graph =
90-
case styles[:theme] do
91-
:dark ->
92-
Graph.modify(graph, :btn, &update_opts(&1, stroke: {1, theme.border}))
56+
Graph.build(font: font, font_size: font_size)
57+
|> rrect({width, height, radius}, fill: theme.background, id: :btn)
58+
|> do_aligned_text(alignment, text, theme.text, width, height)
9359

94-
:light ->
95-
Graph.modify(graph, :btn, &update_opts(&1, stroke: {1, theme.border}))
96-
97-
_ ->
98-
graph
99-
end
60+
# special case the dark and light themes to show an outline
61+
graph = do_special_theme_outline(styles[:theme], graph, theme.border)
10062

10163
state = %{
10264
graph: graph,
@@ -112,6 +74,45 @@ defmodule Scenic.Component.Button do
11274
{:ok, state}
11375
end
11476

77+
defp do_aligned_text(graph, :center, text, fill, width, height) do
78+
text(graph, text,
79+
fill: fill,
80+
translate: {width / 2, height * 0.7},
81+
text_align: :center,
82+
id: :title
83+
)
84+
end
85+
86+
defp do_aligned_text(graph, :left, text, fill, _width, height) do
87+
text(graph, text,
88+
fill: fill,
89+
translate: {8, height * 0.7},
90+
text_align: :left,
91+
id: :title
92+
)
93+
end
94+
95+
defp do_aligned_text(graph, :right, text, fill, width, height) do
96+
text(graph, text,
97+
fill: fill,
98+
translate: {width - 8, height * 0.7},
99+
text_align: :right,
100+
id: :title
101+
)
102+
end
103+
104+
defp do_special_theme_outline(:dark, graph, border) do
105+
Graph.modify(graph, :btn, &update_opts(&1, stroke: {1, border}))
106+
end
107+
108+
defp do_special_theme_outline(:light, graph, border) do
109+
Graph.modify(graph, :btn, &update_opts(&1, stroke: {1, border}))
110+
end
111+
112+
defp do_special_theme_outline(_, graph, _border) do
113+
graph
114+
end
115+
115116
# --------------------------------------------------------
116117
def handle_input(
117118
{:cursor_enter, _uid},

lib/scenic/component/input/dropdown.ex

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ defmodule Scenic.Component.Input.Dropdown do
6060
defp verify_item(_), do: false
6161

6262
# --------------------------------------------------------
63+
# credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity
6364
def init({items, initial_id}, opts) do
6465
id = opts[:id]
6566
styles = opts[:styles]
@@ -135,11 +136,19 @@ defmodule Scenic.Component.Input.Dropdown do
135136
g =
136137
group(
137138
g,
139+
# credo:disable-for-next-line Credo.Check.Refactor.Nesting
138140
fn g ->
139-
case id == initial_id do
140-
true -> rect(g, {width, height}, fill: theme.active, id: id)
141-
false -> rect(g, {width, height}, fill: theme.background, id: id)
142-
end
141+
rect(
142+
g,
143+
{width, height},
144+
fill:
145+
if id == initial_id do
146+
theme.active
147+
else
148+
theme.background
149+
end,
150+
id: id
151+
)
143152
|> text(text,
144153
fill: theme.text,
145154
text_align: :left,

0 commit comments

Comments
 (0)