Skip to content

Commit

Permalink
WIP: adapt code to FCS 43.8
Browse files Browse the repository at this point in the history
Adapt code to accomodate changes in new FCS version.
  • Loading branch information
webwarrior-ws committed Jan 31, 2024
1 parent 6e0a927 commit 2a291ba
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/FSharpLint.Core/Framework/AbstractSyntaxArray.fs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module AbstractSyntaxArray =
| Expression(_) -> SyntaxNode.Expression
| Pattern(SynPat.Ands(_)) -> SyntaxNode.And
| Pattern(SynPat.Or(_)) -> SyntaxNode.Or
| Pattern(Cons(_)) -> SyntaxNode.Cons
| Pattern(SynPat.ListCons(_)) -> SyntaxNode.Cons
| Pattern(SynPat.Wild(_)) -> SyntaxNode.Wildcard
| Pattern(SynPat.Const(constant, _)) -> constToSyntaxNode constant
| Pattern(SynPat.ArrayOrList(_)) -> SyntaxNode.ArrayOrList
Expand Down
64 changes: 41 additions & 23 deletions src/FSharpLint.Core/Framework/Ast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ module Ast =
match pattern with
| SynPat.LongIdent(SynLongIdent([identifier], _, _),
_, _,
SynArgPats.Pats([SynPat.Tuple(_, [lhs; rhs], _)]), _, _)
SynArgPats.Pats([SynPat.Tuple(_, [lhs; rhs], _, _)]), _, _)
when identifier.idText = "op_ColonColon" ->
Some(lhs, rhs)
| SynPat.ListCons(lhsPat, rhsPat, _, _) ->
Some(lhsPat, rhsPat)
| _ -> None

/// Gets a string literal from the AST.
Expand Down Expand Up @@ -151,13 +153,20 @@ module Ast =
| SynType.App(synType, _, types, _, _, _, _) ->
types |> List.revIter (Type >> add)
add <| Type synType
| SynType.Tuple(_, types, _) ->
types |> List.revIter (snd >> Type >> add)
| SynType.Tuple(_, typeSegments, _) ->
typeSegments
|> List.revIter
(fun segment ->
match segment with
| SynTupleTypeSegment.Type(typ) -> typ |> Type |> add
| _ -> ())
| SynType.Fun(synType, synType1, _, _)
| SynType.StaticConstantNamed(synType, synType1, _)
| SynType.MeasureDivide(synType, synType1, _) ->
| SynType.Or(synType, synType1, _, _)
| SynType.StaticConstantNamed(synType, synType1, _) ->
add <| Type synType1
add <| Type synType
| SynType.MeasurePower(synType, _, _) ->
add <| Type synType
| SynType.Var(_)
| SynType.Anon(_)
| SynType.LongIdent(_)
Expand All @@ -171,20 +180,26 @@ module Ast =
typeNames |> List.revIter (snd >> Type >> add)
| SynType.Paren(innerType, _) ->
add <| Type innerType
| SynType.FromParseError(_) ->
()
| SynType.Intersection(_, types, _, _) ->
types |> List.revIter (Type >> add)
| SynType.SignatureParameter(_, _, _, synType, _) ->
add <| Type synType


/// Concatenates the typed-or-untyped structure of `SynSimplePats` into a `SynSimplePat list` to keep other code
/// mostly unchanged.
let inline extractPatterns (simplePats:SynSimplePats) =
let rec loop pat acc =
let loop pat acc =
match pat with
| SynSimplePats.SimplePats(patterns, _range) -> patterns @ acc
| SynSimplePats.Typed(patterns, _type, _range) -> loop patterns acc
| SynSimplePats.SimplePats(patterns, _, _range) -> patterns @ acc
loop simplePats []

