Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error linting projects that use .NET Framework #657

Merged
merged 7 commits into from
Jan 8, 2024
Merged
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
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<DebugType>embedded</DebugType>
<NoWarn>$(NoWarn);NU1605</NoWarn>
</PropertyGroup>
</Project>
22 changes: 14 additions & 8 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ nuget Argu
nuget BenchmarkDotNet
nuget BenchmarkDotNet.Diagnostics.Windows
nuget FParsec
nuget FSharp.Compiler.Service ~> 40.0
nuget Ionide.ProjInfo.ProjectSystem ~> 0.53.0
nuget Ionide.ProjInfo.FCS ~> 0.53.0
nuget FSharp.Core
nuget nunit
nuget FSharp.Compiler.Service ~> 41.0.1
nuget Ionide.ProjInfo.ProjectSystem == 0.58.0
nuget Ionide.ProjInfo.FCS == 0.58.0
nuget Ionide.ProjInfo == 0.58.0
nuget Ionide.ProjInfo.Sln == 0.58.0
nuget FSharp.Core ~> 6.0
nuget nunit ~> 3.0
nuget System.Reactive ~> 5
nuget NUnit3TestAdapter
nuget Microsoft.NET.Test.Sdk 17.7.2
nuget Newtonsoft.Json
Expand All @@ -20,10 +23,10 @@ nuget Microsoft.Build.Locator
# don't expose as a package reference
nuget Microsoft.SourceLink.GitHub copy_local: true
# don't copy runtime assets
nuget Microsoft.Build.Framework copy_local: false
nuget Microsoft.Build.Framework == 16.11.0 copy_local: false
nuget Microsoft.Build.Tasks.Core copy_local: false
nuget Microsoft.Build.Utilities.Core copy_local: false
nuget Microsoft.Build copy_local: false
nuget Microsoft.Build.Utilities.Core == 16.11.0 copy_local: false
nuget Microsoft.Build == 16.11.0 copy_local: false

group Docs
source https://api.nuget.org/v3/index.json
Expand All @@ -43,6 +46,9 @@ group Build
storage: none
strategy: min

nuget System.Reactive ~> 5
nuget MSBuild.StructuredLogger == 2.1.815
nuget FSharp.Core ~> 5.0
nuget Fake.Core.Target
nuget Fake.Core.Process
nuget Fake.DotNet.Cli
Expand Down
1,470 changes: 515 additions & 955 deletions paket.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/FSharpLint.Console/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

open Argu
open System
open System.IO
open FSharpLint.Framework
open FSharpLint.Application
open System.Reflection
Expand Down Expand Up @@ -141,7 +142,7 @@ let private start (arguments:ParseResults<ToolArgs>) (toolsPath:Ionide.ProjInfo.

/// Must be called only once per process.
/// We're calling it globally so we can call main multiple times from our tests.
let toolsPath = Ionide.ProjInfo.Init.init()
let toolsPath = Ionide.ProjInfo.Init.init (DirectoryInfo <| Directory.GetCurrentDirectory()) None

[<EntryPoint>]
let main argv =
Expand Down
2 changes: 1 addition & 1 deletion src/FSharpLint.Core/Framework/AbstractSyntaxArray.fs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module AbstractSyntaxArray =
let private astNodeToSyntaxNode = function
| Expression(SynExpr.Null(_)) -> SyntaxNode.Null
| Expression(SynExpr.Tuple(_)) -> SyntaxNode.Tuple
| Expression(SynExpr.ArrayOrListOfSeqExpr(_))
| Expression(SynExpr.ArrayOrListComputed(_))
| Expression(SynExpr.ArrayOrList(_)) -> SyntaxNode.ArrayOrList
| Expression(SynExpr.AddressOf(_)) -> SyntaxNode.AddressOf
| Identifier(_) -> SyntaxNode.Identifier
Expand Down
92 changes: 54 additions & 38 deletions src/FSharpLint.Core/Framework/Ast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module Ast =
match exprToFlatten with
| SynExpr.App(_, _, x, y, _) ->
match x with
| SynExpr.App(_, true, SynExpr.Ident(op), rhs, _) as app ->
| SynExpr.App(_, true, SynExpr.LongIdent(_, SynLongIdent([op], _, _), _, _), rhs, _) as app ->
let lhs = y

match op.idText with
Expand Down Expand Up @@ -85,33 +85,33 @@ module Ast =
let rec removeAutoGeneratedMatchesFromLambda = function
| SynExpr.Match(DebugPointAtBinding.NoneAtInvisible,
_,
[SynMatchClause(SynPat.Wild(_), _, expr, _, _)], _) ->
[SynMatchClause(SynPat.Wild(_), _, expr, _, _, _)], _, _) ->
removeAutoGeneratedMatchesFromLambda expr
| x -> x

