Skip to content

Commit

Permalink
Add credo
Browse files Browse the repository at this point in the history
Use credo to have consistent code style
  • Loading branch information
davydog187 authored and BlakeWilliams committed Mar 16, 2017
1 parent c764a1b commit 9b544da
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 6 deletions.
129 changes: 129 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# This file contains the configuration for Credo and you are probably reading
# this after creating it with `mix credo.gen.config`.
#
# If you find anything wrong or unclear in this file, please report an
# issue on GitHub: https://github.com/rrrene/credo/issues
#
%{
#
# You can have as many configs as you like in the `configs:` field.
configs: [
%{
#
# Run any config using `mix credo -C <name>`. If no config name is given
# "default" is used.
name: "default",
#
# These are the files included in the analysis:
files: %{
#
# You can give explicit globs or simply directories.
# In the latter case `**/*.{ex,exs}` will be used.
included: ["lib/"],
excluded: [~r"/_build/", ~r"/deps/"]
},
#
# 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.
requires: [],
#
# Credo automatically checks for updates, like e.g. Hex does.
# You can disable this behaviour below:
check_for_updates: true,
#
# If you want to enforce a style guide and need a more traditional linting
# experience, you can change `strict` to `true` below:
strict: false,
#
# If you want to use uncolored output by default, you can change `color`
# to `false` below:
color: true,
#
# You can customize the parameters of any check by adding a second element
# to the tuple.
#
# To disable a check put `false` as second element:
#
# {Credo.Check.Design.DuplicatedCode, false}
#
checks: [
{Credo.Check.Consistency.ExceptionNames},
{Credo.Check.Consistency.LineEndings},
{Credo.Check.Consistency.MultiAliasImportRequireUse},
{Credo.Check.Consistency.ParameterPatternMatching, priority: :low},
{Credo.Check.Consistency.SpaceAroundOperators},
{Credo.Check.Consistency.SpaceInParentheses},
{Credo.Check.Consistency.TabsOrSpaces},

# For some checks, like AliasUsage, you can only customize the priority
# Priority values are: `low, normal, high, higher`
{Credo.Check.Design.AliasUsage, priority: :low},

# For others you can set parameters

# If you don't want the `setup` and `test` macro calls in ExUnit tests
# or the `schema` macro in Ecto schemas to trigger DuplicatedCode, just
# set the `excluded_macros` parameter to `[:schema, :setup, :test]`.
{Credo.Check.Design.DuplicatedCode, excluded_macros: []},

# You can also customize the exit_status of each check.
# 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.TagFIXME},

{Credo.Check.Readability.FunctionNames},
{Credo.Check.Readability.LargeNumbers},
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 80},
{Credo.Check.Readability.ModuleAttributeNames},
{Credo.Check.Readability.ModuleDoc},
{Credo.Check.Readability.ModuleNames, false},
{Credo.Check.Readability.NoParenthesesWhenZeroArity},
{Credo.Check.Readability.ParenthesesInCondition},
{Credo.Check.Readability.PredicateFunctionNames},
{Credo.Check.Readability.PreferImplicitTry},
{Credo.Check.Readability.RedundantBlankLines},
{Credo.Check.Readability.Specs, false},
{Credo.Check.Readability.StringSigils},
{Credo.Check.Readability.TrailingBlankLine},
{Credo.Check.Readability.TrailingWhiteSpace},
{Credo.Check.Readability.VariableNames},
{Credo.Check.Refactor.DoubleBooleanNegation},

# {Credo.Check.Refactor.CaseTrivialMatches}, # deprecated in 0.4.0
{Credo.Check.Refactor.ABCSize},
{Credo.Check.Refactor.CondStatements},
{Credo.Check.Refactor.CyclomaticComplexity},
{Credo.Check.Refactor.FunctionArity},
{Credo.Check.Refactor.MatchInCondition},
{Credo.Check.Refactor.NegatedConditionsInUnless},
{Credo.Check.Refactor.NegatedConditionsWithElse},
{Credo.Check.Refactor.Nesting},
{Credo.Check.Refactor.PipeChainStart, false},
{Credo.Check.Refactor.UnlessWithElse},
{Credo.Check.Refactor.VariableRebinding},

{Credo.Check.Warning.BoolOperationOnSameValues},
{Credo.Check.Warning.IExPry},
{Credo.Check.Warning.IoInspect},
{Credo.Check.Warning.NameRedeclarationByAssignment},
{Credo.Check.Warning.NameRedeclarationByCase},
{Credo.Check.Warning.NameRedeclarationByDef},
{Credo.Check.Warning.NameRedeclarationByFn},
{Credo.Check.Warning.OperationOnSameValues},
{Credo.Check.Warning.OperationWithConstantResult},
{Credo.Check.Warning.UnusedEnumOperation},
{Credo.Check.Warning.UnusedFileOperation},
{Credo.Check.Warning.UnusedKeywordOperation},
{Credo.Check.Warning.UnusedListOperation},
{Credo.Check.Warning.UnusedPathOperation},
{Credo.Check.Warning.UnusedRegexOperation},
{Credo.Check.Warning.UnusedStringOperation},
{Credo.Check.Warning.UnusedTupleOperation},

# Custom checks can be created using `mix credo.gen.check`.
#
]
}
]
}
6 changes: 4 additions & 2 deletions lib/mix/tasks/update_slack_api.ex
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
defmodule Mix.Tasks.UpdateSlackApi do
@moduledoc "Updates Slack API documentation files for generating API code"

