Skip to content

Commit

Permalink
Tweak max widths for gooder code
Browse files Browse the repository at this point in the history
  • Loading branch information
samritchie committed Feb 2, 2024
1 parent 91d9646 commit b80d8a9
Show file tree
Hide file tree
Showing 28 changed files with 221 additions and 675 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fsharp_max_if_then_else_short_width=60
# breaks an infix operator expression if it is on one line
# infix: a + b + c
# default 50
fsharp_max_infix_operator_expression=60
fsharp_max_infix_operator_expression=100

# breaks a single-line record declaration
# i.e. if this gets too wide: { X = 10; Y = 12 }
Expand Down Expand Up @@ -134,7 +134,7 @@ fsharp_max_value_binding_width=140

# maximum width for function and member binding (rh-side)
# default 40
fsharp_max_function_binding_width=80
fsharp_max_function_binding_width=100

# maximum width for expressions like X.DoY().GetZ(10).Help()
# default 50
Expand Down
45 changes: 16 additions & 29 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#r "nuget: Fake.Core.Target"

// Boilerplate
System.Environment.GetCommandLineArgs ()
System.Environment.GetCommandLineArgs()
|> Array.skip 2 // skip fsi.exe; build.fsx
|> Array.toList
|> Fake.Core.Context.FakeExecutionContext.Create false __SOURCE_FILE__
Expand Down Expand Up @@ -90,20 +90,20 @@ Target.create "AssemblyInfo" (fun _ ->
AssemblyInfo.Description summary
AssemblyInfo.Version release.AssemblyVersion
AssemblyInfo.FileVersion release.AssemblyVersion
AssemblyInfo.InternalsVisibleTo (projectName + ".Tests") ]
AssemblyInfo.InternalsVisibleTo(projectName + ".Tests") ]

let getProjectDetails (projectPath: string) =
let projectName = System.IO.Path.GetFileNameWithoutExtension (projectPath)
(projectPath, projectName, System.IO.Path.GetDirectoryName (projectPath), (getAssemblyInfoAttributes projectName))
let projectName = System.IO.Path.GetFileNameWithoutExtension(projectPath)
(projectPath, projectName, System.IO.Path.GetDirectoryName(projectPath), (getAssemblyInfoAttributes projectName))

!! "src/**/*.??proj"
|> Seq.map getProjectDetails
|> Seq.iter (fun (projFileName, _, folderName, attributes) ->
match projFileName with
| proj when proj.EndsWith ("fsproj") -> AssemblyInfoFile.createFSharp (folderName </> "AssemblyInfo.fs") attributes
| proj when proj.EndsWith ("csproj") ->
| proj when proj.EndsWith("fsproj") -> AssemblyInfoFile.createFSharp (folderName </> "AssemblyInfo.fs") attributes
| proj when proj.EndsWith("csproj") ->
AssemblyInfoFile.createCSharp ((folderName </> "Properties") </> "AssemblyInfo.cs") attributes
| proj when proj.EndsWith ("vbproj") ->
| proj when proj.EndsWith("vbproj") ->
AssemblyInfoFile.createVisualBasic ((folderName </> "My Project") </> "AssemblyInfo.vb") attributes
| _ -> ()))

