From 982b36603e1c7396e57e620e0aa9df08c036ea16 Mon Sep 17 00:00:00 2001 From: Kamil Adam Date: Thu, 16 Dec 2021 11:37:35 +0100 Subject: [PATCH] Add Logger --- Makefile | 5 +- docs/ARCHITECTURE.md | 1 + docs/CHANGELOG.md | 7 + docs/reports/hlint.html | 374 ++++++++++++++++++ docs/reports/stan.html | 2 +- helma.cabal | 14 +- hlint.sh | 5 +- hs/app/Main.hs | 4 +- hs/benchmark/HelVM/CartesianProduct.hs | 9 - .../Evaluator/IEvaluatorBenchMark.hs | 1 + .../Automata/WhiteSpace/EvaluatorBenchMark.hs | 2 +- hs/src/HelVM/Common/Collections/MapList.hs | 4 +- hs/src/HelVM/Common/Containers/LLIndexSafe.hs | 12 +- hs/src/HelVM/Common/Containers/MTIndexSafe.hs | 10 +- hs/src/HelVM/Common/Containers/Util.hs | 6 +- hs/src/HelVM/Common/Control/Control.hs | 68 ++++ hs/src/HelVM/Common/Control/Logger.hs | 112 ++++++ hs/src/HelVM/Common/Control/Message.hs | 31 ++ hs/src/HelVM/Common/Control/Safe.hs | 155 ++++++++ hs/src/HelVM/Common/Digit/Digitable.hs | 10 +- hs/src/HelVM/Common/Digit/Digits.hs | 6 +- hs/src/HelVM/Common/Digit/ToDigit.hs | 33 +- hs/src/HelVM/Common/ListLikeUtil.hs | 16 +- hs/src/HelVM/Common/ReadText.hs | 20 +- hs/src/HelVM/Common/Safe.hs | 147 ------- hs/src/HelVM/Common/SequencesUtil.hs | 28 +- hs/src/HelVM/Common/ZipA.hs | 13 + .../BrainFuck/Evaluator/IEvaluator.hs | 6 +- .../BrainFuck/Evaluator/TEvaluator.hs | 8 +- .../HelVM/HelMA/Automata/BrainFuck/Lexer.hs | 2 +- .../HelVM/HelMA/Automata/BrainFuck/Parser.hs | 10 +- hs/src/HelVM/HelMA/Automata/ETA/Addressing.hs | 2 +- .../Automata/ETA/Evaluator/LLEvaluator.hs | 5 +- .../Automata/ETA/Evaluator/MTEvaluator.hs | 5 +- hs/src/HelVM/HelMA/Automata/ETA/Lexer.hs | 2 +- .../HelMA/Automata/ETA/OperandParsers.hs | 2 +- hs/src/HelVM/HelMA/Automata/ETA/Token.hs | 2 +- .../Automata/SubLeq/Evaluator/LLEvaluator.hs | 4 +- hs/src/HelVM/HelMA/Automata/SubLeq/Lexer.hs | 2 +- .../HelMA/Automata/WhiteSpace/Addressing.hs | 4 +- .../WhiteSpace/Evaluator/LLEvaluator.hs | 5 +- .../HelVM/HelMA/Automata/WhiteSpace/Lexer.hs | 4 +- .../Automata/WhiteSpace/OperandParsers.hs | 2 +- .../HelVM/HelMA/Automata/WhiteSpace/Parser.hs | 2 +- .../HelVM/HelMA/Automata/WhiteSpace/Token.hs | 2 +- hs/src/HelVM/HelMA/Automaton/IO/BusinessIO.hs | 30 +- hs/src/HelVM/HelMA/Automaton/IO/MockIO.hs | 95 +++-- .../HelVM/HelMA/Automaton/Memories/LLRAM.hs | 2 +- .../HelVM/HelMA/Automaton/Memories/LLStack.hs | 20 +- .../HelVM/HelMA/Automaton/Memories/MTRAM.hs | 2 +- .../HelVM/HelMA/Automaton/Memories/MTStack.hs | 20 +- hs/test/HelVM/CartesianProduct.hs | 9 - .../HelVM/Common/Collections/MapListSpec.hs | 108 ++--- hs/test/HelVM/Common/Control/LoggerSpec.hs | 18 + hs/test/HelVM/Common/ListLikeUtilSpec.hs | 8 +- hs/test/HelVM/Expectations.hs | 22 +- hs/test/HelVM/GoldenExpectations.hs | 22 +- .../BrainFuck/Evaluator/IEvaluatorSpec.hs | 10 +- .../BrainFuck/Evaluator/TEvaluatorSpec.hs | 10 +- .../HelMA/Automata/BrainFuck/TokensSpec.hs | 8 +- .../HelVM/HelMA/Automata/Cat/EvaluatorSpec.hs | 7 +- .../HelMA/Automata/ETA/AddressingSpec.hs | 60 +-- .../HelVM/HelMA/Automata/ETA/EvaluatorSpec.hs | 12 +- hs/test/HelVM/HelMA/Automata/ETA/LexerSpec.hs | 16 +- .../HelMA/Automata/ETA/OperandParsersSpec.hs | 34 +- .../HelVM/HelMA/Automata/Rev/EvaluatorSpec.hs | 6 +- .../HelMA/Automata/SubLeq/EvaluatorSpec.hs | 6 +- .../HelVM/HelMA/Automata/SubLeq/LexerSpec.hs | 6 +- .../Automata/WhiteSpace/EvaluatorSpec.hs | 24 +- .../HelMA/Automata/WhiteSpace/LexerSpec.hs | 14 +- .../Automata/WhiteSpace/OperandParsersSpec.hs | 76 ++-- .../HelMA/Automata/WhiteSpace/ParserSpec.hs | 14 +- .../HelVM/HelMA/Automaton/FilterIf0Spec.hs | 10 +- hs/test/HelVM/MonadErrorSpec.hs | 4 +- stan.sh | 2 +- 75 files changed, 1266 insertions(+), 573 deletions(-) create mode 100644 docs/reports/hlint.html delete mode 100644 hs/benchmark/HelVM/CartesianProduct.hs create mode 100644 hs/src/HelVM/Common/Control/Control.hs create mode 100644 hs/src/HelVM/Common/Control/Logger.hs create mode 100644 hs/src/HelVM/Common/Control/Message.hs create mode 100644 hs/src/HelVM/Common/Control/Safe.hs delete mode 100644 hs/src/HelVM/Common/Safe.hs create mode 100644 hs/src/HelVM/Common/ZipA.hs delete mode 100644 hs/test/HelVM/CartesianProduct.hs create mode 100644 hs/test/HelVM/Common/Control/LoggerSpec.hs diff --git a/Makefile b/Makefile index 171533afc..918219863 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all bench build check clean configure golden fast haddock hlint main repl report run stan stylish test update +.PHONY: all bench build check clean configure golden fast haddock hlint main output repl report run stan stylish test update all: update fast bench @@ -36,6 +36,9 @@ hlint: main: make stylish configure check build test +output: + if test -d .output; then rm -r .output; fi + repl: cabal new-repl lib:helma diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 3558c5330..e903345d0 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -32,6 +32,7 @@ Tools and libraries: * [x] [slist](https://kowainik.github.io/projects/slist) for sized list * [x] [ListLike](https://hackage.haskell.org/package/ListLike) for list abstraction * [ ] [mono-traversable](https://github.com/snoyberg/mono-traversable#readme) for list abstraction + * [ ] [lens](https://github.com/ekmett/lens#lens-lenses-folds-and-traversals) for for modification * For production code: * [x] [mtl](https://github.com/haskell/mtl) for IoC * [X] [polysemy](https://github.com/polysemy-research/polysemy#readme) for IoC diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1c3230b06..ff046e58f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,12 @@ # 📅 Revision history for HelMA +## 0.6.12.0 -- 2022-01-07 + +* Add `Logger` based on Writer +* Refactor `Safe` +* Replace `CartesianProduct` to `ZipA` +* Use local `hlint` + ## 0.6.11.2 -- 2021-12-14 * Fix version in cabal diff --git a/docs/reports/hlint.html b/docs/reports/hlint.html new file mode 100644 index 000000000..e0603b110 --- /dev/null +++ b/docs/reports/hlint.html @@ -0,0 +1,374 @@ + + + + +HLint Report + + + + + + + + +
+ +

All hints

+ + +

All files

+ + +
+
+

+ Report generated by HLint +v2.1.11 + - a tool to suggest improvements to your Haskell code. +

+ +
+./hs/benchmark/HelVM/HelMA/Automata/BrainFuck/Evaluator/IEvaluatorBenchMark.hs:45:3: Suggestion: Reduce duplication
+Found
+
let file = readBfFile fileName
+let params = (, cellType) <$> file
+let exec = ioExecMockIOWithInput input . uncurryEval =<< params
+calculateOutput <$> exec
+
+Perhaps
+
Combine with ./hs/benchmark/HelVM/HelMA/Automata/BrainFuck/Evaluator/IEvaluatorBenchMark.hs:65:3
+ +
+ +
+./hs/benchmark/HelVM/HelMA/Automata/BrainFuck/Evaluator/IEvaluatorBenchMark.hs:45:3: Suggestion: Reduce duplication
+Found
+
let file = readBfFile fileName
+let params = (, cellType) <$> file
+let exec = ioExecMockIOWithInput input . uncurryEval =<< params
+calculateOutput <$> exec
+
+Perhaps
+
Combine with ./hs/benchmark/HelVM/HelMA/Automata/BrainFuck/Evaluator/IEvaluatorBenchMark.hs:82:3
+ +
+ +
+./hs/benchmark/HelVM/HelMA/Automata/BrainFuck/Evaluator/TEvaluatorBenchMark.hs:44:5: Suggestion: Reduce duplication
+Found
+
let file = readBfFile fileName
+let params = (, cellType) <$> file
+let exec = execMockIOWithInput input . uncurryEval <$> params
+calculateOutput <$> exec
+
+Perhaps
+
Combine with ./hs/benchmark/HelVM/HelMA/Automata/BrainFuck/Evaluator/TEvaluatorBenchMark.hs:64:5
+ +
+ +
+./hs/benchmark/HelVM/HelMA/Automata/BrainFuck/Evaluator/TEvaluatorBenchMark.hs:44:5: Suggestion: Reduce duplication
+Found
+
let file = readBfFile fileName
+let params = (, cellType) <$> file
+let exec = execMockIOWithInput input . uncurryEval <$> params
+calculateOutput <$> exec
+
+Perhaps
+
Combine with ./hs/benchmark/HelVM/HelMA/Automata/BrainFuck/Evaluator/TEvaluatorBenchMark.hs:81:5
+ +
+ +
+./hs/benchmark/HelVM/HelMA/Automata/ETA/EvaluatorBenchMark.hs:35:31: Warning: Redundant do
+Found
+
do ioExec stackType "from-eas" fileName inputs
+Perhaps
+
ioExec stackType "from-eas" fileName inputs
+ +
+ +
+./hs/benchmark/HelVM/HelMA/Automata/ETA/EvaluatorBenchMark.hs:45:31: Warning: Redundant do
+Found
+
do ioExec stackType "original" fileName inputs
+Perhaps
+
ioExec stackType "original" fileName inputs
+ +
+ +
+./hs/src/HelVM/HelMA/Automaton/IO/MockIO.hs:94:25: Suggestion: Move brackets to avoid $
+Found
+
(orError mockIO $ top (input mockIO)) <$
+  put mockIO{input = orError mockIO $ discard $ input mockIO}
+Perhaps
+
orError mockIO (top (input mockIO)) <$
+  put mockIO{input = orError mockIO $ discard $ input mockIO}
+ +
+ +
+./hs/test/HelVM/MonadErrorSpec.hs:9:8: Warning: Redundant do
+Found
+
do describe "MonadError" $
+     do it "Right" $ textRight `shouldBe` Right 1
+        it "Left" $ textLeft `shouldBe` Left "one"
+Perhaps
+
describe "MonadError" $
+  do it "Right" $ textRight `shouldBe` Right 1
+     it "Left" $ textLeft `shouldBe` Left "one"
+ +
+ +
+./hs/test/HelVM/HelMA/Automata/ETA/EvaluatorSpec.hs:30:11: Suggestion: Reduce duplication
+Found
+
let params = (, defaultStackType) <$> file
+let mock
+      = ioExecMockIOWithInput (toText input) . uncurryEval =<< params
+let minorPath = fileName <> input
+
+Perhaps
+
Combine with ./hs/test/HelVM/HelMA/Automata/ETA/EvaluatorSpec.hs:49:11
+ +
+ +
+./hs/test/HelVM/HelMA/Automata/WhiteSpace/EvaluatorSpec.hs:25:21: Warning: Redundant do
+Found
+
do describe "original" $
+     do let majorPath = "simpleEval" </> "original" </> "ws"
+        forM_
+          [("count", ""), ("hworld", ""), ("calc", "-1\n"), ("fact", "10\n"),
+           ("hanoi", "1\n"), ("loctest", "1\n2\n"), ("name", "WriteOnly\n")]
+          $
+          \ (fileName, input) ->
+            do let file = readWsFile ("original" </> fileName)
+               forM_ options $
+                 \ ascii ->
+                   do let paramsF = simpleParamsWithDefaultsAndWhiteTokenType ascii
+                      let paramsIO = paramsF <$> file
+                      let mock = ioExecMockIOWithInput input . simpleEval =<< paramsIO
+                      let minorPath = show ascii </> fileName
+                      describe minorPath $
+                        do it ("output" </> minorPath) $
+                             calculateOutput <$>
+                               mock `goldenShouldIO`
+                                 buildAbsoluteOutFileName (majorPath </> "output" </> minorPath)
+                           it ("logged" </> minorPath) $
+                             calculateLogged <$>
+                               mock `goldenShouldIO`
+                                 buildAbsoluteOutFileName (majorPath </> "logged" </> minorPath)
+Perhaps
+
describe "original" $
+  do let majorPath = "simpleEval" </> "original" </> "ws"
+     forM_
+       [("count", ""), ("hworld", ""), ("calc", "-1\n"), ("fact", "10\n"),
+        ("hanoi", "1\n"), ("loctest", "1\n2\n"), ("name", "WriteOnly\n")]
+       $
+       \ (fileName, input) ->
+         do let file = readWsFile ("original" </> fileName)
+            forM_ options $
+              \ ascii ->
+                do let paramsF = simpleParamsWithDefaultsAndWhiteTokenType ascii
+                   let paramsIO = paramsF <$> file
+                   let mock = ioExecMockIOWithInput input . simpleEval =<< paramsIO
+                   let minorPath = show ascii </> fileName
+                   describe minorPath $
+                     do it ("output" </> minorPath) $
+                          calculateOutput <$>
+                            mock `goldenShouldIO`
+                              buildAbsoluteOutFileName (majorPath </> "output" </> minorPath)
+                        it ("logged" </> minorPath) $
+                          calculateLogged <$>
+                            mock `goldenShouldIO`
+                              buildAbsoluteOutFileName (majorPath </> "logged" </> minorPath)
+ +
+ +
+./hs/test/HelVM/HelMA/Automata/WhiteSpace/EvaluatorSpec.hs:40:15: Suggestion: Reduce duplication
+Found
+
let paramsIO = paramsF <$> file
+let mock = ioExecMockIOWithInput input . simpleEval =<< paramsIO
+let minorPath = show ascii </> fileName
+describe minorPath $
+  do it ("output" </> minorPath) $
+       calculateOutput <$>
+         mock `goldenShouldIO`
+           buildAbsoluteOutFileName (majorPath </> "output" </> minorPath)
+     it ("logged" </> minorPath) $
+       calculateLogged <$>
+         mock `goldenShouldIO`
+           buildAbsoluteOutFileName (majorPath </> "logged" </> minorPath)
+
+Perhaps
+
Combine with ./hs/test/HelVM/HelMA/Automata/WhiteSpace/EvaluatorSpec.hs:87:11
+ +
+ +
+ + + diff --git a/docs/reports/stan.html b/docs/reports/stan.html index 3e3e9151e..a768f5680 100644 --- a/docs/reports/stan.html +++ b/docs/reports/stan.html @@ -1,5 +1,5 @@ -Stan Report

Stan Report

This is the Haskell Static Analysis report generated by Stan

Stan Info

In this section, you can find the general information about the used Stan tool, compile-time and run-time environment variables and settings, including build information, system data and execution configurations.

Stan Version
Version0.0.1.0
Git RevisionUNKNOWN
Release DateUNKNOWN
System Info
Operating Systemlinux
Architecturex86_64
Compilerghc
Compiler Version8.10
Environment
Environment VariablesSTAN_USE_DEFAULT_CONFIG=True
TOML configuration files/home/kamil-adam/git/helvm/helma/.stan.toml
CLI arguments-s --hide-solution report

Project Info

Information about the analysed project

Project namehelma
Cabal Fileshelma.cabal
HIE Files Directory.hie
Files Number100

Analysis Info

Summary stats from the static analysis

Modules100
LoC4896
Extensions31
SafeHaskell Extensions0
Available inspections44
Checked inspections44
Found Observations0
Ignored Observations0

Static Analysis Summary

Here you can find the overall conclusion based on the various metadata and gathered information during the work of Stan on this project.

  • Project health: 100%

    This number was calculated based on the total number of used inspections and the number of triggered inspections in the project. The calculated number also defines the overall project health status.
  • The project is healthy

    Excellent work! Stan haven't found any vulnerabilities in the code.
  • Congratulations! Your project has zero vulnerabilities!

    Stan carefully run all configured inspection and found 0 observations and vulnerabilities to the project.

Observations

Based on the analysis results, Stan found different vulnerabilities distributed among the analysed files. In Stan terminology, we call such vulnerability as Observation. Below you can see the more detailed information about each observation, and find the possible ways to fix them for your project.

Configurations

This section describes the final Stan configuration that was used on the project and explains how this result was assembled. Stan runtime settings have many parts, and each of them can come from different configuration sources. Stan is using Environment variables, TOML configuration file and CLI arguments to get the final results. If some option is specified through the multiple sources, the most prioritized one is used.

ActionFilterScope

Configuration Process Information

Information and warnings that were gathered during the configuration assemble process. This helps to understand how different parts of the configurations were retrieved.

  • No TOML value is specified for key: check
  • No CLI option specified for: checks
  • configChecks is set through the source: TOML
  • No TOML value is specified for key: remove
  • No CLI option specified for: remove
  • configRemoved is set through the source: TOML
  • No TOML value is specified for key: ignore
  • No CLI option specified for: ignore
  • configIgnored is set through the source: TOML

Report Explained

Inspections

List of Inspections used for analysing the project

Inspection STAN-0001

Partial: base/head

Usage of partial function 'head' for lists

Warning
  • Partial
  • List

Possible solutions

  • Replace list with 'NonEmpty' from 'Data.List.NonEmpty'
  • Use explicit pattern-matching over lists

Inspection STAN-0002

Partial: base/tail

Usage of partial function 'tail' for lists

Warning
  • Partial
  • List

Possible solutions

  • Replace list with 'NonEmpty' from 'Data.List.NonEmpty'
  • Use explicit pattern-matching over lists

Inspection STAN-0003

Partial: base/init

Usage of partial function 'init' for lists

Warning
  • Partial
  • List

Possible solutions

  • Replace list with 'NonEmpty' from 'Data.List.NonEmpty'
  • Use explicit pattern-matching over lists

Inspection STAN-0004

Partial: base/last

Usage of partial function 'last' for lists

Warning
  • Partial
  • List

Possible solutions

  • Replace list with 'NonEmpty' from 'Data.List.NonEmpty'
  • Use explicit pattern-matching over lists

Inspection STAN-0005

Partial: base/!!

Usage of partial function '!!' for lists

Warning
  • Partial
  • List

Inspection STAN-0006

Partial: base/cycle

Usage of partial function 'cycle' for lists

Warning
  • Partial
  • List

Possible solutions

  • Replace list with 'NonEmpty' from 'Data.List.NonEmpty'
  • Use explicit pattern-matching over lists

Inspection STAN-0007

Partial: base/genericIndex

Usage of partial function 'genericIndex' for lists

Warning
  • Partial
  • List

Inspection STAN-0008

Partial: base/fromJust

Usage of partial function 'fromJust' for 'Maybe'

Warning
  • Partial

Possible solutions

  • Use explicit pattern-matching over Maybe
  • Use one of the standard functions: 'maybe', 'fromMaybe'

Inspection STAN-0009

Partial: base/read

Usage of partial function 'read' for parsing 'String'

Warning
  • Partial

Possible solutions

  • Use 'readMaybe' or 'readEither' to handle failed parsing

Inspection STAN-0010

Partial: base/succ

Usage of partial function 'succ' for enumerable types

Warning
  • Partial

Possible solutions

  • Use '(+ 1)' for integral types (but be aware of arithmetic overflow)
  • {Extra dependency} Use 'next' from 'Relude.Extra.Enum' in 'relude'

Inspection STAN-0011

Partial: base/pred

Usage of partial function 'pred' for enumerable types

Warning
  • Partial

Possible solutions

  • Use '(- 1)' for integral types (but be aware of arithmetic overflow)
  • {Extra dependency} Use 'prev' from 'Relude.Extra.Enum' in 'relude'

Inspection STAN-0012

Partial: base/toEnum

Usage of partial function 'toEnum' for enumerable types

Warning
  • Partial

Possible solutions

  • {Extra dependency} Use 'safeToEnum' from 'Relude.Extra.Enum' in 'relude'

Inspection STAN-0013

Partial: base/maximum

Usage of partial function 'maximum' for

Warning
  • Partial

Inspection STAN-0014

Partial: base/minimum

Usage of partial function 'minimum' for

Warning
  • Partial

Inspection STAN-0015

Partial: base/maximumBy

Usage of partial function 'maximumBy' for

Warning
  • Partial

Inspection STAN-0016

Partial: base/minimumBy

Usage of partial function 'minimumBy' for

Warning
  • Partial

Inspection STAN-0017

Partial: base/foldl1

Usage of partial function 'foldl1' for

Warning
  • Partial

Inspection STAN-0018

Partial: base/foldl1'

Usage of partial function 'foldl1'' for lists

Warning
  • Partial
  • List

Possible solutions

  • Replace list with 'NonEmpty' from 'Data.List.NonEmpty'
  • Use explicit pattern-matching over lists

Inspection STAN-0019

Partial: base/foldr1

Usage of partial function 'foldr1' for

Warning
  • Partial

Inspection STAN-0020

Partial: base/fromList

Usage of partial function 'fromList' for

Warning
  • Partial

Inspection STAN-0021

Partial: base/fromInteger

Usage of partial function 'fromInteger' for

Warning
  • Partial

Inspection STAN-0101

Infinite: base/reverse

Usage of the 'reverse' function that hangs on infinite lists

PotentialBug
  • Infinite
  • List

Possible solutions

  • Don't use 'reverse' if you expect your function to work with infinite lists
  • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

Inspection STAN-0102

Infinite: base/isSuffixOf

Usage of the 'isSuffixOf' function that hangs on infinite lists

PotentialBug
  • Infinite
  • List

Possible solutions

  • Don't use 'isSuffixOf' if you expect your function to work with infinite lists
  • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

Inspection STAN-0103

Infinite: base/length

Usage of the 'length' function that hangs on infinite lists

PotentialBug
  • Infinite
  • List

Possible solutions

  • Don't use 'length' if you expect your function to work with infinite lists
  • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

Inspection STAN-0104

Infinite: base/genericLength

Usage of the 'genericLength' function that hangs on infinite lists

PotentialBug
  • Infinite
  • List

Possible solutions

  • Don't use 'genericLength' if you expect your function to work with infinite lists
  • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

Inspection STAN-0105

Infinite: base/sum

Usage of the 'sum' function that hangs on infinite lists

PotentialBug
  • Infinite
  • List

Possible solutions

  • Don't use 'sum' if you expect your function to work with infinite lists
  • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

Inspection STAN-0106

Infinite: base/product

Usage of the 'product' function that hangs on infinite lists

PotentialBug
  • Infinite
  • List

Possible solutions

  • Don't use 'product' if you expect your function to work with infinite lists
  • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

Inspection STAN-0201

Anti-pattern: [0 .. length xs]

Creating a list with wrong number of indices

PotentialBug
  • AntiPattern

Possible solutions

  • Replace '[0 .. length xs]' with '[0 .. length xs - 1]'
  • Use 'zip [0 ..] xs` to work with list of pairs: index and element

Inspection STAN-0202

Anti-pattern: foldl

Usage of space-leaking function 'foldl'

Error
  • SpaceLeak
  • AntiPattern

Possible solutions

  • Replace 'foldl' with 'foldl''
  • Use 'foldr (flip . f)` instead of 'foldl f'

Inspection STAN-0203

Anti-pattern: Data.ByteString.Char8.pack

Usage of 'pack' function that doesn't handle Unicode characters

Error
  • AntiPattern

Possible solutions

  • Convert to 'Text' and use 'encodeUtf8' from 'Data.Text.Encoding'
  • {Extra dependency} Use 'encodeUtf8' from 'relude'
  • {Extra dependency} Use the 'utf8-string' package

Inspection STAN-0204

Anti-pattern: HashMap size

Usage of 'size' or 'length' for 'HashMap' that runs in linear time

Performance
  • AntiPattern

Possible solutions

  • {Extra dependency} Switch to 'Map' from 'containers'

Inspection STAN-0205

Anti-pattern: HashSet size

Usage of 'size' or 'length' for 'HashSet' that runs in linear time

Performance
  • AntiPattern

Possible solutions

  • {Extra dependency} Switch to 'Set' from 'containers'

Inspection STAN-0206

Data types with non-strict fields

Defining lazy fields in data types can lead to unexpected space leaks

Performance
  • SpaceLeak
  • Syntax

Possible solutions

  • Add '!' before the type, e.g. !Int or !(Maybe Bool)
  • Enable the 'StrictData' extension: {-# LANGUAGE StrictData #-}

Inspection STAN-0207

Anti-pattern: Foldable methods on possibly error-prone structures

Usage of Foldable methods on (,), Maybe, Either

PotentialBug
  • AntiPattern

Possible solutions

  • Use more explicit functions with specific monomorphic types

Inspection STAN-0208

Anti-pattern: Slow 'length' for Text

Usage of 'length' for 'Text' that runs in linear time

Performance
  • AntiPattern

Possible solutions

  • {Extra dependency} Switch to 'ByteString' from 'bytestring'

Inspection STAN-0209

Anti-pattern: Slow 'nub' for lists

Usage of 'nub' on lists that runs in quadratic time

Performance
  • AntiPattern

Possible solutions

  • {Extra dependency} Switch list to 'Set' from 'containers'
  • {Extra dependency} Use 'ordNub/hashNub/sortNub/unstableNub' from 'relude'
  • {Extra dependency} Use 'nubOrd' from 'containers'
  • {Extra dependency} Use 'nubOrd' from 'extra'

Inspection STAN-0210

Anti-pattern: Slow 'for_' on ranges

Usage of 'for_' or 'forM_' on numerical ranges is slow

Performance
  • AntiPattern

Possible solutions

  • {Extra dependency} Use 'loop' library for fast monadic looping

Inspection STAN-0211

Anti-pattern: '</>' for URLs

Usage of '</>' for URLs results in the errors on Windows

Error
  • AntiPattern

Possible solutions

  • {Extra dependency} Use type-safe library for URLs
  • Concatenate URLs with slashes '/'

Inspection STAN-0212

Anti-pattern: unsafe functions

Usage of unsafe functions breaks referential transparency

Error
  • Unsafe
  • AntiPattern

Possible solutions

  • Remove 'undefined' or at least replace with 'error' to give better error messages
  • Replace 'unsafeCoerce' with 'coerce'
  • Rewrite the code to avoid using 'unsafePerformIO' and other unsafe IO functions

Inspection STAN-0213

Anti-pattern: Pattern matching on '_'

Pattern matching on '_' for sum types can create maintainability issues

Warning
  • AntiPattern

Possible solutions

  • Pattern match on each constructor explicitly
  • Add meaningful names to holes, e.g. '_anyOtherFailure'

Inspection STAN-0214

Anti-pattern: use 'compare'

Usage of multiple comparison operators instead of single 'compare'

Performance
  • AntiPattern

Possible solutions

  • Rewrite code to use single 'compare' instead of many comparison operators

Inspection STAN-0215

Anti-pattern: Slashes in paths

Usage of '/' or '\' in paths results in the errors on different operation systems

Error
  • AntiPattern

Possible solutions

  • {Extra dependency} Use '</>' operator from 'filepath'

Inspection STAN-0301

Missing fixity declaration for operator

Using the implicit default fixity for operator: infixl 9

Style
  • Syntax

Possible solutions

  • Add 'infix[l|r]' declaration to the operator with explicit precedence

Inspection STAN-0302

Big tuples

Using tuples of big size (>= 4) can decrease code readability

Style
  • AntiPattern
  • Syntax

Possible solutions

  • Consider defining and using a custom data type to improve code comprehension

Severity

We are using the following severity system to indicate the observation level

SeverityDescription
StyleCode style issues. Usually harmless.
PerformanceSerious defects that could cause slowness and space leaking.
PotentialBugHuman errors in code.
WarningPotential runtime errors on some inputs.
ErrorDangerous behaviour.