Skip to content

Commit

Permalink
Core: fix FSharpLint warning
Browse files Browse the repository at this point in the history
Fixing the warning avoidSinglePipeOperator rule.
  • Loading branch information
Mersho committed Jan 11, 2024
1 parent bfb6323 commit 680b8a1
Show file tree
Hide file tree
Showing 72 changed files with 638 additions and 669 deletions.
414 changes: 213 additions & 201 deletions src/FSharpLint.Core/Application/Configuration.fs

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions src/FSharpLint.Core/Application/Lint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,17 @@ module Lint =
}

let indentationError =
config.LineRules.IndentationRule
|> Option.map (fun rule -> runLineRuleWithContext rule config.Context.IndentationRuleContext lineParams)
Option.map
(fun rule -> runLineRuleWithContext rule config.Context.IndentationRuleContext lineParams)
config.LineRules.IndentationRule

let noTabCharactersError =
config.LineRules.NoTabCharactersRule
|> Option.map (fun rule -> runLineRuleWithContext rule config.Context.NoTabCharactersRuleContext lineParams)
Option.map
(fun rule -> runLineRuleWithContext rule config.Context.NoTabCharactersRuleContext lineParams)
config.LineRules.NoTabCharactersRule

let lineErrors =
config.LineRules.GenericLineRules
|> Array.collect (fun rule -> runLineRule rule lineParams)
Array.collect (fun rule -> runLineRule rule lineParams) config.LineRules.GenericLineRules

