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.0.0
Git Revision8aa640171d5081c5e6607d3b8931e9fd9edcb6c4
Release DateThu Jun 18 15:20:16 2020 +0100
System Info
Operating Systemlinux
Architecturex86_64
Compilerghc
Compiler Version8.8
Environment
Environment Variables
TOML configuration files/home/vrom911/Kowainik/stan/.stan.toml
CLI argumentscheck --exclude --filter-all --directory=test/ check --exclude --filter-all --directory=src/ check --include --filter-all --file=src/Stan/Example.hs check --exclude --id=STAN-0103 --scope-all check --exclude --id=STAN-0001 --file=src/MyFile.hs ignore --id=OBS-00001 ignore --id=OBS-STAN-0212-emMVqk-114:21 report

Project Info

Information about the analysed project

Project namestan
Cabal Filesstan.cabal
HIE Files Directory.hie
Files Number64

Analysis Info

Summary stats from the static analysis

Modules55
LoC7169
Extensions30
SafeHaskel Extensions0
Available inspections44
Checked inspections43
Found Observations13
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.

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.

📄 src/Stan/Example.hs

  • ModuleStan.Example
    Lines of Code62
    1. ConstraintKinds
    2. DeriveGeneric
    3. DerivingStrategies
    4. GeneralizedNewtypeDeriving
    5. InstanceSigs
    6. KindSignatures
    7. LambdaCase
    8. OverloadedStrings
    9. RecordWildCards
    10. ScopedTypeVariables
    11. StandaloneDeriving
    12. TupleSections
    13. TypeApplications
    14. ViewPatterns
    1. NoUndecidableInstances
    2. PatternSynonyms
  • Observations

    IDOBS-STAN-0211-saA9eI-24:21
    SeverityError
    DescriptionUsage of '</>' for URLs results in the errors on Windows
    Inspection IDSTAN-0211
    Category
    • AntiPattern
    Filesrc/Stan/Example.hs
      23 ┃ 
      24 ┃ mkMyUrlPart myUrl = myUrl </> "asd"
      25 ┃                     ^^^^^^^^^^^^^^^
    

    Possible solutions

    • {Extra dependency} Use type-safe library for URLs
    • Concatenate URLs with slashes '/'
    IDOBS-STAN-0207-saA9eI-27:14
    SeverityPotentialBug
    DescriptionUsage of Foldable methods on (,), Maybe, Either
    Inspection IDSTAN-0207
    Category
    • AntiPattern
    Filesrc/Stan/Example.hs
      26 ┃ 
      27 ┃ pairLength = length ((1, 2) :: (Int, Int))
      28 ┃              ^^^^^^
    

    Possible solutions

    • Use more explicit functions with specific monomorphic types
    IDOBS-STAN-0201-saA9eI-30:16
    SeverityPotentialBug
    DescriptionCreating a list with wrong number of indices
    Inspection IDSTAN-0201
    Category
    • AntiPattern
    Filesrc/Stan/Example.hs
      29 ┃ 
      30 ┃ listIndxs xs = [0 .. length xs]
      31 ┃                ^^^^^^^^^^^^^^^^
    

    Possible solutions

    • Replace '[0 .. length xs]' with '[0 .. length xs - 1]'
    • Use 'zip [0 ..] xs` to work with list of pairs: index and element
    IDOBS-STAN-0203-saA9eI-33:16
    SeverityError
    DescriptionUsage of 'pack' function that doesn't handle Unicode characters
    Inspection IDSTAN-0203
    Category
    • AntiPattern
    Filesrc/Stan/Example.hs
      32 ┃ 
      33 ┃ toByteString = BS8.pack
      34 ┃                ^^^^^^^^
    

    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
    IDOBS-STAN-0215-saA9eI-36:13
    SeverityError
    DescriptionUsage of '/' or '\' in paths results in the errors on different operation systems
    Inspection IDSTAN-0215
    Category
    • AntiPattern
    Filesrc/Stan/Example.hs
      35 ┃ 
      36 ┃ pathToX x = "src/lib" </> x
      37 ┃             ^^^^^^^^^^^^^^^
    

    Possible solutions

    • {Extra dependency} Use '</>' operator from 'filepath'
    IDOBS-STAN-0001-saA9eI-39:20
    SeverityWarning
    DescriptionUsage of partial function 'head' for lists
    Inspection IDSTAN-0001
    Category
    • Partial
    • List
    Filesrc/Stan/Example.hs
      38 ┃ 
      39 ┃ getFirstIPromise = P.head
      40 ┃                    ^^^^^^
    

    Possible solutions

    • Replace list with 'NonEmpty' from 'Data.List.NonEmpty'
    • Use explicit pattern-matching over lists
    IDOBS-STAN-0009-saA9eI-42:12
    SeverityWarning
    DescriptionUsage of partial function 'read' for parsing 'String'
    Inspection IDSTAN-0009
    Category
    • Partial
    Filesrc/Stan/Example.hs
      41 ┃ 
      42 ┃ parseInt = P.read
      43 ┃            ^^^^^^
    

    Possible solutions

    • Use 'readMaybe' or 'readEither' to handle failed parsing
    IDOBS-STAN-0302-saA9eI-44:16
    SeverityStyle
    DescriptionUsing tuples of big size (>= 4) can decrease code readability
    Inspection IDSTAN-0302
    Category
    • AntiPattern
    • Syntax
    Filesrc/Stan/Example.hs
      43 ┃ 
      44 ┃ quad :: Int -> (Int, Int, Int, Int)
      45 ┃                ^^^^^^^^^^^^^^^^^^^^
    

    Possible solutions

    • Consider defining and using a custom data type to improve code comprehension
    IDOBS-STAN-0302-saA9eI-45:10
    SeverityStyle
    DescriptionUsing tuples of big size (>= 4) can decrease code readability
    Inspection IDSTAN-0302
    Category
    • AntiPattern
    • Syntax
    Filesrc/Stan/Example.hs
      44 ┃ 
      45 ┃ quad x = (x, x, x, x)
      46 ┃          ^^^^^^^^^^^^
    

    Possible solutions

    • Consider defining and using a custom data type to improve code comprehension
    IDOBS-STAN-0301-saA9eI-47:1
    SeverityStyle
    DescriptionUsing the implicit default fixity for operator: infixl 9
    Inspection IDSTAN-0301
    Category
    • Syntax
    Filesrc/Stan/Example.hs
      46 ┃ 
      47 ┃ (?+?) :: Int -> Int -> Int
      48 ┃ ^^^^^
    

    Possible solutions

    • Add 'infix[l|r]' declaration to the operator with explicit precedence
    IDOBS-STAN-0214-saA9eI-51:1
    SeverityPerformance
    DescriptionUsage of multiple comparison operators instead of single 'compare'
    Inspection IDSTAN-0214
    Category
    • AntiPattern
    Filesrc/Stan/Example.hs
      50 ┃ 
      51 ┃ isEq x y
      52 ┃     | x < y = False
      53 ┃     | x > y = False
      54 ┃     | otherwise = True
      55 ┃ ^^^^^^^^^^^^^^^^^^^^^^
    

    Possible solutions

    • Rewrite code to use single 'compare' instead of many comparison operators
    IDOBS-STAN-0213-saA9eI-57:37
    SeverityWarning
    DescriptionPattern matching on '_' for sum types can create maintainability issues
    Inspection IDSTAN-0213
    Category
    • AntiPattern
    Filesrc/Stan/Example.hs
      56 ┃ 
      57 ┃ prettyOrdering = \case {GT -> "GT"; _ -> "LT"}
      58 ┃                                     ^^^^^^^^^
    

    Possible solutions

    • Pattern match on each constructor explicitly
    • Add meaningful names to holes, e.g. '_anyOtherFailure'
    IDOBS-STAN-0206-saA9eI-61:7
    SeverityPerformance
    DescriptionDefining lazy fields in data types can lead to unexpected space leaks
    Inspection IDSTAN-0206
    Category
    • SpaceLeak
    • Syntax
    Filesrc/Stan/Example.hs
      60 ┃ 
      61 ┃     , userAge  :: Int
      62 ┃       ^^^^^^^^^^^^^^^
    

    Possible solutions

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

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
— Remove Directory: target/
∩ ExcludeAll inspectionsDirectory: test/
∩ ExcludeAll inspectionsDirectory: src/
∪ IncludeAll inspectionsFile: src/Stan/Example.hs
∩ ExcludeID: STAN-0103All files
∩ ExcludeID: STAN-0001File: src/MyFile.hs
✖ Ignore OBS-00001
✖ Ignore OBS-STAN-0212-emMVqk-114:21

Unrecognised Observations

Some observation IDs specified in the configurations are not found

  • OBS-00001
  • OBS-STAN-0212-emMVqk-114:21

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.

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

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-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 'bytesting'

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.