Commit Graph

69 Commits

Author SHA1 Message Date
Adrián Enríquez
1c44c1c43e
[Style] Sort some package.yaml arrays
Problem: some arrays from the package.yaml file seemed to be almost
alphabetically sorted, but not completely.

Solution: sort the default-extensions and dependencies arrays from the
package.yaml file.
2022-12-23 12:19:42 +01:00
Adrián Enríquez
b30413dd41
[#254] Revise dump-config command
Problem: xrefcheck does not allow to print the config to stdout instead
of writing it to a file. Also, it is easy to overwrite your changes by
mistake by executing the command again.

Solution: provide a --stdout flag to print the config to stdout, and do
not write it to a file unless a --force flag has been included.
2022-12-23 12:19:25 +01:00
Adrián Enríquez
0886062500
[#197] Canonicalize filepaths
Problem: the current usage of filepaths is error-prone and can be
simplified.

Solution: canonicalize filepaths at the boundaries, so their management
will be safer and will simplify the codebase.
2022-12-22 16:29:23 +01:00
Adrián Enríquez
dd52970029
[#211] Avoid warning on case-insensitive systems
Problem: There is currently some problem in stack or cabal
that produces a warning when building this project on
case-insensitive systems.

Solution: The current workaroud for it is to add the GHC
option '-optP-Wno-nonportable-include-path'.
2022-12-13 12:59:58 +01:00
Anton Sorokin
fb77575b0b
[#164] Add workflow for running Windows tests on CI
Problem: we are not testing behavior of xrefcheck on Windows

Solution: and add workflow to run
golden and tasty tests on CI
via github-actions windows runner
Some subproblems appear:

1.
Problem: CI build fails beacuse it needs `pcre` package
Solution: add it (somehow), see `install pacman dependencies`
in ci.yml

2.
Problem: Network errors displayed different on different platforms
Solution: collect output from both and use
`assert_diff expected_linux.gold || assert_diff expected_windows.gold`

3:
Problem: "Config matches" test is failing because checkout action
clone files with CRLF, and test assert equality of two ByteStrings
Solution: manually remove CR
2022-11-30 21:00:58 +02:00
Anton Sorokin
09783e0213
[#164] Use utf8-compatible codepage on Windows
Problem: xrefcheck uses utf8 symbols in reports, which are not supported
on most of Windows shells by default.
Sometimes they are printed as question marks (and it cause golden tests to fail)
and sometimes printing of them raise an error.

Solution: use function `withCP65001` from `code-page` package which
sets correct codepage on Windows and do nothing on other OSs
2022-11-29 19:35:16 +02:00
Anton Sorokin
7115c657ea
[#223] Use nyan-interpolation for defConfigText
Problem:
We have a function `defConfigText :: Flavor -> ByteString` that
uses  `fillHoles` to modify `defConfigUnfilled`.
This is a bit error-prone and very complicated way to have a
`ByteString` with parametric blocks. Also using `ByteString`
instead of `Text` to store text leads to CRLF-related issues when
launched on Windows.

Solution:
Remove `fillHoles` and `defConfigUnfilled`,
`defConfigText` creates a `Text` using `nyan-interpolation`.
2022-11-29 16:52:13 +02:00
Anton Sorokin
8e5f76e210
fixup! fixup! fixup! [#89] Handle user interrupts 2022-11-10 16:20:12 +02:00
Anton Sorokin
8012dc94d3
[#213] Do not print trailing whitespaces
Problem: bats tests are not space sensetive
Solution: remove trailing spaces from xrefcheck output
(see next problems), remove `--ignore-trailing-space`
from `assert_diff`

Problem: there are lines containing only spaces in
xrefcheck's output, because `Fmt.indentF` "indents"
empty lines too.
Solution: add `Xrefcheck.Util.Interpolate.interpolateIndentF`
function that is not indenting empty lines.
Same for `Fmt.blockListF` and `Fmt.blockListF'`.
Those functions are not adding trailing newlines, so it's
easier to use it in interpolation blocks.

Problem: when there is a current file link `[a](#b)`, it is
printed like
```
- text: "a"
- link: (trailing space here)
- anchor: b
```
Solution: like with anchors, print `link: -` instead
2022-11-10 15:10:59 +02:00
Anton Sorokin
82bf996615
[#201] Use nyan-interpolation for building error messages
Problem:
We often need to create large strings, and we use different
fmt tools for this (by-hand concatenation, unlinesF, etc).
Sometimes it is unclear or too heavy, and it always can
be called error-prone

Solution: use `int` quasiquoter to build large strings and
have nice-looking and easy-to-read code
2022-11-03 17:39:10 +02:00
Diogo Castro
94d55601ae
v0.2.2 release 2022-10-25 10:27:27 +01:00
Sergey Gulin
bfbe20a5b0
[#139] Ignore build-related files
Problem: At the moment, we're using the ignored option for mainly 2
purposes: 1) to ignore all files in the `.git` folder (`.git/**/*`) to
ignore all build-related temporary files (the default config ignores
`.stack-work/**/*`). A more robust alternative might be to ignore all
files implicitly ignored by git.

Solution: Use `git ls-files` to ignore all files implicitly ignored by git.
2022-10-21 22:07:00 +10:00
Anton Sorokin
847b21bfbc
[#185] Add CLI option to disable output coloring
Problem: output of xrefcheck contains ANSI-colored text,
which is bad when we redirect output to file
or when our terminal is not supporting colors.
Colorising is performed in `Buildable` instances of various types,
so we can't just pass some extra flag here

Solution: add CLI  option `--no-color`
Create `colorIfNeeded` and `styleIfNeeded` functions that have
`Data.Reflection.Given ColorMode` constraint, and replace all usages of
 `color` and `style` by them, adding new
constraint to instances.
2022-10-08 22:26:10 +03:00
Diogo Castro
b625a38f16
[Chore] Pull cmark-gfm 0.2.5 from hackage
Problem: in #158, we started using `optFootnotes` from the `cmark-gfm`
package. This feature hadn't yet been released on hackage, so we pulled
the package from its github repo.

Since then, cmark-gfm-0.2.5 has been released on hackage.

Solution: pull the latest version from hackage and add a lower bound on
the dependency.
2022-10-07 21:23:44 +01:00
Anton Sorokin
371c53d283
[#179] Drop roman-numerals
Problem: We depend on `roman-numerals` package,
which is outdatead and can't be built with
GHC 9.2.4, which is used by Hackage to generate Haddocks.

Solution: the only place we use this package is showing header levels,
so we can show them "by hands" instead
2022-10-04 19:46:33 +03:00
Diogo Castro
4e9294fbb7
[Chore] Add version constraint to base
Problem: `stack sdist` fails with the following message when there are no version constraints on `base`:

> Package check reported the following errors:
> The dependency 'build-depends: base' does not specify an upper bound on the version number. Each major release of the 'base' package changes the API in various ways and most packages will need some changes to compile with it. The recommended practice is to specify an upper bound on the version of the 'base' package. This ensures your package will continue to build when a new major version of the 'base' package is released. If you are not sure what upper bound to use then use the next  major version. For example if you have tested your package with 'base' version 4.5 and 4.6 then use 'build-depends: base >= 4.5 && < 4.7'.

Solution: Add a version constraint to `base`.
2022-09-28 10:58:59 +01:00
Anton Sorokin
b412781020
[#149] Replace hspec with tasty
Problem: `hspec` and `tasty` are testing frameworks with
almost same functionality,
for historical reasons in xrefcheck we  used different frameworks
for tests and links-tests, and in Serokell we prefer `tasty` now.

Solution: use only `tasty`,
 rewrite code that use `hspec` using correspondance between
 - `testGroup` and `describe`
 -  `testCase` and `it`
 - `shouldBe` and `@?=`
2022-09-25 18:51:41 +03:00
Diogo Castro
0871e29907
v0.2.1 release 2022-09-24 08:30:53 +01:00
Sergey Gulin
c8d19a3f98
[#56] Dump all the errors from different files
Problem: Currently, xrefcheck fails immediately after the first
observed error because `die` is used right in `markdownScanner` What
we want is dumping all the errors from different markdowns and then
print them as a final xrefcheck's result together with the broken
links. Also, despite the fact that in the `makeError` function we have
4 error messages, 2 of them are not reported, and the test case that
should check this only checks that at least one of the four files
throws an error.

Solution: Make xrefcheck to report all errors. Add `ScanError` type
and propagate errors to report all of them, rather than failing
immediately after the first error is detected.
2022-09-23 17:13:50 +10:00
Sergey Gulin
a3f2d28216
[#125] Display URL parsing errors
Problem: We use a 2-step process to parse a URL: we use `parseURI` and
then `mkURIBs`. Both of these functions can fail. At the moment, we're
ignoring their errors and simply throwing a `ExternalResourceInvalidUri`,
and then displaying a generic error message to the user.

Solution: Catch errors from `parseUri` and `mkURIBs` and use them to
tell user why the URL was invalid.
2022-09-08 22:31:12 +10:00
Constantine Ter-Matevosian
80b5edd1c7
[#49] Allow certain reserved characters in the URLs
Problem: The current version of xrefcheck doesn't allow the square
brackets and some other special characters, like the angle brackets and
the curly brackets, to be present in the URLs, even in the query
strings, as they need to be percent-encoded first.

Solution: Allow some of the reserved characters, like the brackets, to
be present in the query strings of the URLs.
There exist two main standards of URL parsing: RFC 3986 and the Web
Hypertext Application Technology Working Group's URL standard. Ideally,
we want to be able to parse the URLs in accordance with the latter
standard, because it provides a much less ambiguous set of rules for
percent-encoding special characters, and is essentially a living
standard that gets updated constantly.
We allow these characters to be present in the query strings by using
the `parseURI` function from the `uri-bytestring` library with
`laxURIParseOptions`.
2022-09-06 04:39:40 +10:00
Andrei Borzenkov
a6b4513587 [#95] Support HTML tag parsing compatible with HTML spec
Problem: We had hardcoded HTML tag parser, that doesn't work with add valid HTML tags

Solution: Replace it with `tagsoup` library, that care about all parsing stuff
2022-07-17 20:48:51 +04:00
Constantine Ter-Matevosian
032395007b
[#31] Handle the "429 too many requests" errors
Problem: The current version of xrefcheck handles the HTTP responses
with the 429 status code just like every other error, when it is
possible to try and eliminate the occurrences of such errors within the
program itself.

Solution: Each time the result of performing a request on a given link
is a 429 error, retrieve the Retry-After information, describing the
delay (in seconds), from the headers of the HTTP response, or,
alternatively, use a configurable default value if the Retry-After
header is absent, and rerun the request after an amount of time
described by the said value had passed. Only after the number of retries
had reached its limiting value, which, as of right now, is not
configurable and is hardcoded, is when the 429 error is converted into
becoming 'unfixable', and any further attempts to remove the error are
terminated.

Additionally, the progress bar has been upgraded and the following
elements are supplied:
1. an extra color -- Blue -- indicating the errors that might get
   eliminated during the verification;
2. a timer with the number of seconds left to wait for the restart of
   the request; if, during the verification, a new 429 error had emerged
   with the new Retry-After value being greater than or equal to the
   elapsed time, the timer is immediately updated with that value and
   begins ticking down each second from scratch.
2022-07-14 17:25:52 +03:00
Andrei Borzenkov
55268fee2c [#106] Fix using ./ in paths
Problem: --ignored and --root CLI options had misbehave when you use ./ in path

Solution: add path normalisation and path-equality from System.FilePath instead of common functions for strings
2022-07-13 16:13:38 +04:00
Andrei Borzenkov
654d143113 [#105] Add hlint support, enable -Weveryting
Problem: we had a lot redundant dependencies and had no linter for handling obvious errors

Solution: hlint support and enable -Weverything flag, fix all hints from them, add hlint to the CI pipeline
2022-07-13 11:08:01 +04:00
Andrei Borzenkov
e460301275 [#107] Replace file-embed library with inline config
Problem: At new resolver version we recieved obscure error when tried to cross-compile project to Windows on CI. Changing file-embed version to the old one doesn't help us.

Solution: inline content of this file into haskell source, using raw-string-qq library, that helps us to avoid escaping and typing newline characters.
2022-07-08 13:01:13 +04:00
Andrei Borzenkov
b255445a55 [#107] Update stack resolver to the newer version
Problem: We had old resolver version, that used ghc 8.10.4 and outdated versions of libraries

Solution: Change resolver to lts 19.13, that uses ghc 9.0.2 and update haskell.nix configuration files to can build project via `nix-build` command
2022-07-08 13:01:13 +04:00
Андреев Кирилл
a9a156ef41
Undo errorneous version increment 2021-11-09 15:50:13 +04:00
Андреев Кирилл
9ecf668fbc
Add explicit strategies to deriving clauses
Problem:  The `deriving ($classes...)` is becoming obsolete.

Solution: Replace with `deriving $strat ($classes...)`;
          make old deriving a warning.
2021-11-04 18:46:54 +04:00
Андреев Кирилл
d644a95734
[#71] Separate concerns in Node traversal.
Problem:  The tree traversal uses explicit recursion and
          does not-closely-unrelated stuff at once.

Solution: Separate different actions.
2021-11-01 15:25:34 +04:00
Kirill Andreev
92c3de5587
Improve readability of imports
Problem:  In
          ```
          import qualified Foo.Bar as Bar
          import Foo.Bar (Bar)
          ```
          names of the imported modules are on different
          vertical lines, which disables autosorting,
          and makes it harder to read.

Solution: Use `ImportQualifiedPost`
2021-11-01 15:25:29 +04:00
Kirill Andreev
2f9a9d8599
Remove mixins
Problem:  Stack cannot build projects with mixins, and they only
          used to splice universum instead of base.

Solution: Use `NoImplicitPreduce` and import `Universum`
          everywhere explicitly.
2021-11-01 15:24:25 +04:00
Andrey Demidenko
c67ee9bd52
[#47] Handle ftp links
Problem:
Currently we support only http and https links. If there is an `ftp://`
link, you will get exception.

Solution:
Use `ftp-client` to check connection to ftp, see response statuses and
check file existence. This produces adding new error types and small
refactoring.
Provide a test which is separate executable, where we have to pass CLA -
ftp host.

Co-authored-by: Alexander Bantyev <alexander.bantyev@serokell.io>
2021-10-08 13:59:14 +03:00
Andrey Demidenko
24226ac2d8
[#81] Add config option for protected links
Problem:
We do not know what to do with protected links, because we cannot check
them. So we have two options, assume that these links is valid or not.

Solution:
Provide config option for user to decide what to do - assume protected
links valid or not.
2021-10-08 13:29:19 +03:00
Kirill Andreev
a61defd917
[#62] [INT-141] Add to changelog, update version 2021-10-04 14:12:09 +04:00
martoon
06a39de707
Make 0.2 release 2021-05-04 15:51:28 +03:00
martoon
045f4146cf
[#55] Generate config depending on the repo type
Problem: now when we include repository type into the config, it seems
to make sense to generate config differently depending on the repository
type. Especially taking into account that currently in some fields we
mix GitHub and GitLab -specific contents.

Solution:

Leave placeholders in the default config and later fill them from the
code depending on the required repository type.

Add a mandatory repository type parameter to `dump-config` CLI command.

Along with a test checking for config validity, add a golden test on the
produced config so that we could assess how sane it looks like.
2021-05-03 17:01:20 +03:00
martoon
63c09a0e55
Prepare 0.1.3 release
Problem: the feature with ignoring links has been added, and it is
necessary in many places.

Solution: make a release.
2021-03-17 15:06:19 +03:00
martoon
d0ca7d7771
[#35] Stop using aeson-options
`aeson-options` package is going to be deprecated. Moreover, it does not
work in the recent lts.

Solution: use `aeson-casing` package instead.
2021-03-10 12:08:29 +03:00
Alyona Antonova
bc9e497efb [#135] Add tests and markdowns to check ignoring regex performance
Problem: There are no tests checking ignoring
regex performance.

Solution: Add test checking that broken links
matched by regexs are not verified and
test checking that not matched broken links
are verified as links with error.
2021-03-09 22:18:07 +03:00
Alyona Antonova
ecff1dc342 [#135] Add support of right in-place annotations
Problem: It can be convenient not only specifying
exclusions in the config, but also annotating
the excluded thing right in-place. It is about
adding comment before the link or the paragraph
or even the whole file to ignore this item.

Solution: Support annotation as html comment in
a "<!-- xrefcheck: ignore mode -->" format, where
mode is "link" or "paragraph" or "file". Modify
`nodeExtractInfo` from `Xrefcheck.Scanners.Markdown`
just to skip a node in AST while parsing. Take into
account that "ignore file" can only be at the top
of the file or right after the license. In markdown
terms: either the first node must be HTML_BLOCK
with "<!-- xrefcheck: ignore file -->" content
or the first is HTML_BLOCK comment (smth
between "<!--" and "-->") and the second is
HTML_BLOCK with "ignore file" content.
Also take into account that "ignore link" must be
followed by a link. Strictly speaking, there is
either LINK after "ignore link" or TEXT and LINK
(if there is some text before the link).
2021-03-09 22:18:07 +03:00
Alyona Antonova
40640124db [#135] Add vcIgnoreRefs as regexs to Xrefcheck.Config
Problem: External links must be ignored sometimes
and not be checked for validity.

Solution: Add `vcIgnoreRefs` to `Config` that is a list
of regexs using `regex-tdfa`. Each regex define a link
we want to ignore while validating. Change
`checkExternalResource` to support matching the regex.
2021-03-09 16:42:29 +03:00
Alexander Bantyev
76b7ae101b
Add a windows build 2020-07-03 12:08:22 +03:00
Ivan Gromakovskii
c56a9eb0bc
Add an upper bound on base
Problem: `stack upload` does not like that `base` does not have an
upper bound, it reports an error while checking the package.

Solution: add an upper bound on `base` to prevent people from using a
broken version of this package in case of breaking changes in `base`.
Since we build with stack, our current default is 4.13 (deduced from
the resolver). However, 4.14 does not seem to have any breaking changes
https://hackage.haskell.org/package/base-4.14.0.0/changelog
so it should be fine to permit it as well, and that's what we are doing.
2020-06-29 23:58:08 +03:00
martoon
0d6e61905f
Make a release 2020-06-26 22:32:03 +03:00
Ivan Gromakovskii
59f188c496
[#36] Switch to lts-15.13
Problem: LTS-14.16 that we currently using and a bit old.
And its GHC is old as well.

Solution: update the resolver, make some changes that were necessary.
They are pretty trivial. The only essential breaking change is the
removal of `parseUrl` from `req`.
2020-05-23 18:41:11 +03:00
Ivan Gromakovskii
557cbeef54
Update version and changelog
Hopefully with recent changes Hackage will finally manage to
build this package, so let's try uploading again.
2020-05-19 21:15:51 +03:00
Ivan Gromakovskii
ccc402574e
[#30] Depend on base instead of base-noprelude
Problem: base-noprelude is a non-standard dependency, unlike `base`.
Due to our use of `mixins` we don't need `base-noprelude` anymore,
we can just hide `Prelude`.

Solution: use `base` and hide `Prelude`.
2020-05-19 21:07:05 +03:00
Ivan Gromakovskii
c87b37e724
Drop autoexporter usage
Problem: `autoexporter` is used in one place to re-export one module.
Probably one day it will re-export more, but at this point it's really
overkill.
Moreover, it causes Hackage build to fail for the reasons mentioned
here:
https://github.com/haskell/hackage-server/issues/821

Solution: stop using it, re-export manually.
2020-05-19 20:57:31 +03:00
martoon
eb98aa70e4
Mention 'Path_* module in package.yaml`
Problem: after we started using mixins feature, generated .cabal file
requires cabal 2.0. Attempt to upload our package to Hackage now reports
an error, saying that `autogen-modules` section have to mention `Path_*`
files.

Solution: add `Paths_xrefcheck` to `generated-other-modules` section of
`package.yaml`.
2020-05-16 16:11:04 +03:00