[|
indentationError |> Option.toArray
Expand Down Expand Up @@ -460,7 +461,7 @@ module Lint =
|> List.filter (not << isIgnoredFile)
|> List.map (fun file -> ParseFile.parseFile file checker (Some projectOptions))

let failedFiles = parsedFiles |> List.choose getFailedFiles
let failedFiles = List.choose getFailedFiles parsedFiles

if List.isEmpty failedFiles then
parsedFiles
Expand Down
3 changes: 1 addition & 2 deletions src/FSharpLint.Core/Framework/Ast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ module Ast =
/// Concatenates the nested-list structure of `SynAttributes` into a `SynAttribute list` to keep other code
/// mostly unchanged.
let extractAttributes (attrs:SynAttributes) =
attrs
|> List.collect (fun attrList -> attrList.Attributes)
List.collect (fun (attrList: SynAttributeList) -> attrList.Attributes) attrs

/// Extracts an expression from parentheses e.g. ((x + 4)) -> x + 4
let rec removeParens = function
Expand Down
113 changes: 57 additions & 56 deletions src/FSharpLint.Core/Framework/AstInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,61 +28,62 @@ module AstInfo =
| None -> Function

let operatorIdentifiers =
[ "op_Nil"
"op_ColonColon"
"op_Addition"
"op_Splice"
"op_SpliceUntyped"
"op_Increment"
"op_Decrement"
"op_Subtraction"
"op_Multiply"
"op_Exponentiation"
"op_Division"
"op_Append"
"op_Concatenate"
"op_Modulus"
"op_BitwiseAnd"
"op_BitwiseOr"
"op_ExclusiveOr"
"op_LeftShift"
"op_LogicalNot"
"op_RightShift"
"op_UnaryPlus"
"op_UnaryNegation"
"op_AddressOf"
"op_IntegerAddressOf"
"op_BooleanAnd"
"op_BooleanOr"
"op_LessThanOrEqual"
"op_Equality"
"op_Inequality"
"op_GreaterThanOrEqual"
"op_LessThan"
"op_GreaterThan"
"op_PipeRight"
"op_PipeRight2"
"op_PipeRight3"
"op_PipeLeft"
"op_PipeLeft2"
"op_PipeLeft3"
"op_Dereference"
"op_ComposeRight"
"op_ComposeLeft"
"op_TypedQuotationUnicode"
"op_ChevronsBar"
"op_Quotation"
"op_QuotationUntyped"
"op_AdditionAssignment"
"op_SubtractionAssignment"
"op_MultiplyAssignment"
"op_DivisionAssignment"
"op_Range"
"op_RangeStep"
"op_Dynamic"
"op_DynamicAssignment"
"op_ArrayLookup"
"op_ArrayAssign" ] |> Set.ofList
Set.ofList
[ "op_Nil"
"op_ColonColon"
"op_Addition"
"op_Splice"
"op_SpliceUntyped"
"op_Increment"
"op_Decrement"
"op_Subtraction"
"op_Multiply"
"op_Exponentiation"
"op_Division"
"op_Append"
"op_Concatenate"
"op_Modulus"
"op_BitwiseAnd"
"op_BitwiseOr"
"op_ExclusiveOr"
"op_LeftShift"
"op_LogicalNot"
"op_RightShift"
"op_UnaryPlus"
"op_UnaryNegation"
"op_AddressOf"
"op_IntegerAddressOf"
"op_BooleanAnd"
"op_BooleanOr"
"op_LessThanOrEqual"
"op_Equality"
"op_Inequality"
"op_GreaterThanOrEqual"
"op_LessThan"
"op_GreaterThan"
"op_PipeRight"
"op_PipeRight2"
"op_PipeRight3"
"op_PipeLeft"
"op_PipeLeft2"
"op_PipeLeft3"
"op_Dereference"
"op_ComposeRight"
"op_ComposeLeft"
"op_TypedQuotationUnicode"
"op_ChevronsBar"
"op_Quotation"
"op_QuotationUntyped"
"op_AdditionAssignment"
"op_SubtractionAssignment"
"op_MultiplyAssignment"
"op_DivisionAssignment"
"op_Range"
"op_RangeStep"
"op_Dynamic"
"op_DynamicAssignment"
"op_ArrayLookup"
"op_ArrayAssign" ]

/// Operator identifiers can be made up of "op_" followed by a sequence of operators from this list.
let operators =
Expand Down Expand Up @@ -116,7 +117,7 @@ module AstInfo =
if Seq.isEmpty str then
true
else
let operator = operators |> List.tryFind (fun op -> str.StartsWith(op))
let operator = List.tryFind (fun (op: string) -> str.StartsWith(op)) operators

match operator with
| Some(operator) -> str.Substring(operator.Length) |> isSequenceOfOperators
Expand Down
24 changes: 12 additions & 12 deletions src/FSharpLint.Core/Framework/HintParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,17 @@ module HintParser =
char(System.Convert.ToInt32(dec, 10))

let private escapeMap =
[ ('"', '\"')
('\\', '\\')
('\'', '\'')
('n', '\n')
('t', '\t')
('b', '\b')
('r', '\r')
('a', '\a')
('f', '\f')
('v', '\v') ] |> Map.ofList
Map.ofList
[ ('"', '\"')
('\\', '\\')
('\'', '\'')
('n', '\n')
('t', '\t')
('b', '\b')
('r', '\r')
('a', '\a')
('f', '\f')
('v', '\v') ]

let private pescapechar: Parser<char, unit> =
skipChar '\\'
Expand Down Expand Up @@ -622,8 +623,7 @@ module HintParser =
let private pminus: Parser<char, unit> = pchar '-'

let private minusString (minus:char option, charList) =
if minus.IsSome then '-' :: charList else charList
|> charListToString
charListToString (if minus.IsSome then '-' :: charList else charList)

let private phexint: Parser<char list, unit> =
skipChar '0'
Expand Down
2 changes: 1 addition & 1 deletion src/FSharpLint.Core/Framework/Suppression.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let private extractRules (rules:Set<String>) (str:string) =

/// Parses a given file to find lines containing rule suppressions.
let parseSuppressionInfo (rules:Set<String>) (lines:string list) =
let rules = rules |> Set.map (fun rule -> rule.ToLowerInvariant())
let rules = Set.map (fun (rule: String) -> rule.ToLowerInvariant()) rules

let choose lineNum line =
let matched = Regex.Match (line, ".*fsharplint:([a-z\-]+)\s*(.*)$")
Expand Down
6 changes: 3 additions & 3 deletions src/FSharpLint.Core/Framework/Utilities.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module ExpressionUtilities =
let getSymbolFromIdent (checkFile:FSharpCheckFileResults option) expr =
match (checkFile, expr) with
| Some(checkFile), Identifier(ident, range) ->
let identNames = ident |> List.map (fun x -> x.idText)
let identNames = List.map (fun (x: Ident) -> x.idText) ident

checkFile.GetSymbolUseAtLocation(
range.StartLine,
Expand Down Expand Up @@ -83,7 +83,7 @@ module ExpressionUtilities =

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

/// Tries to find the source code within a given range.
let tryFindTextOfRange (range:Range) (text:string) =
Expand Down Expand Up @@ -114,7 +114,7 @@ module ExpressionUtilities =

/// Converts a list of type args to its string representation.
let typeArgsToString (text:string) (typeArgs:SynType list) =
let typeStrings = typeArgs |> List.choose (synTypeToString text)
let typeStrings = List.choose (synTypeToString text) typeArgs
if typeStrings.Length = typeArgs.Length
then typeStrings |> String.concat "," |> Some
else None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ let runner args =
| _ -> Array.empty

let rule =
{ Name = "AsyncExceptionWithoutReturn"
Identifier = Identifiers.AsyncExceptionWithoutReturn
RuleConfig =
{ AstNodeRuleConfig.Runner = runner
Cleanup = ignore } }
|> AstNodeRule
AstNodeRule
{ Name = "AsyncExceptionWithoutReturn"
Identifier = Identifiers.AsyncExceptionWithoutReturn
RuleConfig =
{ AstNodeRuleConfig.Runner = runner
Cleanup = ignore } }
18 changes: 8 additions & 10 deletions src/FSharpLint.Core/Rules/Conventions/AvoidSinglePipeOperator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ open FSharpLint.Framework.Rules

let runner (args: AstNodeRuleParams) =
let errors range =
{
Range = range
Message = String.Format(Resources.GetString ("RulesAvoidSinglePipeOperator"))
SuggestedFix = None
TypeChecks = List.Empty
} |> Array.singleton
Array.singleton
{ Range = range
Message = String.Format(Resources.GetString("RulesAvoidSinglePipeOperator"))
SuggestedFix = None
TypeChecks = List.Empty }

let error =
match args.AstNode with
Expand Down Expand Up @@ -47,7 +46,6 @@ let runner (args: AstNodeRuleParams) =


let rule =
{ Name = "AvoidSinglePipeOperator"
Identifier = Identifiers.AvoidSinglePipeOperator
RuleConfig = { AstNodeRuleConfig.Runner = runner; Cleanup = ignore } }
|> AstNodeRule
AstNodeRule { Name = "AvoidSinglePipeOperator"
Identifier = Identifiers.AvoidSinglePipeOperator
RuleConfig = { AstNodeRuleConfig.Runner = runner; Cleanup = ignore } }
12 changes: 6 additions & 6 deletions src/FSharpLint.Core/Rules/Conventions/AvoidTooShortNames.fs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ let runner (args:AstNodeRuleParams) =
suggestions |> Array.map (fun suggestion -> { suggestion with TypeChecks = Option.toList typeCheck }))

let rule =
{ Name = "AvoidTooShortNames"
Identifier = Identifiers.AvoidTooShortNames
RuleConfig =
{ AstNodeRuleConfig.Runner = runner
Cleanup = ignore } }
|> AstNodeRule
AstNodeRule
{ Name = "AvoidTooShortNames"
Identifier = Identifiers.AvoidTooShortNames
RuleConfig =
{ AstNodeRuleConfig.Runner = runner
Cleanup = ignore } }
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ let private runner (args:AstNodeRuleParams) =

/// Checks if any code uses 'let _ = ...' and suggests to use the ignore function.
let rule =
{ Name = "FavourIgnoreOverLetWild"
Identifier = Identifiers.FavourIgnoreOverLetWild
RuleConfig = { AstNodeRuleConfig.Runner = runner; Cleanup = ignore } }
|> AstNodeRule
AstNodeRule { Name = "FavourIgnoreOverLetWild"
Identifier = Identifiers.FavourIgnoreOverLetWild
RuleConfig = { AstNodeRuleConfig.Runner = runner; Cleanup = ignore } }
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ let private runner (args: AstNodeRuleParams) =

/// Checks if any code uses untyped ignore
let rule =
{ Name = "FavourTypedIgnore"
Identifier = Identifiers.FavourTypedIgnore
RuleConfig =
{ AstNodeRuleConfig.Runner = runner
Cleanup = ignore } }
|> AstNodeRule
AstNodeRule
{ Name = "FavourTypedIgnore"
Identifier = Identifiers.FavourTypedIgnore
RuleConfig =
{ AstNodeRuleConfig.Runner = runner
Cleanup = ignore } }
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let private checkTupleOfWildcards pattern identifier =
| _ -> false

let constructorString numberOfWildcards =
let constructorName = identifier |> String.concat "."
let constructorName = String.concat "." identifier
let arguments = Array.create numberOfWildcards "_" |> String.concat ", "
constructorName + "(" + arguments + ")"

Expand Down Expand Up @@ -47,14 +47,13 @@ let private runner (args:AstNodeRuleParams) =
| 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)
let identifier = List.map (fun (x: Ident) -> x.idText) identifier.LongIdent
checkTupleOfWildcards pattern identifier
else
Array.empty
| _ -> Array.empty

