Skip to content
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
2 changes: 1 addition & 1 deletion src/FSharpLint.Core/Application/Configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module IgnoreFiles =
let isDirectory = path.EndsWith("/")

let getRegexSegments (path:string) =
path.Split([| '/' |], StringSplitOptions.RemoveEmptyEntries)
path.Split(Array.singleton '/', StringSplitOptions.RemoveEmptyEntries)
|> Array.map globToRegex

if path.StartsWith("!") then
Expand Down
2 changes: 1 addition & 1 deletion src/FSharpLint.Core/Application/Lint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ module Lint =
let loader = Ionide.ProjInfo.WorkspaceLoader.Create toolsPath
let notifications = ResizeArray<_>()
loader.Notifications.Add notifications.Add
let options = loader.LoadProjects [projectFilePath]
let options = loader.LoadProjects (List.singleton projectFilePath)
options
|> Seq.tryFind (fun opt -> opt.ProjectFileName = projectFilePath)
|> Option.map (fun proj -> Ionide.ProjInfo.FCS.mapToFSharpProjectOptions proj options)
Expand Down
6 changes: 3 additions & 3 deletions src/FSharpLint.Core/Framework/Ast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module Ast =

match op.idText with
| "op_PipeRight" | "op_PipeRight2" | "op_PipeRight3" ->
flattenFuncExpr [rhs] lhs
flattenFuncExpr (List.singleton rhs) lhs
| "op_PipeLeft" | "op_PipeLeft2" | "op_PipeLeft3" ->
flattenFuncExpr (lhs::flattened) rhs
| _ -> flattenFuncExpr (lhs::flattened) app
Expand Down Expand Up @@ -337,7 +337,7 @@ module Ast =
) andBangs
add <| Pattern pattern
| [] -> () // error case. @@TODO@@ any other handling needed here?
| SynExpr.Ident(ident) -> add <| Identifier([ident.idText], ident.idRange)
| SynExpr.Ident(ident) -> add <| Identifier(List.singleton ident.idText, ident.idRange)
| SynExpr.LongIdent(_, SynLongIdent(ident, _, _), _, range) ->
add <| Identifier(List.map (fun (identifier: Ident) -> identifier.idText) ident, range)
| SynExpr.IfThenElse(cond, body, Some(elseExpr), _, _, _, _) ->
Expand Down Expand Up @@ -404,7 +404,7 @@ module Ast =
add <| Type synType
add <| SimplePattern simplePattern
| SynSimplePat.Attrib(simplePattern, _, _) -> add <| SimplePattern simplePattern
| SynSimplePat.Id(identifier, _, _, _, _, _) -> add <| Identifier([identifier.idText], identifier.idRange)
| SynSimplePat.Id(identifier, _, _, _, _, _) -> add <| Identifier(List.singleton identifier.idText, identifier.idRange)

let inline private matchChildren node add =
match node with
Expand Down
12 changes: 6 additions & 6 deletions src/FSharpLint.Core/Framework/HintParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module HintParser =
let private plongident: (CharStream<unit> -> Reply<char list list>) =
choice
[ attempt (sepBy1 pident (skipChar '.'))
pident |>> fun identChars -> [identChars] ]
pident |>> List.singleton ]

let private pidentorop: (CharStream<unit> -> Reply<char list>) =
choice
Expand All @@ -86,9 +86,9 @@ module HintParser =
|>> (fun ((startIdent, idents), maybeOperator) ->
let identifiers = startIdent::idents
match maybeOperator with
| Some(operator) -> identifiers@[operator]
| Some(operator) -> identifiers @ (List.singleton operator)
| None -> identifiers)
attempt (pidentorop |>> fun identOrOpChars -> [identOrOpChars])
attempt (pidentorop |>> List.singleton)
plongident ]
|>> List.map charListToString

Expand Down Expand Up @@ -538,7 +538,7 @@ module HintParser =
let op = InfixOperator(prefix, remainingOpChars,
precedence, associativity, (),
fun remOpChars expr1 expr2 ->
let opIdent = Expression.Identifier [prefix + remOpChars]
let opIdent = Expression.Identifier (List.singleton (prefix + remOpChars))
Expression.InfixOperator(opIdent, expr1, expr2))
opp.AddOperator(op)

