fixup! fixup! [#64] Implement copy/paste protection checks

Review: style, typos, naming
This commit is contained in:
Yuri Romanowski 2022-12-16 20:43:29 +05:00
parent 337bec6b5f
commit 9a6aedca0c
No known key found for this signature in database
GPG Key ID: 9244B9434C595CCA
7 changed files with 32 additions and 31 deletions

View File

@ -41,7 +41,7 @@ Unreleased
* [#231](https://github.com/serokell/xrefcheck/pull/231)
+ Anchor analysis takes now into account the appropriate case-sensitivity depending on
the configured Markdown flavour.
* [240](https://github.com/serokell/xrefcheck/pull/240)
* [#240](https://github.com/serokell/xrefcheck/pull/240)
+ Now xrefcheck is able to detect possible copy-pastes relying on links and their names.
0.2.2

View File

@ -162,7 +162,7 @@ There are several ways to fix this:
followed by an <!-- xrefcheck: no duplication check in link --> [copypasted intentionally](https://good.link.uri/).
```
* You can use a `<!-- xrefcheck: no duplication check in paragraph -->` annotation to disable copy-paste check in a paragraph.
* You can use a `<!-- xrefcheck: no duplication check in file -->` annotation to disable copy-paste check within an entire file.
* You can use a `<!-- xrefcheck: no duplication check in file -->` annotation at the top of the file to disable copy-paste check within an entire file.
## Further work [](#xrefcheck)

View File

@ -107,8 +107,8 @@ data FileInfoDiff = FileInfoDiff
makeLenses ''FileInfoDiff
diffToFileInfo :: Bool -> FileInfoDiff -> FileInfo
diffToFileInfo ignoreCpcInFile (FileInfoDiff refs anchors) =
FileInfo (DList.toList refs) (DList.toList anchors) ignoreCpcInFile
diffToFileInfo cpcEnabledInFile (FileInfoDiff refs anchors) =
FileInfo (DList.toList refs) (DList.toList anchors) cpcEnabledInFile
instance Semigroup FileInfoDiff where
FileInfoDiff a b <> FileInfoDiff c d = FileInfoDiff (a <> c) (b <> d)

View File

@ -136,7 +136,7 @@ instance Buildable ScanErrorDescription where
ParagraphErrCpc txt -> [int||Expected a PARAGRAPH after \
"no duplication check in paragraph" annotation, but found #{txt}|]
UnrecognisedErr txt -> [int||Unrecognised option "#{txt}", perhaps you meant
<"ignore link"|"ignore paragraph"|"ignore all">
"ignore <link|paragraph|all>"
or "no duplication check in <link|paragraph|file>"?|]
specificFormatsSupport :: [([Extension], ScanAction)] -> FormatsSupport

View File

@ -207,11 +207,11 @@ processAnnotations fp = withIgnoreMode . cataNodeWithParentNodeInfo process
IMAGE {} -> handleLink ign ty traverseChildren
_ -> handleOther ign ty traverseChildren
handleLink ::
Maybe Ignore ->
NodeType ->
ScannerM NodeCPC ->
ScannerM NodeCPC
handleLink
:: Maybe Ignore
-> NodeType
-> ScannerM NodeCPC
-> ScannerM NodeCPC
handleLink ign ty traverseChildren = do
-- It's common for all ignore states
ssIgnore .= Nothing
@ -230,10 +230,10 @@ processAnnotations fp = withIgnoreMode . cataNodeWithParentNodeInfo process
Just (Ignore (IMSLink _) _) -> do
pure defNode
handleParagraph ::
Maybe Ignore ->
ScannerM NodeCPC ->
ScannerM NodeCPC
handleParagraph
:: Maybe Ignore
-> ScannerM NodeCPC
-> ScannerM NodeCPC
handleParagraph ign traverseChildren = do
-- If a new paragraph was expected (this stands for True), now we
-- don't expect paragraphs any more.
@ -263,11 +263,11 @@ processAnnotations fp = withIgnoreMode . cataNodeWithParentNodeInfo process
pure node
handleOther ::
Maybe Ignore ->
NodeType ->
ScannerM NodeCPC ->
ScannerM NodeCPC
handleOther
:: Maybe Ignore
-> NodeType
-> ScannerM NodeCPC
-> ScannerM NodeCPC
handleOther ign ty traverseChildren = do
-- If right now there was a copy/paste ignore annotation for paragraph,
-- emit an error and reset these states.
@ -295,8 +295,9 @@ processAnnotations fp = withIgnoreMode . cataNodeWithParentNodeInfo process
Just (IMSLink _) -> ssIgnoreCopyPasteCheck .= Nothing
_ -> pass
reportExpectedParagraphAfterIgnoreCpcAnnotation ::
NodeType -> ScannerM ()
reportExpectedParagraphAfterIgnoreCpcAnnotation
:: NodeType
-> ScannerM ()
reportExpectedParagraphAfterIgnoreCpcAnnotation ty =
use ssIgnoreCopyPasteCheck >>= \case
Just (Ignore IMSParagraph modePos) ->
@ -306,11 +307,11 @@ processAnnotations fp = withIgnoreMode . cataNodeWithParentNodeInfo process
ssIgnoreCopyPasteCheck .= Nothing
_ -> pass
wrapTraverseNodeWithLinkExpected ::
IgnoreLinkState ->
Maybe PosInfo ->
ScannerM NodeCPC ->
ScannerM NodeCPC
wrapTraverseNodeWithLinkExpected
:: IgnoreLinkState
-> Maybe PosInfo
-> ScannerM NodeCPC
-> ScannerM NodeCPC
wrapTraverseNodeWithLinkExpected ignoreLinkState modePos =
if ignoreLinkState /= ExpectingLinkInSubnodes
then id
@ -325,9 +326,9 @@ processAnnotations fp = withIgnoreMode . cataNodeWithParentNodeInfo process
_ -> pass
return node'
wrapTraverseNodeWithLinkExpectedForCpc ::
ScannerM NodeCPC ->
ScannerM NodeCPC
wrapTraverseNodeWithLinkExpectedForCpc
:: ScannerM NodeCPC
-> ScannerM NodeCPC
wrapTraverseNodeWithLinkExpectedForCpc traverse' = do
ignoreCpc <- use ssIgnoreCopyPasteCheck
case ignoreCpc of

View File

@ -4,7 +4,7 @@
scan error at src:35:1-25:
Unrecognised option "no dh", perhaps you meant
<"ignore link"|"ignore paragraph"|"ignore all">
"ignore <link|paragraph|all>"
or "no duplication check in <link|paragraph|file>"?
➥ In file second-file.md

View File

@ -19,7 +19,7 @@
scan error at src:21:1-50:
Unrecognised option "ignore unrecognised-annotation", perhaps you meant
<"ignore link"|"ignore paragraph"|"ignore all">
"ignore <link|paragraph|all>"
or "no duplication check in <link|paragraph|file>"?
➥ In file check-second-file.md