Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kanghyojun committed Feb 11, 2018
1 parent 0eb2c12 commit 02bbdff
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/Nirum/Constructs/TypeDeclaration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ instance Construct TypeDeclaration where
where
fieldsCode = T.intercalate "\n" $ map toCode $ toList fields'
docs' = A.lookupDocs annotationSet'
toCode (TypeDeclaration name' (UnionType tags' defaultTag') annotationSet') =
T.concat [ toCode annotationSet'
toCode (TypeDeclaration name' (UnionType tags' defaultTag') as') =
T.concat [ toCode as'
, "union ", nameCode
, toCodeWithPrefix "\n " (A.lookupDocs annotationSet')
, toCodeWithPrefix "\n " (A.lookupDocs as')
, "\n = " , tagsCode
, "\n ;"
]
Expand All @@ -227,12 +227,12 @@ instance Construct TypeDeclaration where
]
toCode (TypeDeclaration name'
(PrimitiveType typename' jsonType')
annotationSet') =
T.concat [ toCode annotationSet'
as') =
T.concat [ toCode as'
, "// primitive type `", toCode name', "`\n"
, "// internal type identifier: ", showT typename', "\n"
, "// coded to json ", showT jsonType', " type\n"
, docString (A.lookupDocs annotationSet')
, docString (A.lookupDocs as')
]
where
showT :: Show a => a -> T.Text
Expand Down
7 changes: 5 additions & 2 deletions src/Nirum/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,10 @@ unionTypeDeclaration = do

if length (L.filter snd tags') > 1
then fail "`union` have to has only 1 default tag."
else return $ TypeDeclaration typename (UnionType remainTagSet defaultTag) annotationSet''
else return $ TypeDeclaration
typename
(UnionType remainTagSet defaultTag)
annotationSet''

typeDeclaration :: Parser TypeDeclaration
typeDeclaration = do
Expand Down Expand Up @@ -603,7 +606,7 @@ imports = do
spaces
char '('
spaces
idents <- (importName >>= \i -> spaces >> return i)
idents <- (importName >>= \ i -> spaces >> return i)
`sepEndBy1` (char ',' >> spaces)
<?> "names to import"
char ')'
Expand Down
2 changes: 1 addition & 1 deletion src/Nirum/Targets/Docs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ typeDecl mod' ident
|]
where
enumerate :: [a] -> [(Int, a)]
enumerate = zip [0..]
enumerate = zip [0 ..]
enumerateParams :: DES.DeclarationSet S.Parameter -> [(Int, S.Parameter)]
enumerateParams = enumerate . DES.toList
typeDecl _ _ TD.Import {} =
Expand Down
7 changes: 4 additions & 3 deletions src/Nirum/Targets/Python.hs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,8 @@ if hasattr($parentClass, '__qualname__'):
fieldList :: [Field]
fieldList = toList fields
nameMaps :: Code
nameMaps = toIndentedCodes toNamePair (map fieldName fieldList) ",\n "
nameMaps = toIndentedCodes
toNamePair (map fieldName fieldList) ",\n "
parentClass :: T.Text
parentClass = toClassName' parentname
fieldSerializers :: Code
Expand Down Expand Up @@ -1076,7 +1077,6 @@ class #{className}(#{T.intercalate "," $ compileExtendClasses annotations}):
if isinstance(value, dict) and '_tag' not in value:
value = dict(value)
value['_tag'] = '#{toBehindSnakeCaseText $ tagName dt}'
value['_type'] = '#{toAttributeName' typename'}'
%{ of Nothing }
%{ endcase }
if '_type' not in value:
Expand Down Expand Up @@ -1121,7 +1121,8 @@ class #{className}(#{T.intercalate "," $ compileExtendClasses annotations}):
else:
name = attribute_name
tag_types = cls.__nirum_tag_types__
if callable(tag_types): # old compiler could generate non-callable map
# old compiler could generate non-callable map
if callable(tag_types):
tag_types = dict(tag_types())
try:
args[name] = deserialize_meta(tag_types[name], item)
Expand Down
7 changes: 6 additions & 1 deletion test/Nirum/Constructs/TypeDeclarationSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ union shape
nullDecl' =
ServiceDeclaration "null-service" nullService
(singleDocs "Null service declaration.")
pingService = Service [ Method "ping" [] (Just "bool") Nothing empty ]
pingService = Service [ Method
"ping"
[]
(Just "bool")
Nothing
empty ]
pingDecl = ServiceDeclaration "ping-service" pingService empty
pingDecl' =
ServiceDeclaration "ping-service" pingService
Expand Down
4 changes: 2 additions & 2 deletions test/Nirum/ParserSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -842,14 +842,14 @@ union shape
parse' "text get-name (person user)" `shouldBeRight`
Method "get-name" [Parameter "user" "person" empty]
(Just "text") Nothing empty
parse' "text get-name ( person user,text `default` )" `shouldBeRight`
parse' "text get-name (person user,text `default`)" `shouldBeRight`
Method "get-name"
[ Parameter "user" "person" empty
, Parameter "default" "text" empty
]
(Just "text") Nothing empty
parse' "@http(method = \"GET\", path = \"/get-name/\") \
\text get-name ( person user,text `default` )" `shouldBeRight`
\text get-name (person user,text `default`)" `shouldBeRight`
Method "get-name"
[ Parameter "user" "person" empty
, Parameter "default" "text" empty
Expand Down

0 comments on commit 02bbdff

Please sign in to comment.