Expand All @@ -555,10 +555,10 @@ module HintParser =
if prefix = "&" then Expression.AddressOf(true, expr)
else if prefix = "&&" then Expression.AddressOf(false, expr)
else if prefix = "!" || prefix = "~" then
let opIdent = Expression.Identifier [prefix + remOpChars]
let opIdent = Expression.Identifier (List.singleton (prefix + remOpChars))
Expression.PrefixOperator(opIdent, expr)
else
let opIdent = Expression.Identifier ["~" + prefix + remOpChars]
let opIdent = Expression.Identifier (List.singleton ("~" + prefix + remOpChars))
Expression.PrefixOperator(opIdent, expr)

let prefixOp =
Expand Down
12 changes: 6 additions & 6 deletions src/FSharpLint.Core/Framework/HintParserUtilities.fs
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,21 @@ module MergeSyntaxTrees =
| HintExpr(Expression.Lambda(args, LambdaBody(body))) ->
[ for LambdaArg(arg) in args -> HintExpr arg
yield HintExpr body ]
| HintExpr(Expression.LambdaArg(arg)) -> [ HintExpr arg ]
| HintExpr(Expression.LambdaBody(body)) -> [ HintExpr body ]
| HintExpr(Expression.LambdaArg(arg)) -> List.singleton (HintExpr arg)
| HintExpr(Expression.LambdaBody(body)) -> List.singleton (HintExpr body )
| HintExpr(Expression.InfixOperator(Expression.Identifier([ "::" ]) as ident, lhs, rhs)) ->
[ HintExpr ident; HintExpr(Expression.Tuple([ lhs; rhs ])) ]
| HintExpr(Expression.InfixOperator(ident, lhs, rhs)) -> [ HintExpr ident; HintExpr lhs; HintExpr rhs ]
| HintExpr(Expression.PrefixOperator(ident, expr)) -> [ HintExpr ident; HintExpr expr ]
| HintExpr(Expression.AddressOf(_, expr)) -> [ HintExpr expr ]
| HintExpr(Expression.AddressOf(_, expr)) -> List.singleton (HintExpr expr)
| HintExpr(Expression.FunctionApplication(exprs))
| HintExpr(Expression.Tuple(exprs))
| HintExpr(Expression.List(exprs))
| HintExpr(Expression.Array(exprs)) -> List.map HintExpr exprs
| HintExpr(Expression.If(ifCond, bodyExpr, Some(elseExpr))) ->
[ HintExpr ifCond; HintExpr bodyExpr; HintExpr elseExpr ]
| HintExpr(Expression.If(ifCond, bodyExpr, None)) -> [ HintExpr ifCond; HintExpr bodyExpr ]
| HintExpr(Expression.Else(expression)) -> [ HintExpr expression ]
| HintExpr(Expression.Else(expression)) -> List.singleton (HintExpr expression)
| HintExpr(Expression.Identifier(_))
| HintExpr(Expression.Constant(_))
| HintExpr(Expression.Null)
Expand All @@ -180,7 +180,7 @@ module MergeSyntaxTrees =
| HintPat(Pattern.Array(patterns))
| HintPat(Pattern.List(patterns))
| HintPat(Pattern.Tuple(patterns)) -> List.map HintPat patterns
| HintPat(Pattern.Parentheses(pattern)) -> [ HintPat pattern ]
| HintPat(Pattern.Parentheses(pattern)) -> List.singleton (HintPat pattern)
| HintPat(Pattern.Variable(_))
| HintPat(Pattern.Identifier(_))
| HintPat(Pattern.Constant(_))
Expand Down Expand Up @@ -385,7 +385,7 @@ module MergeSyntaxTrees =
| _ -> failwith "Invalid state"

let private getEdges transposed =
getEdgesRec [ProcessTransposed(transposed)] None
getEdgesRec (List.singleton <| ProcessTransposed transposed) None

let mergeHints hints =
let transposed = hints |> List.map hintToList |> transposeHead
Expand Down
2 changes: 1 addition & 1 deletion src/FSharpLint.Core/Framework/Utilities.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module ExpressionUtilities =
open FSharp.Compiler.CodeAnalysis

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let private runner (args:AstNodeRuleParams) =
let checkNotMutable (ident:Ident) = fun () ->
let maybeSymbol =
checkFileResults.GetSymbolUseAtLocation(
ident.idRange.StartLine, ident.idRange.EndColumn, String.Empty, [ident.idText])
ident.idRange.StartLine, ident.idRange.EndColumn, String.Empty, List.singleton ident.idText)