Expand Down Expand Up @@ -155,11 +155,11 @@ Target.create "Pack" (fun _ ->
Target.create "ReleaseGitHub" (fun _ ->
let remote =
Git.CommandHelper.getGitResult "" "remote -v"
|> Seq.filter (fun (s: string) -> s.EndsWith ("(push)"))
|> Seq.tryFind (fun (s: string) -> s.Contains (gitOwner + "/" + gitName))
|> Seq.filter (fun (s: string) -> s.EndsWith("(push)"))
|> Seq.tryFind (fun (s: string) -> s.Contains(gitOwner + "/" + gitName))
|> function
| None -> gitHome + "/" + gitName
| Some (s: string) -> s.Split().[0]
| Some(s: string) -> s.Split().[0]

Git.Staging.stageAll ""
Git.Commit.exec "" (sprintf "Bump version to %s" release.NugetVersion)
Expand Down Expand Up @@ -196,7 +196,7 @@ Target.create "Push" (fun _ ->
| _ -> UserInput.getUserPassword "NuGet Key: "

let pushParams =
{ NuGet.NuGet.NuGetPushParams.Create () with
{ NuGet.NuGet.NuGetPushParams.Create() with
ApiKey = Some key
Source = Some "https://api.nuget.org/v3/index.json" }

Expand All @@ -208,23 +208,10 @@ Target.create "Push" (fun _ ->
Target.create "Default" DoNothing
Target.create "Release" DoNothing

"Clean"
==> "AssemblyInfo"
==> "Restore"
==> "Build"
==> "Test"
==> "Default"

"Clean"
==> "AssemblyInfo"
==> "Restore"
==> "BuildRelease"
==> "Docs"

"Default"
==> "Pack"
==> "ReleaseGitHub"
==> "Push"
==> "Release"
"Clean" ==> "AssemblyInfo" ==> "Restore" ==> "Build" ==> "Test" ==> "Default"

"Clean" ==> "AssemblyInfo" ==> "Restore" ==> "BuildRelease" ==> "Docs"

"Default" ==> "Pack" ==> "ReleaseGitHub" ==> "Push" ==> "Release"

Target.runOrDefaultWithArguments "Default"
27 changes: 6 additions & 21 deletions src/FSharp.AWS.DynamoDB/Expression/ConditionalExpr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ let extractQueryExpr (recordInfo: RecordTableInfo) (expr: Expr) : ConditionalExp
if not expr.IsClosed then
invalidArg "expr" "supplied query is not a closed expression."

let invalidQuery () =
invalidArg "expr"
<| sprintf "Supplied expression is not a valid conditional."
let invalidQuery () = invalidArg "expr" <| sprintf "Supplied expression is not a valid conditional."

let nParams, (|PVar|_|), expr' = extractExprParams recordInfo expr

Expand Down Expand Up @@ -223,10 +221,7 @@ let extractQueryExpr (recordInfo: RecordTableInfo) (expr: Expr) : ConditionalExp
let op = extractOperand None expr

match op with
| Value va ->
va.AttributeValue.L
|> ResizeArray.mapToArray (fun x -> x |> wrap |> Value)
|> Some
| Value va -> va.AttributeValue.L |> ResizeArray.mapToArray (fun x -> x |> wrap |> Value) |> Some
| _ -> None

let extractNestedField (expr: Expr) =
Expand All @@ -241,10 +236,7 @@ let extractQueryExpr (recordInfo: RecordTableInfo) (expr: Expr) : ConditionalExp
let (|Comparison|_|) (pat: Expr) (expr: Expr) =
match expr with
| SpecificCall pat (None, _, args) ->
let pickler =
args
|> List.tryPick (|AttributeGet|_|)
|> Option.map (fun attr -> attr.Pickler)
let pickler = args |> List.tryPick (|AttributeGet|_|) |> Option.map (fun attr -> attr.Pickler)

let operands = args |> List.map (extractOperand pickler)

Expand All @@ -259,8 +251,7 @@ let extractQueryExpr (recordInfo: RecordTableInfo) (expr: Expr) : ConditionalExp

let extractComparison (p: Pickler) (cmp: Comparator) (left: Operand) (right: Operand) =
if cmp.IsComparison && not p.IsComparable then
sprintf "Representation of type '%O' does not support comparisons." p.Type
|> invalidArg "expr"
sprintf "Representation of type '%O' does not support comparisons." p.Type |> invalidArg "expr"

elif left = right then
match cmp with
Expand Down Expand Up @@ -536,15 +527,9 @@ type ConditionalExpression with
let aw = new AttributeWriter()
let expr = writeConditionExpression aw cond

let names =
aw.Names
|> Seq.map (fun kv -> kv.Key, kv.Value)
|> Seq.toList
let names = aw.Names |> Seq.map (fun kv -> kv.Key, kv.Value) |> Seq.toList

let values =
aw.Values
|> Seq.map (fun kv -> kv.Key, kv.Value.Print())
|> Seq.toList
let values = aw.Values |> Seq.map (fun kv -> kv.Key, kv.Value.Print()) |> Seq.toList

expr, names, values

Expand Down
14 changes: 3 additions & 11 deletions src/FSharp.AWS.DynamoDB/Expression/ExprCommon.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ type NestedAttribute =
member nf.Print() =
match nf with
| FParam i -> sprintf "<$param%d>" i
| FField f when not <| isValidFieldName f ->
sprintf "map keys must be 1 to 64k long (as utf8)."
|> invalidArg f
| FField f when not <| isValidFieldName f -> sprintf "map keys must be 1 to 64k long (as utf8)." |> invalidArg f

| FField f -> "." + f
| FIndex i -> sprintf "[%d]" i
Expand Down Expand Up @@ -182,15 +180,9 @@ type QuotedAttribute =
let tryGetPropInfo (properties: PropertyMetadata[]) isFinalProp (p: PropertyInfo) =
match properties |> Array.tryFind (fun rp -> rp.PropertyInfo = p) with
| None -> None
| Some rp when
rp.Pickler.PicklerType = PicklerType.Serialized
&& not isFinalProp
->
| Some rp when rp.Pickler.PicklerType = PicklerType.Serialized && not isFinalProp ->
invalidArg "expr" "cannot access nested properties of serialized fields."
| Some rp when
rp.Pickler.PicklerType = PicklerType.Union
&& not isFinalProp
->
| Some rp when rp.Pickler.PicklerType = PicklerType.Union && not isFinalProp ->
invalidArg "expr" "cannot access nested properties of union fields."
| Some _ as r -> r

Expand Down
6 changes: 1 addition & 5 deletions src/FSharp.AWS.DynamoDB/Expression/ExpressionContainers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@ and UpdateExpression =

let uops = exprs |> Array.collect (fun e -> e.UpdateOps.UpdateOps)

match
uops
|> Seq.map (fun o -> o.Attribute)
|> tryFindConflictingPaths
with
match uops |> Seq.map (fun o -> o.Attribute) |> tryFindConflictingPaths with
| None -> ()
| Some(p1, p2) ->
let msg = sprintf "found conflicting paths '%s' and '%s' being accessed in update expression." p1 p2
Expand Down
27 changes: 6 additions & 21 deletions src/FSharp.AWS.DynamoDB/Expression/ProjectionExpr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ type AttributeId with
if List.isEmpty rest then
false
else
sprintf "Document path '%s' not found." id.Name
|> KeyNotFoundException
|> raise
sprintf "Document path '%s' not found." id.Name |> KeyNotFoundException |> raise

let rec aux result rest (av: AttributeValue) =
match rest with
Expand All @@ -42,28 +40,18 @@ type AttributeId with
let ok, nested = av.M.TryGetValue f
if not ok then notFound tl else aux result tl nested
else
av.Print()
|> sprintf "Expected map, but was '%s'."
|> InvalidCastException
|> raise
av.Print() |> sprintf "Expected map, but was '%s'." |> InvalidCastException |> raise

| FIndex i :: tl ->
if av.IsLSet then
if i < 0 || i >= av.L.Count then
sprintf "Indexed path '%s' out of range." id.Name
|> ArgumentOutOfRangeException
|> raise
sprintf "Indexed path '%s' out of range." id.Name |> ArgumentOutOfRangeException |> raise
else
aux result tl av.L.[i]
else
av.Print()
|> sprintf "Expected list, but was '%s'."
|> InvalidCastException
|> raise
av.Print() |> sprintf "Expected list, but was '%s'." |> InvalidCastException |> raise

| FParam _ :: _ ->
sprintf "internal error; unexpected attribute path '%s'." id.Name
|> invalidOp
| FParam _ :: _ -> sprintf "internal error; unexpected attribute path '%s'." id.Name |> invalidOp

let ok, prop = ro.TryGetValue id.RootName

Expand Down Expand Up @@ -171,9 +159,6 @@ type ProjectionExpr =
let aw = new AttributeWriter()
let expr = __.Write(aw)

let names =
aw.Names
|> Seq.map (fun kv -> kv.Key, kv.Value)
|> Seq.toList
let names = aw.Names |> Seq.map (fun kv -> kv.Key, kv.Value) |> Seq.toList

expr, names
34 changes: 7 additions & 27 deletions src/FSharp.AWS.DynamoDB/Expression/UpdateExpr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ let extractRecordExprUpdaters (recordInfo: RecordTableInfo) (expr: Expr) : Inter
if not expr.IsClosed then
invalidArg "expr" "supplied update expression contains free variables."

let invalidExpr () =
invalidArg "expr"
<| sprintf "Supplied expression is not a valid update expression."
let invalidExpr () = invalidArg "expr" <| sprintf "Supplied expression is not a valid update expression."

let nParams, pRecognizer, expr' = extractExprParams recordInfo expr

Expand All @@ -166,11 +164,7 @@ let extractRecordExprUpdaters (recordInfo: RecordTableInfo) (expr: Expr) : Inter
| Var v when bindings.ContainsKey v -> Some(Root(rp, recordInfo.GetPropertySchemata rp.Name), bindings.[v])
| e -> Some(Root(rp, recordInfo.GetPropertySchemata rp.Name), e)

let assignmentExprs =
assignments
|> Seq.mapi tryExtractValueExpr
|> Seq.choose id
|> Seq.toArray
let assignmentExprs = assignments |> Seq.mapi tryExtractValueExpr |> Seq.choose id |> Seq.toArray

{ RVar = r
NParams = nParams
Expand All @@ -187,9 +181,7 @@ let extractOpExprUpdaters (recordInfo: RecordTableInfo) (expr: Expr) : Intermedi
if not expr.IsClosed then
invalidArg "expr" "supplied update expression contains free variables."

let invalidExpr () =
invalidArg "expr"
<| sprintf "Supplied expression is not a valid update expression."
let invalidExpr () = invalidArg "expr" <| sprintf "Supplied expression is not a valid update expression."

let nParams, (|PVar|_|), expr' = extractExprParams recordInfo expr

Expand Down Expand Up @@ -239,11 +231,7 @@ let extractOpExprUpdaters (recordInfo: RecordTableInfo) (expr: Expr) : Intermedi

do extract body

match
attrs
|> Seq.map (fun attr -> attr.Id)
|> tryFindConflictingPaths
with
match attrs |> Seq.map (fun attr -> attr.Id) |> tryFindConflictingPaths with
| Some(p1, p2) ->
let msg = sprintf "found conflicting paths '%s' and '%s' being accessed in update expression." p1 p2
invalidArg "expr" msg
Expand All @@ -264,9 +252,7 @@ let extractOpExprUpdaters (recordInfo: RecordTableInfo) (expr: Expr) : Intermedi

/// Completes conversion from intermediate update expression to final update operations
let extractUpdateOps (exprs: IntermediateUpdateExprs) =
let invalidExpr () =
invalidArg "expr"
<| sprintf "Supplied expression is not a valid update expression."
let invalidExpr () = invalidArg "expr" <| sprintf "Supplied expression is not a valid update expression."

let (|PVar|_|) = exprs.ParamRecognizer
let (|AttributeGet|_|) (e: Expr) = QuotedAttribute.TryExtract (|PVar|_|) exprs.RVar exprs.RecordInfo e
Expand Down Expand Up @@ -520,15 +506,9 @@ type UpdateOperations with
let aw = new AttributeWriter()
let expr = writeUpdateExpression aw uops

let names =
aw.Names
|> Seq.map (fun kv -> kv.Key, kv.Value)
|> Seq.toList
let names = aw.Names |> Seq.map (fun kv -> kv.Key, kv.Value) |> Seq.toList

let values =
aw.Values
|> Seq.map (fun kv -> kv.Key, kv.Value.Print())
|> Seq.toList
let values = aw.Values |> Seq.map (fun kv -> kv.Key, kv.Value.Print()) |> Seq.toList

expr, names, values

Expand Down
19 changes: 5 additions & 14 deletions src/FSharp.AWS.DynamoDB/Extensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,9 @@ module Extensions =
let getEnv x = Environment.ResolveEnvironmentVariable x

match getEnv accessKeyName, getEnv secretKeyName with
| null, null ->
sprintf "Undefined environment variables '%s' and '%s'" accessKeyName secretKeyName
|> invalidOp
| null, _ ->
sprintf "Undefined environment variable '%s'" accessKeyName
|> invalidOp
| _, null ->
sprintf "Undefined environment variable '%s'" secretKeyName
|> invalidOp
| null, null -> sprintf "Undefined environment variables '%s' and '%s'" accessKeyName secretKeyName |> invalidOp
| null, _ -> sprintf "Undefined environment variable '%s'" accessKeyName |> invalidOp
| _, null -> sprintf "Undefined environment variable '%s'" secretKeyName |> invalidOp
| aK, sK -> new BasicAWSCredentials(aK, sK) :> _

/// <summary>
Expand All @@ -77,8 +71,7 @@ module Extensions =
let credsFile = Path.Combine(getHomePath (), ".aws", "credentials")

if not <| File.Exists credsFile then
sprintf "Could not locate stored credentials profile '%s'." profileName
|> invalidOp
sprintf "Could not locate stored credentials profile '%s'." profileName |> invalidOp

let text = File.ReadAllText credsFile

Expand All @@ -89,7 +82,5 @@ module Extensions =
|> Seq.tryFind (fun (pf, _, _) -> pf = profileName)

match matchingProfile with
| None ->
sprintf "Could not locate stored credentials profile '%s'." profileName
|> invalidOp
| None -> sprintf "Could not locate stored credentials profile '%s'." profileName |> invalidOp
| Some(_, aK, sK) -> new BasicAWSCredentials(aK, sK) :> _
Loading

0 comments on commit b80d8a9

Please sign in to comment.