[#169] Rename ignore file annotation to ignore all

Problem: as in #169, `ignore file` annotation is ignoring
not file itself but all links at file, which is not obvious

Solution: rename it to `ignore all`

Also renamed `IMFile :: IgnoreMode` and `IMSFile :: IgnoreModeState`
to `IMAll` and `IMSAll`
This commit is contained in:
Anton Sorokin 2022-10-19 17:23:03 +03:00
parent eafff47c60
commit 23b52729b1
No known key found for this signature in database
GPG Key ID: 4B53B91ADFBFB649
13 changed files with 42 additions and 38 deletions

View File

@ -52,6 +52,11 @@ Unreleased
instead of expecting link in whole rest of file.
If you've got `Expected a LINK after "ignore link" annotation` message, see
PR's description for examples and details.
* [#199](https://github.com/serokell/xrefcheck/pull/199)
+ Now annotation
`<!-- xrefcheck: ignore all -->` instead of `<!-- xrefcheck: ignore file -->`
should be used to disable checking for links in file, so it's clearer that
file itself is not ignored (and links can target it).
0.2.1
==========

View File

@ -146,7 +146,7 @@ xrefcheck --help
<!-- a comment -->
<!-- another comment -->
<!-- xrefcheck: ignore file -->
<!-- xrefcheck: ignore all -->
...the rest of the file...
```

View File

@ -108,12 +108,12 @@ data ScanErrorDescription
instance Buildable ScanErrorDescription where
build = \case
LinkErr -> "Expected a LINK after \"ignore link\" annotation"
FileErr -> "Annotation \"ignore file\" must be at the top of \
FileErr -> "Annotation \"ignore all\" must be at the top of \
\markdown or right after comments at the top"
ParagraphErr txt -> "Expected a PARAGRAPH after \
\\"ignore paragraph\" annotation, but found " +| txt |+ ""
UnrecognisedErr txt -> "Unrecognised option \"" +| txt |+ "\" perhaps you meant \
\<\"ignore link\"|\"ignore paragraph\"|\"ignore file\"> "
\<\"ignore link\"|\"ignore paragraph\"|\"ignore all\"> "
specificFormatsSupport :: [([Extension], ScanAction)] -> FormatsSupport
specificFormatsSupport formats = \ext -> M.lookup ext formatsMap

View File

@ -78,7 +78,7 @@ nodeExtractText = T.strip . mconcat . map extractText . nodeFlatten
data IgnoreMode
= IMLink
| IMParagraph
| IMFile
| IMAll
deriving stock (Eq)
-- | "ignore link" pragmas in different places behave slightly different,
@ -103,7 +103,7 @@ data IgnoreLinkState
data IgnoreModeState
= IMSLink IgnoreLinkState
| IMSParagraph
| IMSFile
| IMSAll
deriving stock (Eq)
-- | Bind `IgnoreMode` to its `PosInfo` so that we can tell where the
@ -178,11 +178,11 @@ removeIgnored fp = withIgnoreMode . cataNodeWithParentNodeInfo remove
ssIgnore .= Nothing
Node pos ty <$> sequence subs
-- We don't expect to find an `ignore file` annotation here,
-- We don't expect to find an `ignore all` annotation here,
-- since that annotation should be at the top of the file and
-- the file should already be ignored when `checkIgnoreFile` is called.
-- We should report an error if we find it anyway.
(IMSFile, _) -> do
(IMSAll, _) -> do
lift . tell $ makeError modePos fp FileErr
ssIgnore .= Nothing
Node pos ty <$> sequence subs
@ -228,7 +228,7 @@ removeIgnored fp = withIgnoreMode . cataNodeWithParentNodeInfo remove
IMParagraph -> pure IMSParagraph
IMFile -> pure IMSFile
IMAll -> pure IMSAll
(ssIgnore .= Just (Ignore ignoreModeState correctPos)) $> defNode
InvalidMode msg -> do
@ -257,7 +257,7 @@ removeIgnored fp = withIgnoreMode . cataNodeWithParentNodeInfo remove
IMSLink _ -> do
tell $ makeError pos fp LinkErr
pure node
IMSFile -> do
IMSAll -> do
tell $ makeError pos fp FileErr
pure node
(node, _) -> pure node
@ -277,7 +277,7 @@ nodeExtractInfo
-> Node
-> ExtractorM FileInfo
nodeExtractInfo fp input@(Node _ _ nSubs) = do
if checkIgnoreFile nSubs
if checkIgnoreAllFile nSubs
then return def
else diffToFileInfo <$> (foldNode extractor =<< lift (removeIgnored fp input))
@ -336,10 +336,10 @@ nodeExtractInfo fp input@(Node _ _ nSubs) = do
(DList.singleton $ Reference {rName, rPos, rLink, rAnchor})
DList.empty
-- | Check if there is `ignore file` at the beginning of the file,
-- | Check if there is `ignore all` at the beginning of the file,
-- ignoring preceding comments if there are any.
checkIgnoreFile :: [Node] -> Bool
checkIgnoreFile nodes =
checkIgnoreAllFile :: [Node] -> Bool
checkIgnoreAllFile nodes =
let isSimpleComment :: Node -> Bool
isSimpleComment node = isComment node && not (isIgnoreFile node)
@ -350,7 +350,7 @@ checkIgnoreFile nodes =
isComment = isJust . getCommentContent
isIgnoreFile :: Node -> Bool
isIgnoreFile = (ValidMode IMFile ==) . getIgnoreMode
isIgnoreFile = (ValidMode IMAll ==) . getIgnoreMode
defNode :: Node
defNode = Node Nothing DOCUMENT [] -- hard-coded default Node
@ -398,7 +398,7 @@ textToMode :: [Text] -> GetIgnoreMode
textToMode ("ignore" : [x])
| x == "link" = ValidMode IMLink
| x == "paragraph" = ValidMode IMParagraph
| x == "file" = ValidMode IMFile
| x == "all" = ValidMode IMAll
| otherwise = InvalidMode x
textToMode _ = NotAnAnnotation

View File

@ -27,10 +27,10 @@ test_ignoreAnnotations =
let file = "tests/markdowns/with-annotations/no_paragraph.md"
errs <- getErrs file
errs @?= makeError (Just $ PosInfo 7 1 7 35) file (ParagraphErr "HEADING")
, testCase "Check if broken ignore file annotation produce error" do
, testCase "Check if broken ignore all annotation produce error" do
let file = "tests/markdowns/with-annotations/unexpected_ignore_file.md"
errs <- getErrs file
errs @?= makeError (Just $ PosInfo 9 1 9 30) file FileErr
errs @?= makeError (Just $ PosInfo 9 1 9 29) file FileErr
, testCase "Check if broken unrecognised annotation produce error" do
let file = "tests/markdowns/with-annotations/unrecognised_option.md"
errs <- getErrs file
@ -50,8 +50,8 @@ test_ignoreAnnotations =
getRefs fi @?= ["blog", "contacts"]
errs @?= []
]
, testGroup "\"ignore file\" mode"
[ testCase "Check \"ignore file\" performance" $ do
, testGroup "\"ignore all\" mode"
[ testCase "Check \"ignore all\" performance" $ do
(fi, errs) <- parse GitHub "tests/markdowns/with-annotations/ignore_file.md"
getRefs fi @?= []
errs @?= []

View File

@ -41,9 +41,9 @@ load '../helpers'
=== Scan errors found ===
➥ In file to-ignore/inner-directory/broken_annotation.md
scan error at src:9:1-30:
scan error at src:9:1-29:
⛀ Annotation "ignore file" must be at the top of markdown or right after comments at the top
⛀ Annotation "ignore all" must be at the top of markdown or right after comments at the top
@ -58,9 +58,9 @@ EOF
=== Scan errors found ===
➥ In file to-ignore/inner-directory/broken_annotation.md
scan error at src:9:1-30:
scan error at src:9:1-29:
⛀ Annotation "ignore file" must be at the top of markdown or right after comments at the top
⛀ Annotation "ignore all" must be at the top of markdown or right after comments at the top
Scan errors dumped, 1 in total.

View File

@ -1,10 +1,9 @@
=== Scan errors found ===
➥ In file ./to-ignore/inner-directory/broken_annotation.md
scan error at src:9:1-30:
⛀ Annotation "ignore file" must be at the top of markdown or right after comments at the top
scan error at src:9:1-29:
⛀ Annotation "ignore all" must be at the top of markdown or right after comments at the top
Scan errors dumped, 1 in total.

View File

@ -6,6 +6,6 @@
One
<!--xrefcheck: ignore file -->
<!--xrefcheck: ignore all -->
Two

View File

@ -6,7 +6,7 @@
one
<!--xrefcheck: ignore file -->
<!--xrefcheck: ignore all -->
[Bad reference](/no-file.md)

View File

@ -6,6 +6,6 @@
another file with broken annotation
<!--xrefcheck: ignore file -->
<!--xrefcheck: ignore all -->
[Another bad reference](/a.md)

View File

@ -2,9 +2,9 @@
➥ In file check-scan-errors.md
scan error at src:9:1-30:
scan error at src:9:1-29:
⛀ Annotation "ignore file" must be at the top of markdown or right after comments at the top
⛀ Annotation "ignore all" must be at the top of markdown or right after comments at the top
➥ In file check-scan-errors.md
@ -22,13 +22,13 @@
➥ In file check-scan-errors.md
scan error at src:21:1-50:
⛀ Unrecognised option "unrecognised-annotation" perhaps you meant <"ignore link"|"ignore paragraph"|"ignore file">
⛀ Unrecognised option "unrecognised-annotation" perhaps you meant <"ignore link"|"ignore paragraph"|"ignore all">
➥ In file check-second-file.md
scan error at src:9:1-30:
scan error at src:9:1-29:
⛀ Annotation "ignore file" must be at the top of markdown or right after comments at the top
⛀ Annotation "ignore all" must be at the top of markdown or right after comments at the top
➥ In file no_link_eof.md

View File

@ -7,7 +7,7 @@
<!-- a comment -->
<!-- another comment -->
<!-- xrefcheck:ignore file -->
<!-- xrefcheck:ignore all -->
Serokell [web-site](https://serokell.io/)
Serokell [team](https://serokell.io/team)
@ -16,4 +16,4 @@ Serokell [blog](https://serokell.io/blog)
Serokell [labs](https://serokell.io/labs)
Serokell [contacts](https://serokell.io/contacts)
Serokell [contacts](https://serokell.io/contacts)

View File

@ -6,6 +6,6 @@
the first paragraph
<!--xrefcheck: ignore file -->
<!--xrefcheck: ignore all -->
the second paragraph
the second paragraph