Skip to content
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

feat(docs-linter): add lint for local links #2416

Merged
merged 34 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d578061
add checks for local files
leohhhn Jun 21, 2024
ded07f3
fix links
leohhhn Jun 21, 2024
7122f98
link
leohhhn Jun 21, 2024
937241a
links
leohhhn Jun 21, 2024
16d9d2e
fix comments
leohhhn Jun 21, 2024
d77c3b6
add comments
leohhhn Jun 21, 2024
ec370ac
fix comments
leohhhn Jun 21, 2024
9607c40
Apply suggestions from code review
leohhhn Jun 24, 2024
986d989
Merge branch 'master' into docs/linter-files
leohhhn Jun 24, 2024
25f9634
rename file
leohhhn Jun 24, 2024
3a44230
rename job
leohhhn Jun 24, 2024
66758ef
inline ifs
leohhhn Jun 24, 2024
2061e51
add better embedmd link check
leohhhn Jun 24, 2024
b1382e0
rename and remove redeclaration
leohhhn Jun 24, 2024
c89ef2d
rename maps
leohhhn Jun 24, 2024
b722ecf
org imports
leohhhn Jun 24, 2024
21c700d
redeclare
leohhhn Jun 24, 2024
767d375
lastindex
leohhhn Jun 24, 2024
1ae1b0b
add testcase
leohhhn Jun 24, 2024
8322650
Merge branch 'master' into docs/linter-files
leohhhn Jun 24, 2024
346667f
lastindex case
leohhhn Jun 24, 2024
de8cc5b
add case check for embedmd
leohhhn Jun 24, 2024
ec10dcc
add flow test
leohhhn Jun 25, 2024
d5190a0
rm typo
leohhhn Jun 25, 2024
0f84478
Merge branch 'master' into docs/linter-files
leohhhn Jun 26, 2024
d2ed755
update
leohhhn Jun 26, 2024
172bdba
update help
leohhhn Jun 26, 2024
4ddfd52
save
leohhhn Jun 26, 2024
99249d3
update tests
leohhhn Jun 26, 2024
a971146
add testcase
leohhhn Jun 26, 2024
64d6e5f
org imports
leohhhn Jun 26, 2024
91fb6ca
add lock for writing
leohhhn Jun 28, 2024
77b1e15
Merge branch 'refs/heads/master' into docs/linter-files
leohhhn Jun 28, 2024
04081ac
Merge branch 'refs/heads/master' into docs/linter-files
leohhhn Jun 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions misc/docs-linter/links.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ func extractLocalLinks(fileContent []byte) []string {
for scanner.Scan() {
line := scanner.Text()

// Find embedmd links
if strings.Contains(line, "[embedmd]") {
openPar := strings.Index(line, "(")
deelawn marked this conversation as resolved.
Show resolved Hide resolved
closePar := strings.Index(line, ")")

link := line[openPar+1 : closePar]
if pos := strings.Index(link, " "); pos != -1 {
link = link[:pos]
}

links = append(links, link)
continue
}

// Find all matches
matches := re.FindAllString(line, -1)

Expand All @@ -34,10 +48,6 @@ func extractLocalLinks(fileContent []byte) []string {
match = match[:pos]
}

if pos := strings.Index(match, " "); pos != -1 {
match = match[:pos]
}

links = append(links, match)
}
}
Expand Down
6 changes: 2 additions & 4 deletions misc/docs-linter/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,19 @@ func TestExtractLocalLinks(t *testing.T) {
// Create mock file content with random local links
mockFileContent := `
Here is some text with a link to a local file: [text](../concepts/file1.md)
Here is some text with a link to a local file: [text](../concepts/file2.md something weird)
Here is another local link: [another](./path/to/file1.md)
Here is another local link: [another](./path/to/file2.md#header-1-2)
Here is another local link: [another](./path/to/file2.md #header-1-2 weird text)
And a link to an external website: [example](https://example.com)
And a websocket link: [websocket](ws://example.com/socket)
Here's an embedmd link': [embedmd]:# (../assets/how-to-guides/simple-library/tapas.gno go)
`

// Expected JSX tags
expectedLinks := []string{
"../concepts/file1.md",
"../concepts/file2.md",
"./path/to/file1.md",
"./path/to/file2.md",
"./path/to/file2.md",
"../assets/how-to-guides/simple-library/tapas.gno",
}

// Extract local links tags from the mock file content
Expand Down
Loading