match maybeSymbol with
| Some(symbol) -> isNotMutable symbol
Expand Down
27 changes: 20 additions & 7 deletions src/FSharpLint.Core/Rules/Conventions/FavourSingleton.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,28 @@ let runner args =
SuggestedFix = None
TypeChecks = List.Empty }
match args.AstNode with
| AstNode.Binding(SynBinding(_, _, _, _, _, _, _, _, _, expression, _, _, _)) ->
| AstNode.Expression(expression) ->
match expression with
| SynExpr.ArrayOrListComputed(_isArray, innerExpr, range) ->
| SynExpr.ArrayOrListComputed(_isArray, innerExpr, _) ->
match innerExpr with
| SynExpr.Const(_, range) ->
generateViolation range
| SynExpr.Ident _ ->
generateViolation range
| _ -> Array.empty
| SynExpr.ComputationExpr _
| SynExpr.For _
| SynExpr.ForEach _
| SynExpr.IfThenElse _
| SynExpr.IndexRange _
| SynExpr.LetOrUse _
| SynExpr.Match _
| SynExpr.Sequential _
| SynExpr.SequentialOrImplicitYield _
| SynExpr.Set _
| SynExpr.TryFinally _
| SynExpr.TryWith _
| SynExpr.While _
| SynExpr.YieldOrReturn _
| SynExpr.YieldOrReturnFrom _ ->
Array.empty
| _ ->
generateViolation expression.Range
| _ -> Array.empty
| _ -> Array.empty
let rule =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ let runner (args:AstNodeRuleParams) =
| AstNode.Expression(ExpressionUtilities.LetOrUse({Bindings = binding :: _}, true, _)) ->
match binding with
| SynBinding(headPat = pat) ->
getParameterWithBelowMinimumLength [pat]
getParameterWithBelowMinimumLength (List.singleton pat)
| AstNode.Expression(SynExpr.Lambda(_, _, lambdaArgs, _, _, _, _)) ->
let lambdaIdent = FunctionReimplementation.getLambdaParamIdent lambdaArgs
match lambdaIdent with
Expand All @@ -72,7 +72,7 @@ let runner (args:AstNodeRuleParams) =
| AstNode.Expression(SynExpr.For(_, _, identifier, _, _, _, _, _, _)) when isIdentifierTooShort identifier.idText ->
Array.singleton (identifier, identifier.idText, None)
| AstNode.Match(SynMatchClause(namePattern, _, _, _, _, _)) ->
getParameterWithBelowMinimumLength [namePattern]
getParameterWithBelowMinimumLength (List.singleton namePattern)
| AstNode.Binding(SynBinding(_, _, _, _, _, _, _, pattern, _, _, _, _, _)) ->
match pattern with
| SynPat.LongIdent(SynLongIdent(idents, _, _),_, _, SynArgPats.Pats(names), _, _) ->
Expand Down
6 changes: 3 additions & 3 deletions src/FSharpLint.Core/Rules/Hints/HintMatcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ module private MatchExpression =
let private matchExpr = function
| AstNode.Expression(ExpressionUtilities.Identifier([ident], _)) ->
let ident = identAsDecompiledOpName ident
Some(Expression.Identifier([ident]))
Some(Expression.Identifier(List.singleton ident))
| AstNode.Expression(SynExpr.LongIdent(_, ident, _, _)) ->
let identifier = List.map (fun (ident: Ident) -> ident.idText) ident.LongIdent
Some(Expression.Identifier(identifier))
Expand Down Expand Up @@ -192,7 +192,7 @@ module private MatchExpression =
| Some checkFile ->
let maybeSymbolUse =
checkFile.GetSymbolUseAtLocation(
ident.idRange.StartLine, ident.idRange.EndColumn, String.Empty, [ident.idText])
ident.idRange.StartLine, ident.idRange.EndColumn, String.Empty, List.singleton ident.idText)