use Mix.Task
@dir System.tmp_dir

def run(_) do
try do
System.cmd("git", ["clone", "https://github.com/slackhq/slack-api-docs", "#{@dir}/slack-api-docs"])
files()
list_files()
|> filter_json
|> copy_files
after
System.cmd("rm", ["-rf", "#{@dir}/slack-api-docs"])
end
end

defp files do
defp list_files do
File.ls!("#{@dir}slack-api-docs/methods")
end

Expand Down
6 changes: 4 additions & 2 deletions lib/slack/lookups.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
defmodule Slack.Lookups do
@moduledoc "Utility functions for looking up slack state informatin"

@doc ~S"""
Turns a string like `"@USER_NAME"` into the ID that Slack understands (`"U…"`).
"""
def lookup_user_id("@" <> user_name, slack) do
slack.users
|> Map.values
|> Enum.find(%{ }, fn user -> user.name == user_name end)
|> Enum.find(%{}, fn user -> user.name == user_name end)
|> Map.get(:id)
end

Expand All @@ -22,7 +24,7 @@ defmodule Slack.Lookups do
def lookup_direct_message_id(user_id, slack) do
slack.ims
|> Map.values
|> Enum.find(%{ }, fn direct_message -> direct_message.user == user_id end)
|> Enum.find(%{}, fn direct_message -> direct_message.user == user_id end)
|> Map.get(:id)
end

Expand Down
1 change: 1 addition & 0 deletions lib/slack/sends.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Slack.Sends do
@moduledoc "Utility functions for sending slack messages"
alias Slack.Lookups

@doc """
Expand Down
1 change: 1 addition & 0 deletions lib/slack/state.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Slack.State do
@moduledoc "Slack state"
@behaviour Access

def fetch(client, key)
Expand Down
4 changes: 3 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ defmodule Slack.Mixfile do
{:exjsx, "~> 3.2.0"},
{:websocket_client, "~> 1.1.0"},
{:earmark, "~> 0.2.0", only: :dev},
{:ex_doc, "~> 0.12", only: :dev}]
{:ex_doc, "~> 0.12", only: :dev},
{:credo, "~> 0.5", only: [:dev, :test]}
]
end

def docs do
Expand Down
4 changes: 3 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
%{"certifi": {:hex, :certifi, "0.7.0", "861a57f3808f7eb0c2d1802afeaae0fa5de813b0df0979153cbafcd853ababaf", [:rebar3], []},
%{"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], []},
"certifi": {:hex, :certifi, "0.7.0", "861a57f3808f7eb0c2d1802afeaae0fa5de813b0df0979153cbafcd853ababaf", [:rebar3], []},
"credo": {:hex, :credo, "0.6.1", "a941e2591bd2bd2055dc92b810c174650b40b8290459c89a835af9d59ac4a5f8", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, optional: false]}]},
"earmark": {:hex, :earmark, "0.2.1", "ba6d26ceb16106d069b289df66751734802777a3cbb6787026dd800ffeb850f3", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.12.0", "b774aabfede4af31c0301aece12371cbd25995a21bb3d71d66f5c2fe074c603f", [:mix], [{:earmark, "~> 0.2", [hex: :earmark, optional: false]}]},
"exjsx": {:hex, :exjsx, "3.2.0", "7136cc739ace295fc74c378f33699e5145bead4fdc1b4799822d0287489136fb", [:mix], [{:jsx, "~> 2.6.2", [hex: :jsx, optional: false]}]},
Expand Down

0 comments on commit 9b544da

Please sign in to comment.