Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<PackageVersion Include="BenchmarkDotNet" Version="0.15.2" />
<PackageVersion Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.15.2" />
<PackageVersion Include="FParsec" Version="1.1.1" />
<PackageVersion Include="FSharp.Compiler.Service" Version="43.9.201" />
<PackageVersion Include="FSharp.Compiler.Service" Version="43.10.100" />
<PackageVersion Include="FSharp.Control.Reactive" Version="6.1.2" />
<PackageVersion Include="FSharp.Core" Version="9.0.201" />
<PackageVersion Include="FSharp.Core" Version="10.0.100" />
<PackageVersion Include="FSharpx.Collections" Version="3.1.0" />
<PackageVersion Include="Ionide.ProjInfo.ProjectSystem" Version="0.70.2" />
<PackageVersion Include="Ionide.ProjInfo.FCS" Version="0.70.2" />
Expand Down
44 changes: 24 additions & 20 deletions src/FSharpLint.Core/Framework/Ast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ module Ast =
| SynPat.Attrib(pattern, _, _)
| SynPat.Paren(pattern, _) -> add <| Pattern pattern
| SynPat.Named(_) -> ()
| SynPat.Record(patternsAndIdentifier, _) -> List.revIter (fun (_, _, pattern) -> pattern |> Pattern |> add) patternsAndIdentifier
| SynPat.Record(patPairFieldList, _) -> patPairFieldList |> List.revIter(_.Pattern >> Pattern >> add)
| SynPat.Const(_)
| SynPat.Wild(_)
| SynPat.FromParseError(_)
Expand Down Expand Up @@ -278,6 +278,8 @@ module Ast =
| SynExpr.Lazy(expression, _)
| SynExpr.TraitCall(_, _, expression, _)
| SynExpr.YieldOrReturn(_, expression, _, _)
| SynExpr.AnonRecd(_, Some (expression, _), _, _, _)
| SynExpr.IndexFromEnd(expression, _)
| SynExpr.YieldOrReturnFrom(_, expression, _, _) -> add <| Expression expression
| SynExpr.SequentialOrImplicitYield(_, expression1, expression2, ifNotExpression, _) ->
addMany [Expression expression1; Expression expression2; Expression ifNotExpression]
Expand All @@ -296,23 +298,12 @@ module Ast =
| SynExpr.Tuple(_, expressions, _, _)
| SynExpr.ArrayOrList(_, expressions, _) -> List.revIter (Expression >> add) expressions
| SynExpr.Record(_, Some(expr, _), _, _) -> add <| Expression expr
| SynExpr.Record(_, None, _, _) -> ()
| SynExpr.AnonRecd(_, Some (expr,_), _, _, _) ->
add <| Expression expr
| SynExpr.AnonRecd(_, None, _, _, _) -> ()
| SynExpr.ObjExpr(synType, _, _, bindings, _, _, _, _) ->
List.revIter (Binding >> add) bindings
add <| Type synType
| SynExpr.DotNamedIndexedPropertySet(expression, _, expression1, expression2, _)
| SynExpr.For(_, _, _, _, expression, _, expression1, expression2, _) ->
addMany [Expression expression2; Expression expression1; Expression expression]
| SynExpr.LetOrUseBang(_, _, _, pattern, rightHandSide, andBangs, leftHandSide, _, _) ->
addMany [Expression rightHandSide; Expression leftHandSide]
// TODO: is the the correct way to handle the new `and!` syntax?
List.iter (fun (SynExprAndBang(_, _, _, pattern, body, _, _)) ->
addMany [Expression body; Pattern pattern]
) andBangs
add <| Pattern pattern
| SynExpr.ForEach(_, _, _, _, pattern, expression, expression1, _) ->
addMany [Expression expression1; Expression expression; Pattern pattern]
| SynExpr.MatchLambda(_, _, matchClauses, _, _) ->
Expand All @@ -330,9 +321,22 @@ module Ast =
| SynExpr.Upcast(expression, synType, _)
| SynExpr.Downcast(expression, synType, _) ->
addMany [Type synType; Expression expression]
| SynExpr.LetOrUse(_, _, bindings, expression, _, _) ->
// regular let or use
| SynExpr.LetOrUse(_, _, _, false, bindings, expression, _, _) ->
add <| Expression expression
List.revIter (Binding >> add) bindings
// let! or use!
| SynExpr.LetOrUse(_, _, _, true, bindings, leftHandSide, _, _) ->
match bindings with
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

