statiqdev / Statiq.Web

Statiq Web is a flexible static site generator written in .NET.
https://statiq.dev/web
Other
1.64k stars 235 forks source link

Show Line Numbers for ValidateRelativeLink function #942

Open gortok opened 3 years ago

gortok commented 3 years ago

During link validation for a .cshtml file (Razor); I noted that it would tell me the location of the file it couldn't validate, but not the line number:

[INFO] ========== Analyzer Results ==========
[WARN] [C:/Users/George/src/doubleyourproductivity/DypGenerator/input/corporate.cshtml => corporate.html] Could not validate relative link: <link rel="stylesheet" href="../css/bulma-divider.min.css"> (ValidateR                                                    elativeLinks)
[WARN] [C:/Users/George/src/doubleyourproductivity/DypGenerator/input/corporate.cshtml => corporate.html] Could not validate relative link: <a class="navbar-item is-size-5 has-text-weight-semibold" href="/free"                                                    >
                                        Free Content
                                </a> (ValidateRelativeLinks)
[WARN] [C:/Users/George/src/doubleyourproductivity/DypGenerator/input/index.cshtml => index.html] Could not validate relative link: <a class="navbar-item is-size-5 has-text-weight-semibold" href="/free">
                                        Free Content
                                </a> (ValidateRelativeLinks)
[WARN] [C:/Users/George/src/doubleyourproductivity/DypGenerator/input/paid.cshtml => paid.html] Could not validate relative link: <link rel="stylesheet" href="../css/bulma-divider.min.css"> (ValidateRelativeLin                                                    ks)
[WARN] [C:/Users/George/src/doubleyourproductivity/DypGenerator/input/paid.cshtml => paid.html] Could not validate relative link: <a class="navbar-item is-size-5 has-text-weight-semibold" href="/free">
                                        Free Content
                                </a> (ValidateRelativeLinks)
[WARN] 5 total relative links could not be validated (ValidateRelativeLinks)
[INFO] ========== Completed ==========
[INFO] Finished execution in 3860 ms
[INFO] Cleaned temp directory C:/Users/George/src/doubleyourproductivity/DypGenerator/temp

gjstocker@dor MINGW64 ~/src/doubleyourproductivity/DypGenerator (1-statiq-netily-migration)

Recommend that the line number is included in the ValidateRelativeLink function, for ease of finding the line for the error.

daveaglick commented 3 years ago

Excellent idea! I'm going to need to think about implementation a bit though because the line number in the file doesn't necessarily line up with what the Razor engine sees due to stripping out front matter. My first thought is that there are actually a bunch of places where knowing that offset could be valuable for debugging - perhaps a universal ContentOffset value inside the IContentProvider might work well here 🤔. Then any logging that needs to be done relative to line numbers can add the offset to get the real line number of the file on disk (and any modules that remove content can increment it).