Skip to content

Commit

Permalink
use credo in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
deadtrickster committed Jul 30, 2017
1 parent 33baba1 commit f88fc2b
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 1 deletion.
64 changes: 64 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
%{
configs: [
%{
name: "default",
check_for_updates: false,
files: %{
included: ["lib/", "src/", "web/", "apps/", "test/"],
excluded: [~r"/_build/", ~r"/deps/"]
},
checks: [
{Credo.Check.Consistency.ExceptionNames},
{Credo.Check.Consistency.LineEndings},
{Credo.Check.Consistency.SpaceAroundOperators},
{Credo.Check.Consistency.SpaceInParentheses},
{Credo.Check.Consistency.TabsOrSpaces},

{Credo.Check.Design.AliasUsage, false},

{Credo.Check.Design.DuplicatedCode, excluded_macros: [:schema, :setup, :test]},

{Credo.Check.Design.TagTODO, exit_status: 0},
{Credo.Check.Design.TagFIXME, exit_status: 0},

{Credo.Check.Readability.FunctionNames},
{Credo.Check.Readability.LargeNumbers},
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 90, exit_status: 0},
{Credo.Check.Readability.ModuleAttributeNames},
{Credo.Check.Readability.ModuleDoc, false},
{Credo.Check.Readability.ModuleNames},
{Credo.Check.Readability.ParenthesesInCondition},
{Credo.Check.Readability.PredicateFunctionNames},
{Credo.Check.Readability.TrailingBlankLine},
{Credo.Check.Readability.TrailingWhiteSpace},
{Credo.Check.Readability.VariableNames},

{Credo.Check.Refactor.ABCSize},
{Credo.Check.Refactor.CondStatements},
{Credo.Check.Refactor.FunctionArity},
{Credo.Check.Refactor.MatchInCondition},
{Credo.Check.Refactor.PipeChainStart},
{Credo.Check.Refactor.CyclomaticComplexity},
{Credo.Check.Refactor.NegatedConditionsInUnless},
{Credo.Check.Refactor.NegatedConditionsWithElse},
{Credo.Check.Refactor.Nesting},
{Credo.Check.Refactor.UnlessWithElse},

{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.BoolOperationOnSameValues},
{Credo.Check.Warning.UnusedEnumOperation},
{Credo.Check.Warning.UnusedKeywordOperation},
{Credo.Check.Warning.UnusedListOperation},
{Credo.Check.Warning.UnusedStringOperation},
{Credo.Check.Warning.UnusedTupleOperation},
{Credo.Check.Warning.OperationWithConstantResult},
]
}
]
}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ sudo: false
before_script:
- mix deps.get --only test
script:
- mix test
- ./bin/checks.sh
3 changes: 3 additions & 0 deletions bin/checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

MIX_ENV=test mix credo --strict && MIX_ENV=test mix test
89 changes: 89 additions & 0 deletions bin/increment-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash

# Based on https://github.com/fmahnke/shell-semver
# The MIT License (MIT)
# Copyright (c) 2014 Fritz Mahnke
# Increment a version string using Semantic Versioning (SemVer) terminology.
# Parse command line options.


while getopts ":Mmp" Option
do
case $Option in
M ) major=true;;
m ) minor=true;;
p ) patch=true;;
esac
done

shift $(($OPTIND - 1))

STAGED_COUNT=$(git diff --cached --numstat | wc -l)
UNSTAGED_COUNT=$(git diff --numstat | wc -l)

## TODO check we are on master
if [ $STAGED_COUNT -ne "0" ]; then
echo "you have staged changes. Aborting".
exit 1
fi

if [ $UNSTAGED_COUNT -ne "0" ]; then
echo "you have unstaged changes. Aborting".
exit 1
fi

version="$(mix run --no-compile --no-start -e ":io.format('~s', [PrometheusPhoenix.Mixfile.project()[:version]])")"

echo "Old version: ${version}"

# Build array from version string.
oa=( ${version//./ } )
a=( ${version//./ } )

# If version string is missing or has the wrong number of members, show usage message.

if [ ${#a[@]} -ne 3 ]
then
echo "usage: $(basename $0) [-Mmp] TAG_MESSAGE(optional)"
exit 1
fi

# Increment version numbers as requested.

if [ ! -z $major ]
then
((a[0]++))
a[1]=0
a[2]=0
fi

if [ ! -z $minor ]
then
((a[1]++))
a[2]=0
fi

if [ ! -z $patch ]
then
((a[2]++))
fi

new_version="${a[0]}.${a[1]}.${a[2]}"

echo "New version: ${new_version}"

sed -i s/\"${oa[0]}\.${oa[1]}\.${oa[2]}\"/\"${a[0]}\.${a[1]}\.${a[2]}\"/g mix.exs
sed -i s/\~\>\ ${oa[0]}\.${oa[1]}/\~\>\ ${a[0]}\.${a[1]}/g README.md

git add mix.exs
git add README.md
git add doc
git commit -m "Bump to v${new_version}"

TAG_MESSAGE=${1:-"New version: v${new_version}"}

git tag -a "v${new_version}" -m "${TAG_MESSAGE}"
git push origin master
git push origin "v${new_version}"

mix hex.publish
18 changes: 18 additions & 0 deletions bin/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
if [ $# -eq 0 ]; then
git stash -q --keep-index
./bin/checks.sh
RESULT=$?
git stash pop -q
[ $RESULT -ne 0 ] && exit 1
exit 0
else
if [ $1 = "install" ]; then
ln -s `pwd`/bin/pre-commit.sh .git/hooks/pre-commit
elif [ $1 = "uninstall" ]; then
rm .git/hooks/pre-commit
else
echo "Unknown argument $1"
exit 1
fi
fi

0 comments on commit f88fc2b

Please sign in to comment.