match maybeSymbolUse with
| Some symbolUse ->
Expand Down Expand Up @@ -420,7 +420,7 @@ module private MatchExpression =
Expression.PrefixOperator(Expression.Identifier([op]), expr)) ->
matchHintExpr
(fun () -> arguments.SubHint(AstNode.Expression(rightExpr), expr) |> matchHintExpr returnEmptyMatch)
(arguments.SubHint(AstNode.Expression(opExpr), Expression.Identifier([op])))
(arguments.SubHint(AstNode.Expression(opExpr), Expression.Identifier(List.singleton op)))
| _ -> NoMatch

and [<TailCall>] private matchAddressOf arguments =
Expand Down
2 changes: 1 addition & 1 deletion src/FSharpLint.Core/Rules/NamingHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ let isMeasureType = isAttribute "Measure"

let isNotUnionCase (checkFile:FSharpCheckFileResults) (ident:Ident) =
let maybeSymbol = checkFile.GetSymbolUseAtLocation(
ident.idRange.StartLine, ident.idRange.EndColumn, String.Empty, [ident.idText])
ident.idRange.StartLine, ident.idRange.EndColumn, String.Empty, List.singleton ident.idText)

match maybeSymbol with
| Some(symbol) when (symbol.Symbol :? FSharpUnionCase) -> false
Expand Down
8 changes: 4 additions & 4 deletions tests/FSharpLint.Console.Tests/TestApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open NUnit.Framework
open FSharpLint.Console.Program

let getErrorsFromOutput (output:string) =
let splitOutput = output.Split([|Environment.NewLine|], StringSplitOptions.None)
let splitOutput = output.Split(Array.singleton Environment.NewLine, StringSplitOptions.None)

set [ for index in 1..splitOutput.Length - 1 do
if splitOutput.[index].StartsWith "Error" then yield splitOutput.[index - 1] ]
Expand Down Expand Up @@ -46,7 +46,7 @@ type TestConsoleApplication() =
let (returnCode, errors) = main [| "lint"; input.FileName |]

Assert.AreEqual(int ExitCode.Failure, returnCode)
Assert.AreEqual(set ["Consider changing `Signature` to be prefixed with `I`."], errors)
Assert.AreEqual(Set.singleton "Consider changing `Signature` to be prefixed with `I`.", errors)

[<Test>]
member _.``Lint source without any config, rule enabled in default config is triggered for given source.``() =
Expand All @@ -59,7 +59,7 @@ type TestConsoleApplication() =
let (returnCode, errors) = main [| "lint"; input |]

Assert.AreEqual(int ExitCode.Failure, returnCode)
Assert.AreEqual(set ["Consider changing `Signature` to be prefixed with `I`."], errors)
Assert.AreEqual(Set.singleton "Consider changing `Signature` to be prefixed with `I`.", errors)

[<Test>]
member _.``Lint source with valid config to disable rule, disabled rule is not triggered for given source.``() =
Expand Down Expand Up @@ -117,7 +117,7 @@ type TestConsoleApplication() =
let (returnCode, errors) = main [| "lint"; "--lint-config"; config.FileName; input |]

Assert.AreEqual(int ExitCode.Failure, returnCode)
Assert.AreEqual(set ["Use prefix syntax for generic type."], errors)
Assert.AreEqual(Set.singleton "Use prefix syntax for generic type.", errors)

[<TestFixture>]
type TestFileTypeInference() =
Expand Down
12 changes: 6 additions & 6 deletions tests/FSharpLint.Core.Tests/Framework/TestConfiguration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let configWithHints hints =
type TestConfiguration() =
[<Test>]
member _.``Ignore all files ignores any given file.``() =
let ignorePaths = [ IgnoreFiles.parseIgnorePath "*" ]
let ignorePaths = List.singleton (IgnoreFiles.parseIgnorePath "*")

let path = @"D:\dog\source.fs".ToPlatformIndependentPath()

Expand All @@ -24,7 +24,7 @@ type TestConfiguration() =

[<Test>]
member _.``Ignoring a file name not inside a path does not ignore the path``() =
let ignorePaths = [ IgnoreFiles.parseIgnorePath "cat" ]
let ignorePaths = List.singleton (IgnoreFiles.parseIgnorePath "cat")

let path = @"D:\dog\source.fs".ToPlatformIndependentPath()

Expand All @@ -33,7 +33,7 @@ type TestConfiguration() =

