Skip to content

Commit a4c76bc

Browse files
authored
Add content linter rule to prevent not with feature-based versions (#56679)
1 parent 7d24657 commit a4c76bc

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/content-linter/lib/linting-rules/liquid-versioning.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,14 @@ function validateIfversionConditionals(cond, possibleVersionNames) {
133133
if (strParts.length === 2) {
134134
const [notKeyword, version] = strParts
135135
const isValidVersion = validateVersion(version)
136-
const isValid = notKeyword === 'not' && isValidVersion
137-
if (!isValid) {
136+
const isFeatureBasedVersion = Object.keys(getAllFeatures()).includes(version)
137+
138+
if (notKeyword !== 'not' || !isValidVersion) {
138139
errors.push(`"${cond}" is not a valid conditional`)
140+
} else if (isFeatureBasedVersion) {
141+
errors.push(
142+
`"${cond}" is not valid - the 'not' keyword cannot be used with feature-based version "${version}"`,
143+
)
139144
}
140145
}
141146

src/content-linter/tests/unit/liquid-versioning.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,29 @@ describe(liquidIfVersionTags.names.join(' - '), () => {
9494
const errors = result.markdown
9595
expect(errors.length).toBe(0)
9696
})
97+
98+
test('ifversion tags with not keyword and feature-based versions fail', async () => {
99+
const markdown = [
100+
'{% ifversion not volvo %}',
101+
'{% ifversion fpt or not volvo %}',
102+
'{% ifversion not them-and-all %}',
103+
]
104+
const result = await runRule(liquidIfVersionTags, {
105+
strings: { markdown: markdown.join('\n') },
106+
})
107+
const errors = result.markdown
108+
expect(errors.length).toBe(markdown.length)
109+
expect(errors.every((error) => error.errorDetail.includes('feature-based version'))).toBe(true)
110+
})
111+
112+
test('ifversion tags with not keyword and short versions pass', async () => {
113+
const markdown = [
114+
'{% ifversion not ghec %}',
115+
'{% ifversion fpt or not ghes %}',
116+
'{% ifversion not fpt %}',
117+
].join('\n')
118+
const result = await runRule(liquidIfVersionTags, { strings: { markdown } })
119+
const errors = result.markdown
120+
expect(errors.length).toBe(0)
121+
})
97122
})

0 commit comments

Comments
 (0)