| firstBinding :: andBangs ->
match firstBinding with
| SynBinding(headPat = pattern; expr = rightHandSide) ->
addMany [Expression rightHandSide; Expression leftHandSide]
List.iter (fun (SynBinding(headPat = pattern; expr = body)) ->
addMany [Expression body; Pattern pattern]
) andBangs
add <| Pattern pattern
| [] -> () // error case. @@TODO@@ any other handling needed here?
| SynExpr.Ident(ident) -> add <| Identifier([ident.idText], ident.idRange)
| SynExpr.LongIdent(_, SynLongIdent(ident, _, _), _, range) ->
add <| Identifier(List.map (fun (identifier: Ident) -> identifier.idText) ident, range)
Expand Down Expand Up @@ -362,17 +366,17 @@ module Ast =
| SynExpr.DotLambda(_)
| SynExpr.App(_)
| SynExpr.Fixed(_) -> ()
*)
| SynExpr.Record(_, None, _, _) -> ()
| SynExpr.AnonRecd(_, None, _, _, _) -> ()
| SynExpr.Typar(_) -> ()
| SynExpr.WhileBang(_, expression, expression1, _) ->
*)
| SynExpr.WhileBang(_, expression1, expression2, _) ->
add <| Expression expression1
add <| Expression expression
add <| Expression expression2
| SynExpr.DebugPoint(_debugPoint, _, innerExpr) ->
add <| Expression innerExpr
| SynExpr.Dynamic(funcExpr, _, argExpr, _) ->
addMany [Expression funcExpr; Expression argExpr]
| SynExpr.IndexFromEnd(expr, _) ->
add <| Expression expr
| SynExpr.IndexRange(expr1, _, expr2, _, _, _) ->
expr1 |> Option.iter (Expression >> add)
expr2 |> Option.iter (Expression >> add)
Expand Down Expand Up @@ -417,7 +421,7 @@ module Ast =
| SynArgPats.Pats(patterns) ->
patterns |> List.revIter (Pattern >> add)
| SynArgPats.NamePatPairs(namePatterns, _, _) ->
namePatterns |> List.revIter (fun (_, _, pattern) -> pattern |> Pattern |> add)
namePatterns |> List.revIter (_.Pattern >> Pattern >> add)

let inline private typeRepresentationChildren node add =
match node with
Expand Down Expand Up @@ -474,7 +478,7 @@ module Ast =
| Else(expression)
| Expression(expression) -> expressionChildren expression add

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