let inline private memberDefinitionChildren node add =
match node with
| SynMemberDefn.Member(binding, _) -> add <| Binding binding
| SynMemberDefn.ImplicitCtor(_, _, patterns, _, _, _) ->
| SynMemberDefn.ImplicitCtor(_, _, patterns, _, _, _, _) ->
let combinedPatterns = extractPatterns patterns
combinedPatterns |> List.revIter (SimplePattern >> add)
| SynMemberDefn.ImplicitInherit(synType, expression, _, _) ->
Expand All @@ -200,10 +215,10 @@ module Ast =
| SynMemberDefn.AbstractSlot(_) -> ()
| SynMemberDefn.ValField(field, _) -> add <| Field field
| SynMemberDefn.NestedType(typeDefinition, _, _) -> add <| TypeDefinition typeDefinition
| SynMemberDefn.AutoProperty(_, _, _, Some(synType), _, _, _, _, _, expression, _, _, _) ->
| SynMemberDefn.AutoProperty(_, _, _, Some(synType), _, _, _, _, _, expression, _, _) ->
add <| Expression expression
add <| Type synType
| SynMemberDefn.AutoProperty(_, _, _, None, _, _, _, _, _, expression, _, _, _) ->
| SynMemberDefn.AutoProperty(_, _, _, None, _, _, _, _, _, expression, _, _) ->
add <| Expression expression
| SynMemberDefn.GetSetMember(memberDefnForGet, memberDefnForSet, _, _) ->
memberDefnForGet |> Option.iter (Binding >> add)
Expand All @@ -220,7 +235,7 @@ module Ast =
add <| Pattern pattern1
add <| Pattern pattern
| SynPat.ArrayOrList(_, patterns, _)
| SynPat.Tuple(_, patterns, _)
| SynPat.Tuple(_, patterns, _, _)
| SynPat.Ands(patterns, _) -> patterns |> List.revIter (Pattern >> add)
| SynPat.Attrib(pattern, _, _)
| SynPat.Paren(pattern, _) -> add <| Pattern pattern
Expand All @@ -230,10 +245,9 @@ module Ast =
| SynPat.Wild(_)
| SynPat.FromParseError(_)
| SynPat.InstanceMember(_)
| SynPat.DeprecatedCharRange(_)
| SynPat.Null(_)
| SynPat.OptionalVal(_) -> ()
| Cons(lhs, rhs) ->
| SynPat.ListCons(lhs, rhs, _, _) ->
add <| Pattern rhs
add <| Pattern lhs
| SynPat.LongIdent(_, _, _, constructorArguments, _, _) ->
Expand Down Expand Up @@ -282,9 +296,9 @@ module Ast =
| SynExpr.ArrayOrList(_, expressions, _) -> expressions |> List.revIter (Expression >> add)
| SynExpr.Record(_, Some(expr, _), _, _) -> add <| Expression expr
| SynExpr.Record(_, None, _, _) -> ()
| SynExpr.AnonRecd(_, Some (expr,_), _, _) ->
| SynExpr.AnonRecd(_, Some (expr,_), _, _, _) ->
add <| Expression expr
| SynExpr.AnonRecd(_, None, _, _) -> ()
| SynExpr.AnonRecd(_, None, _, _, _) -> ()
| SynExpr.ObjExpr(synType, _, _, bindings, _, _, _, _) ->
bindings |> List.revIter (Binding >> add)
add <| Type synType
Expand Down Expand Up @@ -367,6 +381,13 @@ module Ast =
| SynExpr.IndexRange(expr1, _, expr2, _, _, _) ->
expr1 |> Option.iter (Expression >> add)
expr2 |> Option.iter (Expression >> add)
| SynExpr.DotLambda(expr, _, _) ->
expr |> Expression |> add
| SynExpr.Typar(typar, _) ->
()
| SynExpr.WhileBang(_, whileExpr, doExpr, _) ->
add <| Expression whileExpr
add <| Expression doExpr

let inline private typeSimpleRepresentationChildren node add =
match node with
Expand All @@ -381,11 +402,8 @@ module Ast =

let inline private simplePatternsChildren node add =
match node with
| SynSimplePats.SimplePats(simplePatterns, _) ->
| SynSimplePats.SimplePats(simplePatterns, _, _) ->
simplePatterns |> List.revIter (SimplePattern >> add)
| SynSimplePats.Typed(simplePatterns, synType, _) ->
add <| Type synType
add <| SimplePatterns simplePatterns

let inline private simplePatternChildren node add =
match node with
Expand All @@ -409,7 +427,7 @@ module Ast =
match node with
| SynArgPats.Pats(patterns) ->
patterns |> List.revIter (Pattern >> add)
| SynArgPats.NamePatPairs(namePatterns, _) ->
| SynArgPats.NamePatPairs(namePatterns, _, _) ->
namePatterns |> List.revIter (fun (_, _, pattern) -> pattern |> Pattern |> add)