let (|IsCurriedLambda|_|) = function
| SynExpr.Lambda(_, _, parameter, (SynExpr.Lambda(_) as inner), _, _) as outer
| SynExpr.Lambda(_, _, parameter, (SynExpr.Lambda(_) as inner), _, _, _) as outer
when outer.Range = inner.Range ->
Some(parameter, inner)
| _ -> None

let rec getLambdaParametersAndExpression parameters = function
| IsCurriedLambda(parameter, curriedLambda) ->
getLambdaParametersAndExpression (parameter::parameters) curriedLambda
| SynExpr.Lambda(_, _, parameter, body, _, _) ->
| SynExpr.Lambda(_, _, parameter, body, _, _, _) ->
{ Arguments = parameter::parameters |> List.rev
Body = removeAutoGeneratedMatchesFromLambda body } |> Some
| _ -> None

match lambda with
| AstNode.Expression(SynExpr.Lambda(_, _, _, _, _, range) as lambda) ->
| AstNode.Expression(SynExpr.Lambda(_, _, _, _, _, range, _) as lambda) ->
getLambdaParametersAndExpression [] lambda
|> Option.map (fun x -> (x, range))
| _ -> None

let (|Cons|_|) pattern =
match pattern with
| SynPat.LongIdent(LongIdentWithDots([identifier], _),
| SynPat.LongIdent(SynLongIdent([identifier], _, _),
_, _,
SynArgPats.Pats([SynPat.Tuple(_, [lhs; rhs], _)]), _, _)
when identifier.idText = "op_ColonColon" ->
Expand All @@ -130,13 +130,13 @@ module Ast =

let inline private moduleDeclarationChildren node add =
match node with
| SynModuleDecl.NestedModule(componentInfo, _, moduleDeclarations, _, _) ->
| SynModuleDecl.NestedModule(componentInfo, _, moduleDeclarations, _, _, _) ->
moduleDeclarations |> List.revIter (ModuleDeclaration >> add)
add <| ComponentInfo componentInfo
| SynModuleDecl.Let(_, bindings, _) -> bindings |> List.revIter (Binding >> add)
| SynModuleDecl.DoExpr(_, expression, _) -> add <| Expression expression
| SynModuleDecl.Expr(expression, _) -> add <| Expression expression
| SynModuleDecl.Types(typeDefinitions, _) -> typeDefinitions |> List.revIter (TypeDefinition >> add)
| SynModuleDecl.Exception(SynExceptionDefn.SynExceptionDefn(repr, members, _), _) ->
| SynModuleDecl.Exception(SynExceptionDefn.SynExceptionDefn(repr, _, members, _), _) ->
members |> List.revIter (MemberDefinition >> add)
add <| ExceptionRepresentation repr
| SynModuleDecl.NamespaceFragment(moduleOrNamespace) -> add <| ModuleOrNamespace moduleOrNamespace
Expand All @@ -153,7 +153,7 @@ module Ast =
add <| Type synType
| SynType.Tuple(_, types, _) ->
types |> List.revIter (snd >> Type >> add)
| SynType.Fun(synType, synType1, _)
| SynType.Fun(synType, synType1, _, _)
| SynType.StaticConstantNamed(synType, synType1, _)
| SynType.MeasureDivide(synType, synType1, _) ->
add <| Type synType1
Expand Down Expand Up @@ -191,20 +191,23 @@ module Ast =
add <| Expression expression
add <| Type synType
| SynMemberDefn.LetBindings(bindings, _, _, _) -> bindings |> List.revIter (Binding >> add)
| SynMemberDefn.Interface(synType, Some(members), _) ->
| SynMemberDefn.Interface(synType, _, Some(members), _) ->
members |> List.revIter (MemberDefinition >> add)
add <| Type synType
| SynMemberDefn.Interface(synType, None, _)
| SynMemberDefn.Interface(synType, _, None, _)
| SynMemberDefn.Inherit(synType, _, _) -> add <| Type synType
| SynMemberDefn.Open(_)
| 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)
memberDefnForSet |> Option.iter (Binding >> add)