| UnionCase(unionCase) -> unionCaseChildren unionCase add
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ let isLetBinding index (syntaxArray:AbstractSyntaxArray.Node []) =
if index > 0 then
match syntaxArray.[syntaxArray.[index].ParentIndex].Actual with
| AstNode.ModuleDeclaration(SynModuleDecl.Let(_))
| AstNode.Expression(SynExpr.LetOrUse(_, false, _, _, _, _)) -> true
| AstNode.Expression(SynExpr.LetOrUse(_, false, _, false, _, _, _, _)) -> true
| _ -> false
else false
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let private runner (args:AstNodeRuleParams) =
let bindingRange =
match args.GetParents(args.NodeIndex) with
| AstNode.ModuleDeclaration(SynModuleDecl.Let(_, _, range)) :: _
| AstNode.Expression(SynExpr.LetOrUse(_, false, _, _, range, _)) :: _ ->
| AstNode.Expression(SynExpr.LetOrUse(_, false, _, false, _, _, range, _)) :: _ ->
Some(range)
| _ -> None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let private runner (args:AstNodeRuleParams) =
match args.GetParents(args.NodeIndex) with
| AstNode.ModuleDeclaration(SynModuleDecl.Let(_, _, range)) :: _ ->
Some({ FromRange = range; FromText = "let"; ToText = String.Empty })
| AstNode.Expression(SynExpr.LetOrUse(_, false, _, _, range, _)) :: _ ->
| AstNode.Expression(SynExpr.LetOrUse(_, false, _, false, _, _, range, _)) :: _ ->
Some({ FromRange = range; FromText = "use"; ToText = String.Empty })
| _ -> None
match args.AstNode with
Expand Down
4 changes: 2 additions & 2 deletions src/FSharpLint.Core/Rules/Conventions/DisallowShadowing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let rec private processExpressions
(processArgs: SynSimplePats -> bool)
(expressions: list<SynExpr>) =
match expressions with
| SynExpr.LetOrUse(_, _, bindings, _, _, _) :: rest ->
| SynExpr.LetOrUse(_, _, _, false, bindings, _, _, _) :: rest ->
bindings |> List.exists processBinding
|| processExpressions processBinding processArgs rest
| SynExpr.Sequential(_, _, expr1, expr2, _, _) :: rest ->
Expand Down Expand Up @@ -65,7 +65,7 @@ let rec private processPatterns (definitionsAndPatterns: list<array<FSharpSymbol
| (definitions, SynPat.Paren(pat, _)) :: rest ->
processPatterns ((definitions, pat) :: rest)
| (definitions, SynPat.Record(fieldPats, _)) :: rest ->
processPatterns ((fieldPats |> List.map (fun (_, _, pat) -> (definitions, pat))) @ rest)
processPatterns ((fieldPats |> List.map (fun patPairField -> (definitions, patPairField.Pattern))) @ rest)
| (definitions, SynPat.Tuple(_, pats, _, _)) :: rest ->
processPatterns ((pats |> List.map (fun pat -> (definitions, pat))) @ rest)
| (definitions, SynPat.Typed(pat, _, _)) :: rest ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ let runner (args: AstNodeRuleParams) =
funcs
|> List.choose (processFunction false checkInfo funcs)
|> List.toArray
| AstNode.Expression(SynExpr.LetOrUse(true, _, bindings, _, _, _)), Some checkInfo ->
| AstNode.Expression(SynExpr.LetOrUse(true, _, _, false, bindings, _, _, _)), Some checkInfo ->
match UnneededRecKeyword.getRecursiveFunctionsFromBindings bindings with
| [] -> Array.empty
| funcs ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let rec private processLetBinding (instanceNames: Set<string>) (body: SynExpr) (
and [<TailCall>] processExpression (expression: SynExpr) (continuation: unit -> array<WarningDetails>) : array<WarningDetails> =
Array.append
(match expression with
| SynExpr.LetOrUse(_, _, bindings, body, _, _) ->
| SynExpr.LetOrUse(_, _, _, false, bindings, body, _, _) ->
let instanceNames = extraFromBindings bindings List.Empty |> Set.ofList
processLetBinding instanceNames body returnEmptyArray
| SynExpr.Sequential(_, _, expr1, expr2, _, _) ->
Expand All @@ -74,7 +74,7 @@ and [<TailCall>] processExpression (expression: SynExpr) (continuation: unit ->

let runner args =
match args.AstNode with
| Binding(SynBinding(_, _, _, _, _, _, _, _, _, SynExpr.LetOrUse(_, _, bindings, body, _, _), _, _, _)) ->
| Binding(SynBinding(_, _, _, _, _, _, _, _, _, SynExpr.LetOrUse(_, _, _, false, bindings, body, _, _), _, _, _)) ->
let instanceNames = extraFromBindings bindings List.Empty |> Set.ofList
processLetBinding instanceNames body returnEmptyArray
| Match(SynMatchClause(_, _, expr, _, _, _)) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ let rec private processExpressions (errorsSoFar: array<WarningDetails>) (args: A
| SynExpr.Record(_, _, synExprRecordFields, _) :: tail ->
let mapping =
function
| SynExprRecordField(_, _, expr, _) -> expr
| SynExprRecordField(_, _, expr, _, _) -> expr
let fieldExpressions =
synExprRecordFields
|> List.choose mapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ let runner (args:AstNodeRuleParams) =

let identifiers =
match args.AstNode with
| AstNode.Expression(SynExpr.LetOrUseBang(_, _, _, pat, _, _, _, _, _)) ->
getParameterWithBelowMinimumLength [pat]
| AstNode.Expression(SynExpr.LetOrUse(isBang = true; bindings = binding :: _)) ->
match binding with
| SynBinding(headPat = pat) ->
getParameterWithBelowMinimumLength [pat]
| AstNode.Expression(SynExpr.Lambda(_, _, lambdaArgs, _, _, _, _)) ->
let lambdaIdent = FunctionReimplementation.getLambdaParamIdent lambdaArgs
match lambdaIdent with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ let rec private innerGetPatternIdents<'Item> (accessibility:AccessControlLevel)
idents
(match args with
| SynArgPats.NamePatPairs(pats, _, _) ->
innerGetAllPatternIdents AccessControlLevel.Private getIdents (pats |> List.map (fun(_, _, synPat) -> synPat))
innerGetAllPatternIdents AccessControlLevel.Private getIdents (pats |> List.map _.Pattern)
| SynArgPats.Pats(pats) ->
innerGetAllPatternIdents AccessControlLevel.Private getIdents pats)
| SynPat.Named(_, _, access, _) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let checkRecursiveAsyncFunction (args:AstNodeRuleParams) (range:Range) (doBangEx
match crumb with
| AstNode.ModuleDeclaration (SynModuleDecl.Let (true, bindings, _)) ->
bindings
| AstNode.Expression (SynExpr.LetOrUse (true, false, bindings, _, _, _)) ->
| AstNode.Expression (SynExpr.LetOrUse (true, false, _, false, bindings, _, _, _)) ->
bindings
| _ -> List.Empty)
|> List.choose getFunctionNameFromAsyncCompExprBinding
Expand Down
3 changes: 1 addition & 2 deletions src/FSharpLint.Core/Rules/Conventions/RedundantNewKeyword.fs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ let runner args =
args.GetParents args.NodeIndex
|> List.tryFind
(function
| AstNode.Expression(SynExpr.LetOrUse(_, true, _, _, _, _)) -> true
| AstNode.Expression(SynExpr.LetOrUseBang(_, true, _, _, _, _, _, _, _)) -> true
| AstNode.Expression(SynExpr.LetOrUse(_, true, _, _, _, _, _, _)) -> true
| _ -> false)
match maybeUseBinding with
| Some _binding ->
Expand Down
13 changes: 10 additions & 3 deletions src/FSharpLint.Core/Rules/Formatting/Typography/Indentation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module ContextBuilder =
| (SynExpr.Record (_, _, fields, _)) ->
let newAcc = fields :: acc
fields
|> List.fold (fun currentAcc (SynExprRecordField(_, _, exprOpt, _)) ->
|> List.fold (fun currentAcc (SynExprRecordField(_, _, exprOpt, _, _)) ->
match exprOpt with
| Some expr -> collectRecordFieldsInner currentAcc expr
| None -> currentAcc
Expand Down Expand Up @@ -84,7 +84,7 @@ module ContextBuilder =
collectRecordFields record
|> List.collect (fun recordFields ->
recordFields
|> List.map (fun (SynExprRecordField((fieldName, _), _, _, _)) -> fieldName.Range)
|> List.map (fun (SynExprRecordField((fieldName, _), _, _, _, _)) -> fieldName.Range)
|> firstRangePerLine
|> createAbsoluteAndOffsetOverridesBasedOnFirst)
| Expression (SynExpr.ArrayOrListComputed(expr=(SynExpr.ComputationExpr(expr=expr)))) ->
Expand Down Expand Up @@ -131,7 +131,14 @@ module ContextBuilder =
|> createAbsoluteAndOffsetOverridesBasedOnFirst
| Pattern (SynPat.Record (fieldPats=fieldPats)) ->
fieldPats
|> List.map (fun ((_, fieldIdent), _, _) -> fieldIdent.idRange)
|> List.map (fun patPairField -> patPairField.Range)
// @@TODO@@ Do we need to look at the ranges inside FieldName here?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any comments on this one?

//let fieldIdent =
// match patPairField.FieldName.LongIdent with
// | [id] -> id
// | lid -> List.last lid
//
//fieldIdent.idRange)
|> firstRangePerLine
|> createAbsoluteAndOffsetOverridesBasedOnFirst
| _ -> List.Empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let rec checkExpression (expression: SynExpr) (range: range) (continuation: unit
}
| SynExpr.App (_, _, funcExpr, _, innerRange) ->
checkExpression funcExpr innerRange returnEmptyArray
| SynExpr.LetOrUse (_, _, _, body, innerRange, _) ->
| SynExpr.LetOrUse (_, _, _, false, _, body, innerRange, _) ->
checkExpression body innerRange returnEmptyArray
| _ -> Array.empty)
(continuation ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type TestAst() =
match ast with
| ParsedInput.ImplFile(implFile) ->
match implFile with
| ParsedImplFileInput(_, _, _, _, _, Module(app)::_, _, _, _) ->
| ParsedImplFileInput(_, _, _, _, Module(app)::_, _, _, _) ->
app
| _ -> failwith "Expected at least one module or namespace."
| _ -> failwith "Expected an implementation file."
Expand Down
Loading