let inline private typeRepresentationChildren node add =
Expand Down Expand Up @@ -448,7 +466,7 @@ module Ast =
| Type(x) -> typeChildren x add
| Match(x) -> matchChildren x add
| MemberDefinition(x) -> memberDefinitionChildren x add
| Field(SynField(_, _, _, synType, _, _, _, _)) -> add <| Type synType
| Field(SynField(_, _, _, synType, _, _, _, _, _)) -> add <| Type synType
| Pattern(x) -> patternChildren x add
| ConstructorArguments(x) -> constructorArgumentsChildren x add
| SimplePattern(x) -> simplePatternChildren x add
Expand All @@ -467,7 +485,7 @@ module Ast =
| Else(x)
| Expression(x) -> expressionChildren x add

| File(ParsedInput.ImplFile(ParsedImplFileInput(_, _, _, _, _, moduleOrNamespaces, _, _))) ->
| File(ParsedInput.ImplFile(ParsedImplFileInput(_, _, _, _, _, moduleOrNamespaces, _, _, _))) ->
moduleOrNamespaces |> List.revIter (ModuleOrNamespace >> add)

| UnionCase(x) -> unionCaseChildren x add
Expand Down
2 changes: 1 addition & 1 deletion src/FSharpLint.Core/Framework/AstInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module AstInfo =
| Other

let identifierTypeFromValData = function
| SynValData.SynValData(memberFlags, valInfo, _) ->
| SynValData.SynValData(memberFlags, valInfo, _, _) ->
match memberFlags with
| Some(memberFlags) ->
match memberFlags.MemberKind with
Expand Down
4 changes: 2 additions & 2 deletions src/FSharpLint.Core/Framework/Utilities.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ module ExpressionUtilities =

/// Converts an operator name e.g. op_Add to the operator symbol e.g. +
let identAsDecompiledOpName (ident:Ident) =
if ident.idText.StartsWith("op_") then
PrettyNaming.DecompileOpName ident.idText
if PrettyNaming.IsLogicalOpName ident.idText then
PrettyNaming.ConvertValLogicalNameToDisplayNameCore ident.idText
else ident.idText