let inline private patternChildren node add =
match node with
Expand All @@ -213,16 +216,16 @@ module Ast =
| SynPat.Typed(pattern, synType, _) ->
add <| Type synType
add <| Pattern pattern
| SynPat.Or(pattern, pattern1, _) ->
| SynPat.Or(pattern, pattern1, _, _) ->
add <| Pattern pattern1
add <| Pattern pattern
| SynPat.ArrayOrList(_, patterns, _)
| SynPat.Tuple(_, patterns, _)
| SynPat.Ands(patterns, _) -> patterns |> List.revIter (Pattern >> add)
| SynPat.Attrib(pattern, _, _)
| SynPat.Named(pattern, _, _, _, _)
| SynPat.Paren(pattern, _) -> add <| Pattern pattern
| SynPat.Record(patternsAndIdentifier, _) -> patternsAndIdentifier |> List.revIter (snd >> Pattern >> add)
| SynPat.Named(_) -> ()
| SynPat.Record(patternsAndIdentifier, _) -> patternsAndIdentifier |> List.revIter (fun (_, _, pattern) -> pattern |> Pattern |> add)
| SynPat.Const(_)
| SynPat.Wild(_)
| SynPat.FromParseError(_)
Expand All @@ -235,6 +238,9 @@ module Ast =
add <| Pattern lhs
| SynPat.LongIdent(_, _, _, constructorArguments, _, _) ->
add <| ConstructorArguments constructorArguments
| SynPat.As(lhsPart, rhsPart, _) ->
add <| Pattern lhsPart
add <| Pattern rhsPart

