Skip to content

Commit 342391f

Browse files
SamirTalwarhasura-bot
authored andcommitted
Upgrade Ormolu to v0.5.
This upgrades the version of Ormolu required by the HGE repository to v0.5.0.1, and reformats all code accordingly. Ormolu v0.5 reformats code that uses infix operators. This is mostly useful, adding newlines and indentation to make it clear which operators are applied first, but in some cases, it's unpleasant. To make this easier on the eyes, I had to do the following: * Add a few fixity declarations (search for `infix`) * Add parentheses to make precedence clear, allowing Ormolu to keep everything on one line * Rename `relevantEq` to `(==~)` in hasura#6651 and set it to `infix 4` * Add a few _.ormolu_ files (thanks to @hallettj for helping me get started), mostly for Autodocodec operators that don't have explicit fixity declarations In general, I think these changes are quite reasonable. They mostly affect indentation. PR-URL: hasura/graphql-engine-mono#6675 GitOrigin-RevId: cd47d87f1d089fb0bc9dcbbe7798dbceedcd7d83
1 parent 89f639b commit 342391f

File tree

204 files changed

+1789
-1294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+1789
-1294
lines changed

nix/shell.nix

+1-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ let
5252
# The correct version of GHC.
5353
pkgs.haskell.compiler.${pkgs.ghcName}
5454

55-
# We use the default versions of these packages.
56-
(versions.ensureVersion pkgs.haskellPackages.ormolu)
57-
58-
# We build these packages using our custom GHC.
5955
pkgs.haskell.packages.${pkgs.ghcName}.alex
6056
pkgs.haskell.packages.${pkgs.ghcName}.apply-refact
6157
pkgs.haskell.packages.${pkgs.ghcName}.cabal-install
@@ -66,6 +62,7 @@ let
6662
(versions.ensureVersion pkgs.haskell.packages.${pkgs.ghcName}.hpack)
6763
pkgs.haskell.packages.${pkgs.ghcName}.hoogle
6864
pkgs.haskell.packages.${pkgs.ghcName}.hspec-discover
65+
(versions.ensureVersion pkgs.haskell.packages.${pkgs.ghcName}.ormolu)
6966
];
7067

7168
devInputs = [

scripts/make/lint.mk

+8-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ HLINT_CHECK_VERSION = $(shell jq '.hlint' ./server/VERSIONS.json)
1515
NIX_FMT = nixpkgs-fmt
1616

1717
ORMOLU = ormolu
18-
ORMOLU_ARGS = --cabal-default-extensions
1918
ORMOLU_VERSION = $(shell $(ORMOLU) --version | awk 'NR==1 { print $$2 }')
2019
ORMOLU_CHECK_VERSION = $(shell jq '.ormolu' ./server/VERSIONS.json)
2120

@@ -37,29 +36,29 @@ check-ormolu-version:
3736
.PHONY: format-hs
3837
## format-hs: auto-format Haskell source code using ormolu
3938
format-hs: check-ormolu-version
40-
@echo running ormolu --mode inplace
41-
@$(ORMOLU) $(ORMOLU_ARGS) --mode inplace $(HS_FILES)
39+
@echo running $(ORMOLU) --mode inplace
40+
@$(ORMOLU) --mode inplace $(HS_FILES)
4241

4342
.PHONY: format-hs-changed
4443
## format-hs-changed: auto-format Haskell source code using ormolu (changed files only)
4544
format-hs-changed: check-ormolu-version
46-
@echo running ormolu --mode inplace
45+
@echo running $(ORMOLU) --mode inplace
4746
@if [ -n "$(CHANGED_HS_FILES)" ]; then \
48-
$(ORMOLU) $(ORMOLU_ARGS) --mode inplace $(CHANGED_HS_FILES); \
47+
$(ORMOLU) --mode inplace $(CHANGED_HS_FILES); \
4948
fi
5049

5150
.PHONY: check-format-hs
5251
## check-format-hs: check Haskell source code formatting using ormolu
5352
check-format-hs: check-ormolu-version
54-
@echo running ormolu --mode check
55-
@$(ORMOLU) $(ORMOLU_ARGS) --mode check $(HS_FILES)
53+
@echo running $(ORMOLU) --mode check
54+
@$(ORMOLU) --mode check $(HS_FILES)
5655

5756
.PHONY: check-format-hs-changed
5857
## check-format-hs-changed: check Haskell source code formatting using ormolu (changed-files-only)
5958
check-format-hs-changed: check-ormolu-version
60-
@echo running ormolu --mode check
59+
@echo running $(ORMOLU) --mode check
6160
@if [ -n "$(CHANGED_HS_FILES)" ]; then \
62-
$(ORMOLU) $(ORMOLU_ARGS) --mode check $(CHANGED_HS_FILES); \
61+
$(ORMOLU) --mode check $(CHANGED_HS_FILES); \
6362
fi
6463

6564
# We don't bother checking only changed *.nix files, as there's so few.

server/.ormolu

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
infixr 8 .=
2+
infixr 8 .==

server/VERSIONS.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"ghc": "9.2.4",
33
"hlint": "3.4.1",
44
"hpack": "0.34.7",
5-
"ormolu": "0.3.1.0"
5+
"ormolu": "0.5.0.1"
66
}

