stan icon indicating copy to clipboard operation
stan copied to clipboard

[RFC] Design API for specifying custom inspections

Open chshersh opened this issue 5 years ago • 3 comments

Users may want to introduce their own inspections (e.g. forbidding their partial functions). It would be nice to be able to support this API as well.

My first thoughts (not a final proposal): add a new enum field in the Check data type, like:

data InspectionSource
    = Stan  -- Default, when missing
    | Custom

So users can write:

[[check]]
type = "Include"
source = "Custom"
...

What users can include for now:

  • Custom NameMetas to forbid custom functions
    • Question: How can they specify PatternType? We need some custom format and parser for PatternType, sounds like something that requires thinking... But if we can come up with that, we can also support custom PatternAst.

chshersh avatar May 27 '20 10:05 chshersh

Yes, we definitely need to start designing this feature. @chshersh , what do you think if we would support the creation of custom inspections through the other list in TOML config?

[[inspections]]
type = ForbidExtension
name = "NamedPunFields"
id = "123" # optional, we can use the same tactic we already have, but without a number
    # e.g. USER-DE-hash1234
    #           ^ DE is the code for the type of ins
... 
# I don'r know yet what else we need and how to name it

[[check]]
...
# what we had before

What do you think?

vrom911 avatar May 27 '20 11:05 vrom911

@vrom911 :egg:cellent proposal :+1: That makes more sense to me. And we can easily extend these possibilities further.

chshersh avatar May 27 '20 11:05 chshersh

I will try to share my thoughts of how :egg:zample of the custom inspection specifying can look like on something like STAN-0001 (partial head):

[[inspection]]
type = "ForbidName"
id = "MYAPP-0001"  # will become USER-MYAPP-0001
name = "Usage of partial 'head'"
description = "..."
solution = [ "...", "..." ]
category =  [ "List", "Partial" ]
severity = "PossibleBug"
nameMeta = { package = "base", module = "GHC.OldList", name = "head" }
patternType = { fun = { arg = { nameMeta = { "..." },  vars = { "..." } }, res = "?" } }

chshersh avatar May 28 '20 11:05 chshersh