let identAsCompiledOpName (identName: string) =
Expand Down
6 changes: 3 additions & 3 deletions src/FSharpLint.Core/Rules/Conventions/AvoidTooShortNames.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let private getParameterWithBelowMinimumLength (pats: SynPat list): (Ident * str
match pat with
| SynPat.Typed(typedPat, _, _) ->
loop (typedPat::tail) acc
| SynPat.Tuple(_, elementPats, _) ->
| SynPat.Tuple(_, elementPats, _, _) ->
loop elementPats acc
| _ -> loop (pat::tail) acc
| SynPat.LongIdent(_, _, _, argPats, _, _)::tail ->
Expand Down Expand Up @@ -77,12 +77,12 @@ let private getIdentifiers (args:AstNodeRuleParams) =
| SynPat.Named(SynIdent(identifier, _), _, _, _) when isIdentifierTooShort identifier.idText ->
(identifier, identifier.idText, None) |> Array.singleton
| _ -> Array.empty
| AstNode.Field(SynField(_, _, Some identifier, _, _, _, _, _)) when isIdentifierTooShort identifier.idText ->
| AstNode.Field(SynField(_, _, Some identifier, _, _, _, _, _, _)) when isIdentifierTooShort identifier.idText ->
(identifier, identifier.idText, None) |> Array.singleton
| AstNode.TypeDefinition(SynTypeDefn(componentInfo, _typeDef, _, _, _, _)) ->
let checkTypes types =
seq {
for SynTyparDecl(_attr, SynTypar(id, _, _)) in types do
for SynTyparDecl(_attr, SynTypar(id, _, _), _, _) in types do
if isIdentifierTooShort id.idText then
yield (id, id.idText, None)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let private checkTupleOfWildcards pattern identifier =
constructorName + "(" + arguments + ")"

match pattern with
| SynPat.Tuple(_isStruct, patterns, range) when List.length patterns > 1 && patterns |> List.forall isWildcard ->
| SynPat.Tuple(_isStruct, patterns, _commaRanges, range) when List.length patterns > 1 && patterns |> List.forall isWildcard ->
let errorFormat = Resources.GetString("RulesTupleOfWildcardsError")
let refactorFrom = constructorString (List.length patterns)
let refactorTo = (constructorString 1)
Expand All @@ -37,14 +37,14 @@ let private isTupleMemberArgs breadcrumbs tupleRange =
| _ -> None

match breadcrumbs with
| AstNode.Binding(MemberBindingArgs(SynPat.Tuple(_, _, range)))::AstNode.Expression(SynExpr.ObjExpr(_))::_
| AstNode.Binding(MemberBindingArgs(SynPat.Tuple(_, _, range)))::AstNode.MemberDefinition(_)::_ ->
| AstNode.Binding(MemberBindingArgs(SynPat.Tuple(_, _, _, range)))::AstNode.Expression(SynExpr.ObjExpr(_))::_
| AstNode.Binding(MemberBindingArgs(SynPat.Tuple(_, _, _, range)))::AstNode.MemberDefinition(_)::_ ->
tupleRange = range
| _ -> false

let private runner (args:AstNodeRuleParams) =
match args.AstNode with
| AstNode.Pattern(SynPat.LongIdent(identifier, _, _, SynArgPats.Pats([SynPat.Paren(SynPat.Tuple(_, _, range) as pattern, _)]), _, _)) ->
| AstNode.Pattern(SynPat.LongIdent(identifier, _, _, SynArgPats.Pats([SynPat.Paren(SynPat.Tuple(_, _, _, range) as pattern, _)]), _, _)) ->
let breadcrumbs = args.GetParents 2
if (not << isTupleMemberArgs breadcrumbs) range then
let identifier = identifier.LongIdent |> List.map (fun x -> x.idText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open FSharpLint.Framework.Ast
open FSharpLint.Framework.Rules

let rec getLambdaParamIdent = function
| SynSimplePats.SimplePats([pattern], _) ->
| SynSimplePats.SimplePats([pattern], _, _) ->
let rec getIdent = function
| SynSimplePat.Id(ident, _, _, _, _, _) -> ident
| SynSimplePat.Typed(simplePattern, _, _)
Expand All @@ -14,8 +14,6 @@ let rec getLambdaParamIdent = function

getIdent pattern |> Some
| SynSimplePats.SimplePats(_) -> None
| SynSimplePats.Typed(simplePatterns, _, _) ->
getLambdaParamIdent simplePatterns

let checkLambda (args:AstNodeRuleParams) checker =
match args.AstNode with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ let private validateLambdaIsNotPointless (text:string) lambda range =
let identifier =
identifier
|> List.map (fun x ->
if PrettyNaming.IsMangledOpName x.idText then
PrettyNaming.DecompileOpName x.idText |> sprintf "( %s )"
if PrettyNaming.IsLogicalOpName x.idText then
PrettyNaming.ConvertValLogicalNameToDisplayNameCore x.idText |> sprintf "( %s )"
else
x.idText)
|> String.concat "."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open FSharpLint.Rules.Helper.Naming

let private getIdentifiers (args:AstNodeRuleParams) =
match args.AstNode with
| AstNode.EnumCase(SynEnumCase(_, SynIdent(identifier, _), _, _, _, _, _)) ->
| AstNode.EnumCase(SynEnumCase(_, SynIdent(identifier, _), _, _, _, _)) ->
(identifier, identifier.idText, None) |> Array.singleton
| _ -> Array.empty

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let private getIdentifiers (args: AstNodeRuleParams) =
| AstNode.TypeDefinition(SynTypeDefn(componentInfo, _typeDef, _, _, _, _)) ->
let checkTypes types =
seq {
for SynTyparDecl(_attr, SynTypar(id, _, _)) in types do
for SynTyparDecl(_attr, SynTypar(id, _, _), _, _) in types do
yield (id, id.idText, None)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let private getIdentifiers (args:AstNodeRuleParams) =
Array.empty
| AstNode.MemberDefinition(memberDef) ->
match memberDef with
| SynMemberDefn.AbstractSlot(SynValSig(_, SynIdent(identifier, _), _, _, _, _, _, _, _, _, _, _), _, _) ->
| SynMemberDefn.AbstractSlot(SynValSig(_, SynIdent(identifier, _), _, _, _, _, _, _, _, _, _, _), _, _, _) ->
(identifier, identifier.idText, None) |> Array.singleton
| _ -> Array.empty
| _ -> Array.empty
Expand Down
13 changes: 8 additions & 5 deletions src/FSharpLint.Core/Rules/Conventions/Naming/NamingHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ let getAccessControlLevel (syntaxArray:AbstractSyntaxArray.Node []) i =
| TypeSimpleRepresentation(SynTypeDefnSimpleRepr.Record(access, _, _))
| TypeSimpleRepresentation(SynTypeDefnSimpleRepr.Union(access, _, _))
| UnionCase(SynUnionCase(_, _, _, _, access, _, _))
| Field(SynField(_, _, _, _, _, _, access, _))
| Field(SynField(_, _, _, _, _, _, access, _, _))
| ComponentInfo(SynComponentInfo(_, _, _, _, _, _, access, _))
| ModuleOrNamespace (SynModuleOrNamespace.SynModuleOrNamespace(_, _, _, _, _, _, access, _, _))
| ExceptionRepresentation(SynExceptionDefnRepr.SynExceptionDefnRepr(_, _, _, _, access, _))
Expand Down Expand Up @@ -318,12 +318,12 @@ let rec getPatternIdents<'T> (accessibility:AccessControlLevel) (getIdents:GetId

let hasNoArgs =
match args with
| SynArgPats.NamePatPairs(pats, _) -> pats.IsEmpty
| SynArgPats.NamePatPairs(pats, _, _) -> pats.IsEmpty
| SynArgPats.Pats(pats) -> pats.IsEmpty

let argSuggestions =
match args with
| SynArgPats.NamePatPairs(pats, _) ->
| SynArgPats.NamePatPairs(pats, _, _) ->
pats
|> List.toArray
|> Array.collect (fun(_, _, synPat) -> getPatternIdents AccessControlLevel.Private getIdents false synPat)
Expand All @@ -347,7 +347,7 @@ let rec getPatternIdents<'T> (accessibility:AccessControlLevel) (getIdents:GetId
| SynPat.Paren(p, _) ->
getPatternIdents accessibility getIdents false p
| SynPat.Ands(pats, _)
| SynPat.Tuple(_, pats, _)
| SynPat.Tuple(_, pats, _, _)
| SynPat.ArrayOrList(_, pats, _) ->
pats
|> List.toArray
Expand All @@ -361,11 +361,14 @@ let rec getPatternIdents<'T> (accessibility:AccessControlLevel) (getIdents:GetId
| SynPat.Const(_)
| SynPat.Wild(_)
| SynPat.OptionalVal(_)
| SynPat.DeprecatedCharRange(_) | SynPat.InstanceMember(_) | SynPat.FromParseError(_) -> Array.empty
| SynPat.InstanceMember(_) | SynPat.FromParseError(_) -> Array.empty
| SynPat.As(lhsPat, rhsPat, _) ->
Array.append
(getPatternIdents accessibility getIdents false lhsPat)
(getPatternIdents accessibility getIdents false rhsPat)
| SynPat.ListCons(lhsPat, rhsPat, _, _) ->
[|lhsPat; rhsPat|]
|> Array.collect (getPatternIdents accessibility getIdents false)

let rec identFromSimplePat = function
| SynSimplePat.Id(ident, _, _, _, _, _) -> Some ident
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let private getIdentifiers (args:AstNodeRuleParams) =
match args.AstNode with
| AstNode.MemberDefinition(memberDef) ->
match memberDef with
| SynMemberDefn.ImplicitCtor(_, _, ctorArgs, _, _, _) ->
| SynMemberDefn.ImplicitCtor(_, _, ctorArgs, _, _, _, _) ->
ctorArgs
|> extractPatterns
|> List.toArray
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let private getMembers (members:SynMemberDefn list) =
let isPublicMember = function
| SynMemberDefn.AbstractSlot(_) -> true
| SynMemberDefn.Member(SynBinding(access, _, _, _, _, _, _, _, _, _, _, _, _), _)
| SynMemberDefn.AutoProperty(_, _, _, _, _, _, _, access, _, _, _, _, _) -> isPublic access
| SynMemberDefn.AutoProperty(_, _, _, _, _, _, _, _, access, _, _, _) -> isPublic access
| _ -> false

members
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let private runner (args: AstNodeRuleParams) =
false,
_attributes,
_xmlDoc,
SynValData (Some memberFlags, _, _),
SynValData (Some memberFlags, _, _, _),
SynPat.LongIdent (memberIdentifier, _, _, argPats, _, _),
_returnInfo,
expr,
Expand Down
Loading

0 comments on commit 2a291ba

Please sign in to comment.