Skip to content

Commit

Permalink
Credo configuration (#70)
Browse files Browse the repository at this point in the history
* fix large numbers

* refactoring control structure 'with' in the search function

* delete unsense operations

* add in modules a @moduledoc tag

* refactoring two functions which was too complex

* add credo in CI

* fix credo issues in the folder examples
  • Loading branch information
qnVictoria committed Feb 18, 2021
1 parent 491ef34 commit dfe6130
Show file tree
Hide file tree
Showing 28 changed files with 340 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ jobs:
- run: mix deps.get
- run: MIX_ENV=test mix format --check-formatted
- run: MIX_ENV=test mix compile --warnings-as-errors
- run: MIX_ENV=test mix credo --all
- run: MIX_ENV=test mix test --trace
- run: MIX_ENV=test mix coveralls.circle
- run: MIX_ENV=test mix coveralls.circle
190 changes: 190 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# 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/",
"src/",
"test/",
"examples/",
"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.
#
requires: [],
#
# If you want to enforce a style guide and need a more traditional linting
# experience, you can change `strict` to `true` below:
#
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:
#
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: [
#
## Consistency Checks
#
{Credo.Check.Consistency.ExceptionNames, []},
{Credo.Check.Consistency.LineEndings, []},
{Credo.Check.Consistency.ParameterPatternMatching, []},
{Credo.Check.Consistency.SpaceAroundOperators, []},
{Credo.Check.Consistency.SpaceInParentheses, []},
{Credo.Check.Consistency.TabsOrSpaces, []},

#
## Design Checks
#
# You can customize the priority of any check
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage,
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
# 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: 0]},
{Credo.Check.Design.TagFIXME, []},

#
## Readability Checks
#
{Credo.Check.Readability.AliasOrder, []},
{Credo.Check.Readability.FunctionNames, []},
{Credo.Check.Readability.LargeNumbers, []},
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
{Credo.Check.Readability.ModuleAttributeNames, []},
{Credo.Check.Readability.ModuleDoc, []},
{Credo.Check.Readability.ModuleNames, []},
{Credo.Check.Readability.ParenthesesInCondition, []},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{Credo.Check.Readability.PredicateFunctionNames, []},
{Credo.Check.Readability.PreferImplicitTry, []},
{Credo.Check.Readability.RedundantBlankLines, []},
{Credo.Check.Readability.Semicolons, []},
{Credo.Check.Readability.SpaceAfterCommas, []},
{Credo.Check.Readability.StringSigils, []},
{Credo.Check.Readability.TrailingBlankLine, []},
{Credo.Check.Readability.TrailingWhiteSpace, []},
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
{Credo.Check.Readability.VariableNames, []},

#
## Refactoring Opportunities
#
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.CyclomaticComplexity, []},
{Credo.Check.Refactor.FunctionArity, []},
{Credo.Check.Refactor.LongQuoteBlocks, []},
# {Credo.Check.Refactor.MapInto, []},
{Credo.Check.Refactor.MatchInCondition, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, []},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.WithClauses, []},

#
## Warnings
#
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
{Credo.Check.Warning.BoolOperationOnSameValues, []},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
# {Credo.Check.Warning.LazyLogging, []},
{Credo.Check.Warning.MixEnv, false},
{Credo.Check.Warning.OperationOnSameValues, []},
{Credo.Check.Warning.OperationWithConstantResult, []},
{Credo.Check.Warning.RaiseInsideRescue, []},
{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, []},
{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.Consistency.MultiAliasImportRequireUse, false},
{Credo.Check.Consistency.UnusedVariableNames, false},
{Credo.Check.Design.DuplicatedCode, false},
{Credo.Check.Readability.AliasAs, false},
{Credo.Check.Readability.BlockPipe, false},
{Credo.Check.Readability.ImplTrue, false},
{Credo.Check.Readability.MultiAlias, false},
{Credo.Check.Readability.SeparateAliasRequire, false},
{Credo.Check.Readability.SinglePipe, false},
{Credo.Check.Readability.Specs, false},
{Credo.Check.Readability.StrictModuleLayout, false},
{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, false},
{Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Warning.LeakyEnvironment, false},
{Credo.Check.Warning.MapGetUnsafePass, false},
{Credo.Check.Warning.UnsafeToAtom, false}

#
# Custom checks can be created using `mix credo.gen.check`.
#
]
}
]
}
4 changes: 4 additions & 0 deletions examples/lib/shops/spiders/allo_ua.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule Spiders.AlloUa do
@moduledoc """
Spider implementation for website allo.ua.
"""

use Crawly.Spider

def override_settings() do
Expand Down
4 changes: 4 additions & 0 deletions examples/lib/shops/spiders/amazon_comedybooks.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule Spiders.AmazonComedyBooks do
@moduledoc """
Spider implementation for website amazon.de.
"""