let inline private expressionChildren node add =
match node with
Expand All @@ -244,8 +250,8 @@ module Ast =
| SynExpr.LongIdentSet(_, expression, _)
| SynExpr.Do(expression, _)
| SynExpr.Assert(expression, _)
| SynExpr.CompExpr(_, _, expression, _)
| SynExpr.ArrayOrListOfSeqExpr(_, expression, _)
| SynExpr.ComputationExpr(_, expression, _)
| SynExpr.ArrayOrListComputed(_, expression, _)
| SynExpr.AddressOf(_, expression, _, _)
| SynExpr.InferredDowncast(expression, _)
| SynExpr.InferredUpcast(expression, _)
Expand All @@ -264,7 +270,7 @@ module Ast =
| SynExpr.DotIndexedSet(expression, _, expression1, _, _, _)
| SynExpr.JoinIn(expression, _, expression1, _)
| SynExpr.While(_, expression, expression1, _)
| SynExpr.TryFinally(expression, expression1, _, _, _)
| SynExpr.TryFinally(expression, expression1, _, _, _, _)
| SynExpr.Set(expression, expression1, _)
| SynExpr.DotSet(expression, _, expression1, _) ->
add <| Expression expression1
Expand All @@ -279,7 +285,7 @@ module Ast =
| SynExpr.AnonRecd(_, Some (expr,_), _, _) ->
add <| Expression expr
| SynExpr.AnonRecd(_, None, _, _) -> ()
| SynExpr.ObjExpr(synType, _, bindings, _, _, _) ->
| SynExpr.ObjExpr(synType, _, _, bindings, _, _, _, _) ->
bindings |> List.revIter (Binding >> add)
add <| Type synType
| SynExpr.ImplicitZero(_)
Expand All @@ -293,28 +299,28 @@ module Ast =
| SynExpr.LibraryOnlyUnionCaseFieldSet(_)
| SynExpr.ArbitraryAfterError(_) -> ()
| SynExpr.DotNamedIndexedPropertySet(expression, _, expression1, expression2, _)
| SynExpr.For(_, _, expression, _, expression1, expression2, _) ->
| SynExpr.For(_, _, _, _, expression, _, expression1, expression2, _) ->
add <| Expression expression2
add <| Expression expression1
add <| Expression expression
| SynExpr.LetOrUseBang(_, _, _, pattern, rightHandSide, andBangs, leftHandSide, _) ->
| SynExpr.LetOrUseBang(_, _, _, pattern, rightHandSide, andBangs, leftHandSide, _, _) ->
add <| Expression rightHandSide
add <| Expression leftHandSide
// TODO: is the the correct way to handle the new `and!` syntax?
andBangs |> List.iter (fun (_, _, _, pattern, body, _) ->
andBangs |> List.iter (fun (SynExprAndBang(_, _, _, pattern, body, _, _)) ->
add <| Expression body
add <| Pattern pattern
)
add <| Pattern pattern
| SynExpr.ForEach(_, _, _, pattern, expression, expression1, _) ->
| SynExpr.ForEach(_, _, _, _, pattern, expression, expression1, _) ->
add <| Expression expression1
add <| Expression expression
add <| Pattern pattern
| SynExpr.MatchLambda(_, _, matchClauses, _, _) ->
matchClauses |> List.revIter (Match >> add)
| SynExpr.TryWith(expression, _, matchClauses, _, _, _, _)
| SynExpr.MatchBang(_, expression, matchClauses, _)
| SynExpr.Match(_, expression, matchClauses, _) ->
| SynExpr.TryWith(expression, matchClauses, _, _, _, _)
| SynExpr.MatchBang(_, expression, matchClauses, _, _)
| SynExpr.Match(_, expression, matchClauses, _, _) ->
matchClauses |> List.revIter (Match >> add)
add <| Expression expression
| SynExpr.TypeApp(expression, _, types, _, _, _, _) ->
Expand All @@ -326,11 +332,11 @@ module Ast =
| SynExpr.Downcast(expression, synType, _) ->
add <| Type synType
add <| Expression expression
| SynExpr.LetOrUse(_, _, bindings, expression, _) ->
| SynExpr.LetOrUse(_, _, bindings, expression, _, _) ->
add <| Expression expression
bindings |> List.revIter (Binding >> add)
| SynExpr.Ident(ident) -> add <| Identifier([ident.idText], ident.idRange)
| SynExpr.LongIdent(_, LongIdentWithDots(ident, _), _, range) ->
| SynExpr.LongIdent(_, SynLongIdent(ident, _, _), _, range) ->
add <| Identifier(ident |> List.map (fun x -> x.idText), range)
| SynExpr.IfThenElse(cond, body, Some(elseExpr), _, _, _, _) ->
add <| Else elseExpr
Expand All @@ -351,6 +357,16 @@ module Ast =
| SynExpr.Lambda(_)
| SynExpr.App(_)
| SynExpr.Fixed(_) -> ()
| SynExpr.DebugPoint(_debugPoint, _, innerExpr) ->
add <| Expression innerExpr
| SynExpr.Dynamic(funcExpr, _, argExpr, _) ->
add <| Expression funcExpr
add <| Expression argExpr
| SynExpr.IndexFromEnd(expr, _) ->
add <| Expression expr
| SynExpr.IndexRange(expr1, _, expr2, _, _, _) ->
expr1 |> Option.iter (Expression >> add)
expr2 |> Option.iter (Expression >> add)

let inline private typeSimpleRepresentationChildren node add =
match node with
Expand Down Expand Up @@ -381,11 +397,11 @@ module Ast =

let inline private matchChildren node add =
match node with
| SynMatchClause(pattern, Some(expression), expression1, _, _) ->
| SynMatchClause(pattern, Some(expression), expression1, _, _, _) ->
add <| Expression expression1
add <| Expression expression
add <| Pattern pattern
| SynMatchClause(pattern, None, expression1, _, _) ->
| SynMatchClause(pattern, None, expression1, _, _, _) ->
add <| Expression expression1
add <| Pattern pattern

Expand All @@ -394,7 +410,7 @@ module Ast =
| SynArgPats.Pats(patterns) ->
patterns |> List.revIter (Pattern >> add)
| SynArgPats.NamePatPairs(namePatterns, _) ->
namePatterns |> List.revIter (snd >> Pattern >> add)
namePatterns |> List.revIter (fun (_, _, pattern) -> pattern |> Pattern |> add)

let inline private typeRepresentationChildren node add =
match node with
Expand All @@ -416,14 +432,14 @@ module Ast =
let traverseNode node add =
match node with
| ModuleDeclaration(x) -> moduleDeclarationChildren x add
| ModuleOrNamespace(SynModuleOrNamespace(_, _, _, moduleDeclarations, _, _, _, _)) ->
| ModuleOrNamespace(SynModuleOrNamespace(_, _, _, moduleDeclarations, _, _, _, _, _)) ->
moduleDeclarations |> List.revIter (ModuleDeclaration >> add)
| Binding(SynBinding(_, _, _, _, _, _, _, pattern, _, expression, _, _)) ->
| Binding(SynBinding(_, _, _, _, _, _, _, pattern, _, expression, _, _, _)) ->
add <| Expression expression
add <| Pattern pattern
| ExceptionRepresentation(SynExceptionDefnRepr.SynExceptionDefnRepr(_, unionCase, _, _, _, _)) ->
add <| UnionCase unionCase
| TypeDefinition(SynTypeDefn(componentInfo, typeRepresentation, members, implicitCtor, _)) ->
| TypeDefinition(SynTypeDefn(componentInfo, typeRepresentation, members, implicitCtor, _, _)) ->
implicitCtor |> Option.iter (MemberDefinition >> add)
members |> List.revIter (MemberDefinition >> add)
add <| TypeRepresentation typeRepresentation
Expand All @@ -438,7 +454,7 @@ module Ast =
| SimplePattern(x) -> simplePatternChildren x add
| LambdaArg(x)
| SimplePatterns(x) -> simplePatternsChildren x add
| InterfaceImplementation(SynInterfaceImpl(synType, bindings, _)) ->
| InterfaceImplementation(SynInterfaceImpl(synType, _, bindings, _, _)) ->
bindings |> List.revIter (Binding >> add)
add <| Type synType
| TypeRepresentation(x) -> typeRepresentationChildren x add
Expand All @@ -451,7 +467,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
12 changes: 8 additions & 4 deletions src/FSharpLint.Core/Framework/Utilities.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module ExpressionUtilities =

let (|Identifier|_|) = function
| SynExpr.Ident(ident) -> Some([ident], ident.idRange)
| SynExpr.LongIdent(_, longIdent, _, _) -> Some(longIdent.Lid, longIdent.Range)
| SynExpr.LongIdent(_, longIdent, _, _) -> Some(longIdent.LongIdent, longIdent.Range)
| _ -> None

let getSymbolFromIdent (checkFile:FSharpCheckFileResults option) expr =
Expand All @@ -52,7 +52,11 @@ module ExpressionUtilities =
PrettyNaming.DecompileOpName ident.idText
else ident.idText

let identAsCompiledOpName = PrettyNaming.CompileOpName
let identAsCompiledOpName (identName: string) =
if PrettyNaming.IsOperatorDisplayName identName then
PrettyNaming.CompileOpName identName
else
identName

/// Extracts an expression from parentheses e.g. ((x + 4)) -> x + 4
let rec removeParens = function
Expand All @@ -76,8 +80,8 @@ module ExpressionUtilities =
lid |> List.map (fun li -> li.idText) |> String.concat "."

/// Converts a LongIdentWithDots to a String.
let longIdentWithDotsToString (lidwd:LongIdentWithDots) =
lidwd.Lid |> longIdentToString
let longIdentWithDotsToString (lidwd: SynLongIdent) =
lidwd.LongIdent |> longIdentToString

/// Tries to find the source code within a given range.
let tryFindTextOfRange (range:Range) (text:string) =
Expand Down
Loading
Loading