lspitzner / lspitzner/brittany

More "walking comment" bugs

Open
#253 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug hs:comments layouting
Dominant language
Haskell
Stars
686
Forks
69
PR merge metrics
No merged PRs in 30d

Description

It seems the ["walking comment"](https://github.com/lspitzner/brittany/issues/167) problem still exists. It arises only within `instance` bodies with vertical alignment.

Here are the examples found:

```hs
instance ToJSON CompleteMathQuestion where
toJSON CompleteMathQuestion {..} = Object $ core <> extra
where
-- We don't want to repeat the `QuestionExtra` instance here so we smush the two parts together
(Object core) = object
[ "id" .= completeMathQuestionId
, "is-deprecated" .= completeMathQuestionIsDeprecated
, "stem-id" .= completeMathQuestionStemId
, "skill-id" .= completeMathQuestionSkillId
, "answer-type" .= completeMathQuestionAnswerType
, "is-printable" .= completeMathQuestionIsPrintable
, "question-text" .= completeMathQuestionText
, "question-diagram-name" .= completeMathQuestionDiagramName
, "summative-test" .= completeMathQuestionSummativeTest
, "answers" .= completeMathQuestionAnswers
, "worth" .= completeMathQuestionWorth
]
(Object extra) = toJSON completeMathQuestionExtra
```

```hs
instance Ord StandardCode where
StandardCode gradeL domainL tailL `compare` StandardCode gradeR domainR tailR
=
-- It doesn't make sense to order standards from different domains, but we already have too much code relying on this.
domainL
`compare` domainR
<> gradeL
`compare` gradeR
<> tailL
`compare` tailR
```

```hs
instance Arbitrary BadgeAward where
arbitrary =
BadgeAward
<$> arbitrary
<*> arbitrary
<*> arbitrary
-- This is a garbage value for testing. Only the frontend utilizes the meta data.
<*> pure Nothing
<*> arbitrary
```

```hs
instance Arbitrary MathStandardAssignmentAnswer where
arbitrary =
MathStandardAssignmentAnswer
<$> arbitrary
<*> arbitrary
<*> arbitrary
<*> (getPositive <$> arbitrary)
<*> arbitrary
<*> arbitrary
-- NB. All new answers will have an associated @answer@
<*> (Just <$> arbitrary)
```

```hs
instance ToJSON BadgeAwardResponse where
toJSON m = case m of
-- Flattens the structure. Aeson's derivations only allow specification of
-- the "tag" and "contents" field (through @sumEncoding@), so we need
-- something customized.
Static response ->
toJSON $ object ["tag" .= String "static"] `WithMetadata` response
Tier response ->
toJSON $ object ["tag" .= String "tier"] `WithMetadata` response
Category response ->
toJSON $ object ["tag" .= String "category"] `WithMetadata` response
Level response ->
toJSON $ object ["tag" .= String "level"] `WithMetadata` response
SubjectExpertResponse response ->
toJSON $ object ["tag" .= String "subject-expert"] `WithMetadata` response
```

```hs

instance FromJSON MathAssessmentMetadata where
parseJSON = A.withObject "MathAssessment metadata" $ \o ->
-- must be ordered from most specific to least specific parsers
Legacy
. MAMGradeManyStandards
<$> parseJSON (Object o) <|> Legacy . MAMGradeDomainStandard
<$> parseJSON (Object o) <|> Legacy . MAMGradeDomain
<$> parseJSON (Object o) <|> MathAssessmentMetadata
<$> parseJSON (Object o)
-- fail "could not parse"
```

```hs
instance ToJSON Metrics where
toJSON Metrics {..} = object
[ "metrics" .= object
[ "minutes" .= (getSum seconds `div` 60)

-- Underscores in this JSON are intentional
--
-- Clever Goals utilizes a `noun_verb` "syntax" for goal naming. The
-- properties correlate directly with a goal's name. In this way goal
-- naming is dynamic and can be thought of as a simple key value store.
-- The underscore separates the two components of the goal's name. This
-- expressily dissallows multiple underscores in any goal name.
--
-- `minutes` is a fixed property and diverges from the `noun_verb` syntax.
--
, "math_completed" .= mathCompleted
, "ela_completed" .= elaCompleted
, "science_completed" .= scienceCompleted
, "socialstudies_completed" .= socialStudiesCompleted
]
]
```

```hs
instance FromNamedRecord CompleteMathQuestion where
parseNamedRecord m = do
-- Extract question id early to improve error reporting
completeMathQuestionId <- m .: "id"
case CSV.runParser (parseCompleteMathQuestion completeMathQuestionId m) of
Left msg -> M.fail
(T.unpack (questionIdtoText completeMathQuestionId) ++ ": " ++ msg)
Right val -> pure val
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin by comparing the listed instance-body examples with the behavior described in issue #167 and tracing Brittany's vertical-alignment handling for comments. Confirm the formatter's current output on each example; done means comments remain attached to their intended code and formatting is stable for all shown cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.