use Crawly.Spider

def override_settings() do
Expand Down
8 changes: 6 additions & 2 deletions examples/lib/shops/spiders/autoria.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule Spiders.Autoria do
@moduledoc """
Spider implementation for website auto.ria.com.
"""

use Crawly.Spider

alias Crawly.Utils
Expand Down Expand Up @@ -31,7 +35,7 @@ defmodule Spiders.Autoria do
def parse_item(response) do
{:ok, document} = Floki.parse_document(response.body)

hrefs =
hrefs =
document
|> Floki.find(".content-bar a.m-link-ticket")
|> Enum.map(fn link -> Floki.attribute(link, "href") end)
Expand Down Expand Up @@ -71,7 +75,7 @@ defmodule Spiders.Autoria do
end

defp start_urls() do
Enum.map(0..8, fn page_number ->
Enum.map(0..8, fn page_number ->
"https://auto.ria.com/uk/search/?indexName=auto,order_auto,newauto_search&paintCondition=1&technicalCondition=1&plateNumber.length.gte=1&verified.VIN=1&body.id[0]=3&body.id[3]=4&body.id[4]=2&year[0].gte=2011&year[0].lte=2021&categories.main.id=1&country.origin.id[0].not=804&country.origin.id[1].not=643&country.origin.id[2].not=158&country.origin.id[3].not=860&country.origin.id[4].not=356&country.origin.id[5].not=364&country.import.usa.not=-1&price.USD.gte=6000&price.USD.lte=9500&price.currency=1&mileage.gte=1&mileage.lte=150&abroad.not=0&custom.not=1&damage.not=1&page=#{page_number}&size=20"
end)
end
Expand Down
4 changes: 4 additions & 0 deletions examples/lib/shops/spiders/elixir_jobs.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule Spiders.ElixirJobs do
@moduledoc """
Spider implementation for website elixir-radar.com.
"""

use Crawly.Spider

def override_settings() do
Expand Down
6 changes: 5 additions & 1 deletion examples/lib/shops/spiders/homebase.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
defmodule Spiders.Homebase do
@moduledoc """
Spider implementation for website homebase.co.uk.
"""

use Crawly.Spider

@image_folder Application.get_env(:crawly, :image_folder, "/tmp")
@image_folder Application.compile_env(:crawly, :image_folder, "/tmp")

def override_settings() do
ui_node = System.get_env("UI_NODE") || "ui@127.0.0.1"
Expand Down
4 changes: 4 additions & 0 deletions examples/lib/shops/spiders/oregon_regs.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule Spiders.OregonRegs do
@moduledoc """
Spider implementation for website state.or.us.
"""

use Crawly.Spider

@impl Crawly.Spider
Expand Down
4 changes: 4 additions & 0 deletions examples/lib/shops/spiders/walmart.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule Spiders.Walmart do
@moduledoc """
Spider implementation for website walmart.com.
"""

use Crawly.Spider

@impl Crawly.Spider
Expand Down
4 changes: 2 additions & 2 deletions lib/crawly_ui/manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ defmodule CrawlyUI.Manager do

# Return an ECTO fragement for the given search query
def search(search_string) do
with {:ok, tokens} <- parse_search_string(search_string),
tokens = Enum.map(tokens, &String.trim(&1)) do
with {:ok, tokens} <- parse_search_string(search_string) do
tokens = Enum.map(tokens, &String.trim(&1))
# take first two elements from the list
[key, value | rest] = tokens

Expand Down
4 changes: 4 additions & 0 deletions lib/crawly_ui/manager/item.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule CrawlyUI.Manager.Item do
@moduledoc """
Schema for items table.
"""

use Ecto.Schema
import Ecto.Changeset

Expand Down
4 changes: 4 additions & 0 deletions lib/crawly_ui/manager/job.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule CrawlyUI.Manager.Job do
@moduledoc """
Schema for jobs table.
"""

use Ecto.Schema
import Ecto.Changeset

Expand Down
4 changes: 4 additions & 0 deletions lib/crawly_ui/manager/log.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule CrawlyUI.Manager.Log do
@moduledoc """
Schema for logs table.
"""

use Ecto.Schema
import Ecto.Changeset

Expand Down
4 changes: 4 additions & 0 deletions lib/crawly_ui/manager/spider.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule CrawlyUI.Manager.Spider do
@moduledoc """
Schema for spiders table.
"""

use Ecto.Schema
import Ecto.Changeset

Expand Down
4 changes: 4 additions & 0 deletions lib/crawly_ui/query_parser.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule CrawlyUI.QueryParser do
@moduledoc """
Implementing efficient parser combinators.
"""

import NimbleParsec

key = ascii_string([?a..?z, ?A..?Z, ?\s, ?\t], min: 1)
Expand Down
Loading

0 comments on commit dfe6130

Please sign in to comment.