-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#64] Copy paste detection in lists #102
Draft
Heimdell
wants to merge
7
commits into
master
Choose a base branch
from
kirill.andreev/copy-paste-in-lists
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
317e3a6
Convert empty instances to `derive anyclass`
Heimdell e16377b
Move imports of DList in Xrefcheck.Core
Heimdell 681c6b1
Add a type to store bad copy-paste info
Heimdell dfda710
Remove manual enumeration of flavours
Heimdell f60aece
Add a plug for copy-paste detector
Heimdell 94748c5
Add copy-paste scanner and tests
Heimdell 034bef5
Restore gist extraction
Heimdell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ import Control.Lens (makeLenses) | |
import Data.Aeson (FromJSON (..), withText) | ||
import Data.Char (isAlphaNum) | ||
import Data.Char qualified as C | ||
import Data.DList (DList) | ||
import Data.DList qualified as DList | ||
import Data.Default (Default (..)) | ||
import Data.List qualified as L | ||
import Data.Map qualified as M | ||
|
@@ -26,8 +28,6 @@ import Text.Numeral.Roman (toRoman) | |
|
||
import Xrefcheck.Progress | ||
import Xrefcheck.Util | ||
import Data.DList (DList) | ||
import Data.DList qualified as DList | ||
|
||
----------------------------------------------------------- | ||
-- Types | ||
|
@@ -62,6 +62,7 @@ instance FromJSON Flavor where | |
-- representation of this thing, and it actually appears in reports only. | ||
newtype Position = Position (Maybe Text) | ||
deriving stock (Show, Eq, Generic) | ||
deriving anyclass NFData | ||
|
||
instance Buildable Position where | ||
build (Position pos) = case pos of | ||
|
@@ -77,7 +78,9 @@ data Reference = Reference | |
, rAnchor :: Maybe Text | ||
-- ^ Section or custom anchor tag. | ||
, rPos :: Position | ||
} deriving stock (Show, Generic) | ||
} | ||
deriving stock (Show, Generic) | ||
deriving anyclass NFData | ||
|
||
-- | Context of anchor. | ||
data AnchorType | ||
|
@@ -88,35 +91,50 @@ data AnchorType | |
| BiblioAnchor | ||
-- ^ Id of entry in bibliography | ||
deriving stock (Show, Eq, Generic) | ||
deriving anyclass NFData | ||
|
||
-- | A referable anchor. | ||
data Anchor = Anchor | ||
{ aType :: AnchorType | ||
, aName :: Text | ||
, aPos :: Position | ||
} deriving stock (Show, Eq, Generic) | ||
} | ||
deriving stock (Show, Eq, Generic) | ||
deriving anyclass NFData | ||
|
||
data CopyPaste = CopyPaste | ||
{ cpAnchorText :: Text | ||
, cpPlainText :: Text | ||
, cpPosition :: Position | ||
} | ||
deriving stock (Show, Eq, Generic) | ||
deriving anyclass NFData | ||
|
||
data FileInfoDiff = FileInfoDiff | ||
{ _fidReferences :: DList Reference | ||
, _fidAnchors :: DList Anchor | ||
, _fidCopyPastes :: DList CopyPaste | ||
} | ||
makeLenses ''FileInfoDiff | ||
|
||
diffToFileInfo :: FileInfoDiff -> FileInfo | ||
diffToFileInfo (FileInfoDiff refs anchors) = | ||
FileInfo (DList.toList refs) (DList.toList anchors) | ||
diffToFileInfo (FileInfoDiff refs anchors pastas) = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: I believe here should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🍝 |
||
FileInfo (DList.toList refs) (DList.toList anchors) (DList.toList pastas) | ||
|
||
instance Semigroup FileInfoDiff where | ||
FileInfoDiff a b <> FileInfoDiff c d = FileInfoDiff (a <> c) (b <> d) | ||
FileInfoDiff a b e <> FileInfoDiff c d f = FileInfoDiff (a <> c) (b <> d) (e <> f) | ||
|
||
instance Monoid FileInfoDiff where | ||
mempty = FileInfoDiff mempty mempty | ||
mempty = FileInfoDiff mempty mempty mempty | ||
|
||
-- | All information regarding a single file we care about. | ||
data FileInfo = FileInfo | ||
{ _fiReferences :: [Reference] | ||
, _fiAnchors :: [Anchor] | ||
} deriving stock (Show, Generic) | ||
, _fiCopyPastes :: [CopyPaste] | ||
} | ||
deriving stock (Show, Generic) | ||
deriving anyclass NFData | ||
makeLenses ''FileInfo | ||
|
||
instance Default FileInfo where | ||
|
@@ -129,12 +147,6 @@ newtype RepoInfo = RepoInfo (Map FilePath FileInfo) | |
-- Instances | ||
----------------------------------------------------------- | ||
|
||
instance NFData Position | ||
instance NFData Reference | ||
instance NFData AnchorType | ||
instance NFData Anchor | ||
instance NFData FileInfo | ||
|
||
instance Buildable Reference where | ||
build Reference{..} = | ||
nameF ("reference " +| paren (build loc) |+ " " +| rPos |+ "") $ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like
AnchorText
andPlainText
sound confusing. The issue doesn't focus on anchors, but all type of links, external and internal. Perhaps, more genericLinkText
andURLText
would be better?UPD: Okay, I'm not sure if all the links were intended to check, as there is only example with files in issue description. But it's also not clear that this feature is for files only