Skip to content

Commit c9c2c03

Browse files
authored
Revert "Repo sync"
1 parent efcebd7 commit c9c2c03

File tree

20 files changed

+67
-668
lines changed

20 files changed

+67
-668
lines changed

src/content-linter/lib/linting-rules/frontmatter-landing-recommended.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,13 @@ import { addError } from 'markdownlint-rule-helpers'
55
import { getFrontmatter } from '../helpers/utils'
66

77
function isValidArticlePath(articlePath, currentFilePath) {
8-
const ROOT = process.env.ROOT || '.'
9-
10-
// Strategy 1: Always try as an absolute path from content root first
11-
const contentDir = path.join(ROOT, 'content')
12-
const normalizedPath = articlePath.startsWith('/') ? articlePath.substring(1) : articlePath
13-
const absolutePath = path.join(contentDir, `${normalizedPath}.md`)
14-
15-
if (fs.existsSync(absolutePath) && fs.statSync(absolutePath).isFile()) {
16-
return true
17-
}
18-
19-
// Strategy 2: Fall back to relative path from current file's directory
8+
// Article paths in recommended are relative to the current page's directory
9+
const relativePath = articlePath.startsWith('/') ? articlePath.substring(1) : articlePath
2010
const currentDir = path.dirname(currentFilePath)
21-
const relativePath = path.join(currentDir, `${normalizedPath}.md`)
11+
const fullPath = path.join(currentDir, `${relativePath}.md`)
2212

2313
try {
24-
return fs.existsSync(relativePath) && fs.statSync(relativePath).isFile()
14+
return fs.existsSync(fullPath) && fs.statSync(fullPath).isFile()
2515
} catch {
2616
return false
2717
}

src/content-linter/tests/fixtures/landing-recommended/test-absolute-only.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/content-linter/tests/fixtures/landing-recommended/test-absolute-priority.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/content-linter/tests/fixtures/landing-recommended/test-path-priority.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/content-linter/tests/fixtures/landing-recommended/test-priority-validation.md

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, test, beforeAll, afterAll } from 'vitest'
1+
import { describe, expect, test } from 'vitest'
22

33
import { runRule } from '@/content-linter/lib/init-test'
44
import { frontmatterLandingRecommended } from '@/content-linter/lib/linting-rules/frontmatter-landing-recommended'
@@ -10,28 +10,13 @@ const DUPLICATE_RECOMMENDED =
1010
'src/content-linter/tests/fixtures/landing-recommended/duplicate-recommended.md'
1111
const INVALID_PATHS = 'src/content-linter/tests/fixtures/landing-recommended/invalid-paths.md'
1212
const NO_RECOMMENDED = 'src/content-linter/tests/fixtures/landing-recommended/no-recommended.md'
13-
const ABSOLUTE_PRIORITY =
14-
'src/content-linter/tests/fixtures/landing-recommended/test-absolute-priority.md'
15-
const PATH_PRIORITY = 'src/content-linter/tests/fixtures/landing-recommended/test-path-priority.md'
16-
const ABSOLUTE_ONLY = 'src/content-linter/tests/fixtures/landing-recommended/test-absolute-only.md'
17-
const PRIORITY_VALIDATION =
18-
'src/content-linter/tests/fixtures/landing-recommended/test-priority-validation.md'
1913

2014
const ruleName = frontmatterLandingRecommended.names[1]
2115

2216
// Configure the test fixture to not split frontmatter and content
2317
const fmOptions = { markdownlintOptions: { frontMatter: null } }
2418

2519
describe(ruleName, () => {
26-
const envVarValueBefore = process.env.ROOT
27-
28-
beforeAll(() => {
29-
process.env.ROOT = 'src/fixtures/fixtures'
30-
})
31-
32-
afterAll(() => {
33-
process.env.ROOT = envVarValueBefore
34-
})
3520
test('landing page with recommended articles passes', async () => {
3621
const result = await runRule(frontmatterLandingRecommended, {
3722
files: [VALID_LANDING],
@@ -90,61 +75,4 @@ describe(ruleName, () => {
9075
})
9176
expect(result[VALID_LANDING]).toEqual([])
9277
})
93-
94-
test('absolute paths are prioritized over relative paths', async () => {
95-
// This test verifies that when both absolute and relative paths exist with the same name,
96-
// the absolute path is chosen over the relative path.
97-
//
98-
// Setup:
99-
// - /article-one should resolve to src/fixtures/fixtures/content/article-one.md (absolute)
100-
// - article-one (relative) would resolve to src/content-linter/tests/fixtures/landing-recommended/article-one.md
101-
//
102-
// The test passes because our logic prioritizes the absolute path resolution first
103-
const result = await runRule(frontmatterLandingRecommended, {
104-
files: [ABSOLUTE_PRIORITY],
105-
...fmOptions,
106-
})
107-
expect(result[ABSOLUTE_PRIORITY]).toEqual([])
108-
})
109-
110-
test('path priority resolution works correctly', async () => {
111-
// This test verifies that absolute paths are prioritized over relative paths
112-
// when both files exist with the same name.
113-
//
114-
// Setup:
115-
// - /article-one could resolve to EITHER:
116-
// 1. src/fixtures/fixtures/content/article-one.md (absolute - should be chosen)
117-
// 2. src/content-linter/tests/fixtures/landing-recommended/article-one.md (relative - should be ignored)
118-
//
119-
// Our prioritization logic should choose #1 (absolute) over #2 (relative)
120-
// This test passes because the absolute path exists and is found first
121-
const result = await runRule(frontmatterLandingRecommended, {
122-
files: [PATH_PRIORITY],
123-
...fmOptions,
124-
})
125-
expect(result[PATH_PRIORITY]).toEqual([])
126-
})
127-
128-
test('absolute-only paths work when no relative path exists', async () => {
129-
// This test verifies that absolute path resolution works when no relative path exists
130-
// /article-two exists in src/fixtures/fixtures/content/article-two.md
131-
// but NOT in src/content-linter/tests/fixtures/landing-recommended/article-two.md
132-
// This test would fail if we didn't prioritize absolute paths properly
133-
const result = await runRule(frontmatterLandingRecommended, {
134-
files: [ABSOLUTE_ONLY],
135-
...fmOptions,
136-
})
137-
expect(result[ABSOLUTE_ONLY]).toEqual([])
138-
})
139-
140-
test('mixed valid and invalid absolute paths are handled correctly', async () => {
141-
// This test has both a valid absolute path (/article-one) and an invalid one (/nonexistent-absolute)
142-
// It should fail because of the invalid path, proving our absolute path resolution is working
143-
const result = await runRule(frontmatterLandingRecommended, {
144-
files: [PRIORITY_VALIDATION],
145-
...fmOptions,
146-
})
147-
expect(result[PRIORITY_VALIDATION]).toHaveLength(1)
148-
expect(result[PRIORITY_VALIDATION][0].errorDetail).toContain('nonexistent-absolute')
149-
})
15078
})

src/fixtures/fixtures/article-one.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/fixtures/fixtures/content/article-one.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/fixtures/fixtures/content/article-two.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/fixtures/fixtures/content/subdir/article-three.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)