let rule =
{ Name = "TupleOfWildcards"
Identifier = Identifiers.TupleOfWildcards
RuleConfig = { AstNodeRuleConfig.Runner = runner; Cleanup = ignore } }
|> AstNodeRule
AstNodeRule { Name = "TupleOfWildcards"
Identifier = Identifiers.TupleOfWildcards
RuleConfig = { AstNodeRuleConfig.Runner = runner; Cleanup = ignore } }
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ let private runner (args:AstNodeRuleParams) =
Array.empty

let rule =
{ Name = "UselessBinding"
Identifier = Identifiers.UselessBinding
RuleConfig = { AstNodeRuleConfig.Runner = runner; Cleanup = ignore } }
|> AstNodeRule

AstNodeRule { Name = "UselessBinding"
Identifier = Identifiers.UselessBinding
RuleConfig = { AstNodeRuleConfig.Runner = runner; Cleanup = ignore } }
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ let private runner (args:AstNodeRuleParams) =
| _ -> Array.empty

let rule =
{ Name = "WildcardNamedWithAsPattern"
Identifier = Identifiers.WildcardNamedWithAsPattern
RuleConfig = { AstNodeRuleConfig.Runner = runner; Cleanup = ignore } }
|> AstNodeRule

AstNodeRule { Name = "WildcardNamedWithAsPattern"
Identifier = Identifiers.WildcardNamedWithAsPattern
RuleConfig = { AstNodeRuleConfig.Runner = runner; Cleanup = ignore } }
Loading

0 comments on commit 680b8a1

Please sign in to comment.