[<Test>]
member _.``Ignoring a file doesn't ignore a directory.``() =
let ignorePaths = [ IgnoreFiles.parseIgnorePath "dog" ]
let ignorePaths = List.singleton (IgnoreFiles.parseIgnorePath "dog")

let path = @"D:\dog\source.fs".ToPlatformIndependentPath()

Expand All @@ -42,7 +42,7 @@ type TestConfiguration() =

[<Test>]
member _.``Ignoring a directory doesn't ignore a file.``() =
let ignorePaths = [ IgnoreFiles.parseIgnorePath "source.fs/" ]
let ignorePaths = List.singleton (IgnoreFiles.parseIgnorePath "source.fs/")

let path = @"D:\dog\source.fs".ToPlatformIndependentPath()

Expand All @@ -51,7 +51,7 @@ type TestConfiguration() =

[<Test>]
member _.``Ignoring all files in a given directory ignores a given file from the directory.``() =
let ignorePaths = [ IgnoreFiles.parseIgnorePath "dog/*" ]
let ignorePaths = List.singleton (IgnoreFiles.parseIgnorePath "dog/*")

let path = @"D:\dog\source.fs".ToPlatformIndependentPath()

Expand All @@ -60,7 +60,7 @@ type TestConfiguration() =

[<Test>]
member _.``Ignoring a file that does not exist inside a directory that does exist does not ignore the file.``() =
let ignorePaths = [ IgnoreFiles.parseIgnorePath "dog/source1" ]
let ignorePaths = List.singleton (IgnoreFiles.parseIgnorePath "dog/source1")

let path = @"D:\dog\source.fs".ToPlatformIndependentPath()

Expand Down
15 changes: 7 additions & 8 deletions tests/FSharpLint.Core.Tests/Framework/TestFuzzyHintMatcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ do

let array = generateAst source |> astToArray

let hintTrie = MergeSyntaxTrees.mergeHints [toHint @"fun _ -> () ===> ignore"]
let hintTrie = MergeSyntaxTrees.mergeHints (List.singleton (toHint @"fun _ -> () ===> ignore"))

let matches = ResizeArray()

Expand All @@ -179,7 +179,7 @@ do

let array = generateAst source |> astToArray

let hintTrie = MergeSyntaxTrees.mergeHints [toHint @"List.isEmpty [] ===> true"]
let hintTrie = MergeSyntaxTrees.mergeHints (List.singleton (toHint @"List.isEmpty [] ===> true"))

let matches = ResizeArray()

Expand All @@ -197,7 +197,7 @@ do

let array = generateAst source |> astToArray

let hintTrie = MergeSyntaxTrees.mergeHints [toHint @"x + 0 ===> x"]
let hintTrie = MergeSyntaxTrees.mergeHints (List.singleton (toHint @"x + 0 ===> x"))

let matches = ResizeArray()

Expand All @@ -215,7 +215,7 @@ do

let array = generateAst source |> astToArray

let hintTrie = MergeSyntaxTrees.mergeHints [toHint @"~~~1 ===> x"]
let hintTrie = MergeSyntaxTrees.mergeHints (List.singleton (toHint @"~~~1 ===> x"))

let matches = ResizeArray()

Expand All @@ -234,8 +234,7 @@ do

let array = generateAst source |> astToArray

let hintTrie = MergeSyntaxTrees.mergeHints [toHint @"List.rev (List.rev x) ===> x"]

let hintTrie = MergeSyntaxTrees.mergeHints (List.singleton (toHint @"List.rev (List.rev x) ===> x"))
let matches = ResizeArray()

possibleMatches array hintTrie (fun n1 hint -> matches.Add(n1, hint))
Expand All @@ -252,7 +251,7 @@ do

let array = generateAst source |> astToArray

let hintTrie = MergeSyntaxTrees.mergeHints [toHint @"fun x -> x ===> id"]
let hintTrie = MergeSyntaxTrees.mergeHints (List.singleton (toHint @"fun x -> x ===> id"))

let matches = ResizeArray()

Expand All @@ -270,7 +269,7 @@ do

let array = generateAst source |> astToArray

let hintTrie = MergeSyntaxTrees.mergeHints [toHint @"fun x -> x ===> id"]
let hintTrie = MergeSyntaxTrees.mergeHints (List.singleton (toHint @"fun x -> x ===> id"))

let matches = ResizeArray()

Expand Down
Loading
Loading