server/lib/aeson-ordered/src/Data/Aeson/Ordered.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ value = do
280280
C_n -> A8.string "null" $> Null
281281
_
282282
| w >= 48 && w <= 57 || w == 45 ->
283-
Number <$> A8.scientific
283+
Number <$> A8.scientific
284284
| otherwise -> fail "not a valid json value"
285285
{-# INLINE value #-}
286286

server/lib/api-tests/test/Test/EventTrigger/PG/EventTriggersRunSQLSpec.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ args:
172172
eitherDecode responseBody
173173
`onLeft` \err ->
174174
assertFailure
175-
( "In request: " ++ "/v2/query"
175+
( "In request: "
176+
++ "/v2/query"
176177
++ "Couldn't decode JSON body:"
177178
++ show err
178179
++ "Body was:"

server/lib/api-tests/test/Test/Regression/NullRemoteRelationship8345Spec.hs

+7-7
Original file line numberDiff line numberDiff line change
@@ -401,17 +401,17 @@ lhsRemoteServerMkLocalTestEnvironment _ = do
401401
flip foldMap orderByList \LHSHasuraTrackOrderBy {..} ->
402402
if
403403
| Just idOrder <- tob_id -> case idOrder of
404-
Asc -> compare trackId1 trackId2
405-
Desc -> compare trackId2 trackId1
404+
Asc -> compare trackId1 trackId2
405+
Desc -> compare trackId2 trackId1
406406
| Just titleOrder <- tob_title -> case titleOrder of
407-
Asc -> compare trackTitle1 trackTitle2
408-
Desc -> compare trackTitle2 trackTitle1
407+
Asc -> compare trackTitle1 trackTitle2
408+
Desc -> compare trackTitle2 trackTitle1
409409
| Just albumIdOrder <- tob_album_id ->
410-
compareWithNullLast albumIdOrder trackAlbumId1 trackAlbumId2
410+
compareWithNullLast albumIdOrder trackAlbumId1 trackAlbumId2
411411
| Just artistIdOrder <- tob_artist_id ->
412-
compareWithNullLast artistIdOrder trackArtistId1 trackArtistId2
412+
compareWithNullLast artistIdOrder trackArtistId1 trackArtistId2
413413
| otherwise ->
414-
error "empty track_order object"
414+
error "empty track_order object"
415415
compareWithNullLast Desc x1 x2 = compareWithNullLast Asc x2 x1
416416
compareWithNullLast Asc Nothing Nothing = EQ
417417
compareWithNullLast Asc (Just _) Nothing = LT

server/lib/api-tests/test/Test/Regression/UsingTheSameFunctionForRootFieldAndComputedField8643Spec.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ functionSetup testEnvironment =
6060
Fixture.SetupAction
6161
{ setupAction =
6262
Postgres.run_ testEnvironment $
63-
"CREATE FUNCTION " ++ Constants.postgresDb
63+
"CREATE FUNCTION "
64+
++ Constants.postgresDb
6465
++ ".authors(author_row author) \
6566
\RETURNS SETOF author AS $$ \
6667
\ SELECT * \

server/lib/api-tests/test/Test/RemoteRelationship/MetadataAPI/Common.hs

+6-6
Original file line numberDiff line numberDiff line change
@@ -559,15 +559,15 @@ lhsRemoteServerMkLocalTestEnvironment _ = do
559559
flip foldMap orderByList \LHSHasuraTrackOrderBy {..} ->
560560
if
561561
| Just idOrder <- tob_id -> case idOrder of
562-
Asc -> compare trackId1 trackId2
563-
Desc -> compare trackId2 trackId1
562+
Asc -> compare trackId1 trackId2
563+
Desc -> compare trackId2 trackId1
564564
| Just titleOrder <- tob_title -> case titleOrder of
565-
Asc -> compare trackTitle1 trackTitle2
566-
Desc -> compare trackTitle2 trackTitle1
565+
Asc -> compare trackTitle1 trackTitle2
566+
Desc -> compare trackTitle2 trackTitle1
567567
| Just albumIdOrder <- tob_album_id ->
568-
compareWithNullLast albumIdOrder trackAlbumId1 trackAlbumId2
568+
compareWithNullLast albumIdOrder trackAlbumId1 trackAlbumId2
569569
| otherwise ->
570-
error "empty track_order object"
570+
error "empty track_order object"
571571
compareWithNullLast Desc x1 x2 = compareWithNullLast Asc x2 x1
572572
compareWithNullLast Asc Nothing Nothing = EQ
573573
compareWithNullLast Asc (Just _) Nothing = LT

server/lib/api-tests/test/Test/RemoteRelationship/XToDBArrayRelationshipSpec.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -601,12 +601,12 @@ lhsRemoteServerMkLocalTestEnvironment _ = do
601601
flip foldMap orderByList \HasuraArtistOrderBy {..} ->
602602
if
603603
| Just idOrder <- aob_id ->
604-
compareWithNullLast idOrder artistId1 artistId2
604+
compareWithNullLast idOrder artistId1 artistId2
605605
| Just nameOrder <- aob_name -> case nameOrder of
606-
Asc -> compare artistName1 artistName2
607-
Desc -> compare artistName2 artistName1
606+
Asc -> compare artistName1 artistName2
607+
Desc -> compare artistName2 artistName1
608608
| otherwise ->
609-
error "empty artist_order object"
609+
error "empty artist_order object"
610610
compareWithNullLast Desc x1 x2 = compareWithNullLast Asc x2 x1
611611
compareWithNullLast Asc Nothing Nothing = EQ
612612
compareWithNullLast Asc (Just _) Nothing = LT

server/lib/api-tests/test/Test/RemoteRelationship/XToDBObjectRelationshipSpec.hs

+6-6
Original file line numberDiff line numberDiff line change
@@ -598,15 +598,15 @@ lhsRemoteServerMkLocalTestEnvironment _ = do
598598
flip foldMap orderByList \HasuraTrackOrderBy {..} ->
599599
if
600600
| Just idOrder <- tob_id -> case idOrder of
601-
Asc -> compare trackId1 trackId2
602-
Desc -> compare trackId2 trackId1
601+
Asc -> compare trackId1 trackId2
602+
Desc -> compare trackId2 trackId1
603603
| Just titleOrder <- tob_title -> case titleOrder of
604-
Asc -> compare trackTitle1 trackTitle2
605-
Desc -> compare trackTitle2 trackTitle1
604+
Asc -> compare trackTitle1 trackTitle2
605+
Desc -> compare trackTitle2 trackTitle1
606606
| Just albumIdOrder <- tob_album_id ->
607-
compareWithNullLast albumIdOrder trackAlbumId1 trackAlbumId2
607+
compareWithNullLast albumIdOrder trackAlbumId1 trackAlbumId2
608608
| otherwise ->
609-
error "empty track_order object"
609+
error "empty track_order object"
610610
compareWithNullLast Desc x1 x2 = compareWithNullLast Asc x2 x1
611611
compareWithNullLast Asc Nothing Nothing = EQ
612612
compareWithNullLast Asc (Just _) Nothing = LT

server/lib/api-tests/test/Test/RemoteRelationship/XToRemoteSchemaRelationshipSpec.hs

+6-6
Original file line numberDiff line numberDiff line change
@@ -445,15 +445,15 @@ lhsRemoteServerMkLocalTestEnvironment _ = do
445445
flip foldMap orderByList \LHSHasuraTrackOrderBy {..} ->
446446
if
447447
| Just idOrder <- tob_id -> case idOrder of
448-
Asc -> compare trackId1 trackId2
449-
Desc -> compare trackId2 trackId1
448+
Asc -> compare trackId1 trackId2
449+
Desc -> compare trackId2 trackId1
450450
| Just titleOrder <- tob_title -> case titleOrder of
451-
Asc -> compare trackTitle1 trackTitle2
452-
Desc -> compare trackTitle2 trackTitle1
451+
Asc -> compare trackTitle1 trackTitle2
452+
Desc -> compare trackTitle2 trackTitle1
453453
| Just albumIdOrder <- tob_album_id ->
454-
compareWithNullLast albumIdOrder trackAlbumId1 trackAlbumId2
454+
compareWithNullLast albumIdOrder trackAlbumId1 trackAlbumId2
455455
| otherwise ->
456-
error "empty track_order object"
456+
error "empty track_order object"
457457
compareWithNullLast Desc x1 x2 = compareWithNullLast Asc x2 x1
458458
compareWithNullLast Asc Nothing Nothing = EQ
459459
compareWithNullLast Asc (Just _) Nothing = LT

server/lib/api-tests/test/Test/SQLServer/VarcharLiteralsSpec.hs

+4-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ tests opts = do
275275

276276
actual
277277
`sqlShouldSatisfy` ( \sql ->
278-
"'horse'" `T.isInfixOf` sql
278+
"'horse'"
279+
`T.isInfixOf` sql
279280
&& not ("N'horse'" `T.isInfixOf` sql)
280281
)
281282

@@ -297,7 +298,8 @@ tests opts = do
297298

298299
actual
299300
`sqlShouldSatisfy` ( \sql ->
300-
"'horse'" `T.isInfixOf` sql
301+
"'horse'"
302+
`T.isInfixOf` sql
301303
&& not ("N'horse'" `T.isInfixOf` sql)
302304
)
303305

server/lib/dc-api/.ormolu

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
infixr 8 .=

server/lib/dc-api/src/Hasura/Backends/DataConnector/API.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ data Prometheus
124124
-- we can just demand that agent authors pick one of the following.
125125
instance Accept Prometheus where
126126
contentTypes _ =
127-
"text" // "plain" /: ("version", "0.0.4") /: ("charset", "utf-8")
127+
("text" // "plain" /: ("version", "0.0.4") /: ("charset", "utf-8"))
128128
:| ["application" // "openmetrics-text" /: ("version", "0.0.1")]
129129

130130
instance MimeRender Prometheus Text where

server/lib/dc-api/src/Hasura/Backends/DataConnector/API/V0/Query.hs

+13-13
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ instance HasCodec QueryRequest where
7171
object "QueryRequest" $
7272
QueryRequest
7373
<$> requiredField "table" "The name of the table to query"
74-
.= _qrTable
74+
.= _qrTable
7575
<*> requiredField "table_relationships" "The relationships between tables involved in the entire query request"
76-
.= _qrTableRelationships
76+
.= _qrTableRelationships
7777
<*> requiredField "query" "The details of the query against the table"
78-
.= _qrQuery
78+
.= _qrQuery
7979

8080
newtype FieldName = FieldName {unFieldName :: Text}
8181
deriving stock (Eq, Ord, Show, Generic, Data)
@@ -104,17 +104,17 @@ instance HasCodec Query where
104104
named "Query" . object "Query" $
105105
Query
106106
<$> optionalFieldOrNull "fields" "Fields of the query"
107-
.= _qFields
107+
.= _qFields
108108
<*> optionalFieldOrNull "aggregates" "Aggregate fields of the query"
109-
.= _qAggregates
109+
.= _qAggregates
110110
<*> optionalFieldOrNull "limit" "Optionally limit to N results"
111-
.= _qLimit
111+
.= _qLimit
112112
<*> optionalFieldOrNull "offset" "Optionally offset from the Nth result"
113-
.= _qOffset
113+
.= _qOffset
114114
<*> optionalFieldOrNull "where" "Optionally constrain the results to satisfy some predicate"
115-
.= _qWhere
115+
.= _qWhere
116116
<*> optionalFieldOrNull "order_by" "Optionally order the results by the value of one or more fields"
117-
.= _qOrderBy
117+
.= _qOrderBy
118118

119119
-- | A relationship consists of the following components:
120120
-- - a sub-query, from the perspective that a relationship field will occur
@@ -132,9 +132,9 @@ relationshipFieldObjectCodec :: JSONObjectCodec RelationshipField
132132
relationshipFieldObjectCodec =
133133
RelationshipField
134134
<$> requiredField "relationship" "The name of the relationship to follow for the subquery"
135-
.= _rfRelationship
135+
.= _rfRelationship
136136
<*> requiredField "query" "Relationship query"
137-
.= _rfQuery
137+
.= _rfQuery
138138

139139
-- | The specific fields that are targeted by a 'Query'.
140140
--
@@ -181,9 +181,9 @@ instance HasCodec QueryResponse where
181181
named "QueryResponse" . object "QueryResponse" $
182182
QueryResponse
183183
<$> optionalFieldOrNull "rows" "The rows returned by the query, corresponding to the query's fields"
184-
.= _qrRows
184+
.= _qrRows
185185
<*> optionalFieldOrNull "aggregates" "The results of the aggregates returned by the query"
186-
.= _qrAggregates
186+
.= _qrAggregates
187187

188188
instance HasStatus QueryResponse where
189189
type StatusOf QueryResponse = 200

server/lib/dc-api/test/Test/SchemaSpec.hs

+6-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ spec TestData {..} api sourceName config API.Capabilities {..} = describe "schem
3838
-- We remove some properties here so that we don't compare them since they vary between agent implementations
3939
let extractJsonForComparison table =
4040
let columns = fmap toJSON . sortOn API._ciName $ API._tiColumns table
41-
in columns & traverse %~ \column ->
42-
column
43-
& _Object . at "type" .~ Nothing -- Types can vary between agents since underlying datatypes can change
44-
& _Object . at "description" .~ Nothing -- Descriptions are not supported by all agents
45-
-- If the agent only supports nullable columns, we make all columns nullable
41+
in columns
42+
& traverse %~ \column ->
43+
column
44+
& _Object . at "type" .~ Nothing -- Types can vary between agents since underlying datatypes can change
45+
& _Object . at "description" .~ Nothing -- Descriptions are not supported by all agents
46+
-- If the agent only supports nullable columns, we make all columns nullable
4647
let setExpectedColumnNullability columns =
4748
if API._dscColumnNullability _cDataSchema == API.OnlyNullableColumns
4849
then columns & traverse %~ (_Object . at "nullable" ?~ Bool True)

server/lib/graphql-parser-hs/.ormolu

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
infix 0 <?>

server/lib/graphql-parser-hs/src/Language/GraphQL/Draft/Parser.hs

+4-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ variableDefinitions = parens (many1 variableDefinition)
112112

113113
variableDefinition :: Parser AST.VariableDefinition
114114
variableDefinition =
115-
AST.VariableDefinition <$> variable
115+
AST.VariableDefinition
116+
<$> variable
116117
<* tok ":"
117118
<*> graphQLType
118119
<*> optional defaultValue
@@ -500,7 +501,8 @@ nameParser :: AT.Parser AST.Name
500501
nameParser =
501502
AST.unsafeMkName
502503
<$> tok
503-
( (<>) <$> AT.takeWhile1 isFirstChar
504+
( (<>)
505+
<$> AT.takeWhile1 isFirstChar
504506
<*> AT.takeWhile isNonFirstChar
505507
)
506508
{-# INLINE nameParser #-}

server/lib/pg-client-hs/src/Database/PG/Query/Connection.hs

+6-3
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ initPQConn ci logger =
192192

193193
whenSerVerNotOk v =
194194
throwIO $
195-
PGConnErr $ "Unsupported postgres version: " <> fromString (show v)
195+
PGConnErr $
196+
"Unsupported postgres version: " <> fromString (show v)
196197

197198
whenSerVerOk conn = do
198199
-- Set some parameters and check the response
@@ -318,7 +319,8 @@ checkResult conn mRes =
318319
msg <- liftIO $ readConnErr conn
319320
let whenConnOk =
320321
throwPGIntErr $
321-
PGIUnexpected $ "Fatal error (perhaps an OOM): " <> msg
322+
PGIUnexpected $
323+
"Fatal error (perhaps an OOM): " <> msg
322324
isConnOk >>= bool (whenConnNotOk msg) whenConnOk
323325
Just res -> do
324326
st <- lift $ PQ.resultStatus res
@@ -537,7 +539,8 @@ execQuery ::
537539
execQuery pgConn pgQuery = do
538540
resOk <-
539541
retryOnConnErr pgConn $
540-
bool withoutPrepare withPrepare $ allowPrepare && preparable
542+
bool withoutPrepare withPrepare $
543+
allowPrepare && preparable
541544
withExceptT PGIUnexpected $ convF resOk
542545
where
543546
PGConn conn allowPrepare cancelable _ _ _ _ _ _ = pgConn

server/lib/pg-client-hs/src/Database/PG/Query/Listen.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ listen pool channel handler = catchConnErr $
7070
eRes <-
7171
liftIO $
7272
runExceptT $
73-
execMulti pgConn (mkTemplate listenCmd) $ const $ return ()
73+
execMulti pgConn (mkTemplate listenCmd) $
74+
const $
75+
return ()
7476
either throwTxErr return eRes
7577
-- Emit onStart event
7678
liftIO $ handler PNEOnStart

server/lib/pg-client-hs/src/Database/PG/Query/Transaction.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ rawQE ef q args prep = TxET $
191191
ReaderT $ \pgConn ->
192192
withExceptT (ef . txErrF) $
193193
hoist liftIO $
194-
execQuery pgConn $ PGQuery (mkTemplate stmt) args prep fromRes
194+
execQuery pgConn $
195+
PGQuery (mkTemplate stmt) args prep fromRes
195196
where
196197
txErrF = PGTxErr stmt args prep
197198
stmt = getQueryText q

0 commit comments

Comments
 (0)