Skip to content

Commit 81cfa44

Browse files
authored
Turn on ifversion rule and fix bug (#55454)
1 parent 329369d commit 81cfa44

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

data/reusables/contributing/content-linter-rules.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@
5656
| GHD018 | liquid-syntax | Markdown content must use valid Liquid | error | liquid |
5757
| GHD019 | liquid-if-tags | Liquid `ifversion` tags should be used instead of `if` tags when the argument is a valid version | error | liquid, versioning |
5858
| GHD020 | liquid-ifversion-tags | Liquid `ifversion` tags should contain valid version names as arguments | error | liquid, versioning |
59+
| GHD022 | liquid-ifversion-versions | Liquid `ifversion`, `elsif`, and `else` tags should be valid and not contain unsupported versions. | error | liquid, versioning |
5960
| GHD035 | rai-reusable-usage | RAI articles and reusables can only reference reusable content in the data/reusables/rai directory | error | feature, rai |
6061
| GHD036 | image-no-gif | Image must not be a gif, styleguide reference: contributing/style-guide-and-content-model/style-guide.md#images | error | images |
6162
| GHD038 | expired-content | Expired content must be remediated. | error | expired |
6263
| GHD039 | expiring-soon | Content that expires soon should be proactively addressed. | warning | expired |
6364
| [GHD040](https://github.com/github/docs/blob/main/src/content-linter/README.md) | table-liquid-versioning | Tables must use the correct liquid versioning format | error | tables |
6465
| GHD041 | third-party-action-pinning | Code examples that use third-party actions must always pin to a full length commit SHA | error | feature, actions |
6566
| GHD042 | liquid-tag-whitespace | Liquid tags should start and end with one whitespace. Liquid tag arguments should be separated by only one whitespace. | error | liquid, format |
66-
| GHD043 | link-quotation | Internal link titles must not be surrounded by quotations | error | links, url |
67+
| GHD043 | link-quotation | Internal link titles must not be surrounded by quotations | error | links, url |
68+
| GHD022 | liquid-ifversion-versions | Liquid `ifversion`, `elsif`, and `else` tags should be valid and not contain unsupported versions. | error | liquid, versioning |

src/content-linter/lib/linting-rules/liquid-ifversion-versions.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,8 @@ async function getApplicableVersionFromLiquidTag(conditionStr, filename) {
196196
const firstAnd = ands[0].split(' ')[0]
197197
// if all ands don't start with the same version it's invalid
198198
if (!ands.every((and) => and.startsWith(firstAnd))) {
199-
console.error(
200-
'The condition tag `' + conditionStr + '` is invalid. Please update ' + filename,
201-
)
199+
// noop - we don't handle this case
200+
// TODO - handle this case in the future
202201
return []
203202
}
204203
const andValues = []

src/content-linter/style/github-docs.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ const githubDocsConfig = {
8989
'partial-markdown-files': true,
9090
'yml-files': true,
9191
},
92-
// 'liquid-ifversion-versions': {
93-
// // GHD022
94-
// severity: 'error',
95-
// 'partial-markdown-files': true,
96-
// 'yml-files': true,
97-
// },
92+
'liquid-ifversion-versions': {
93+
// GHD022
94+
severity: 'error',
95+
'partial-markdown-files': true,
96+
'yml-files': true,
97+
},
9898
'yaml-scheduled-jobs': {
9999
// GHD021
100100
severity: 'error',
@@ -206,12 +206,12 @@ export const githubDocsFrontmatterConfig = {
206206
severity: 'error',
207207
'partial-markdown-files': false,
208208
},
209-
// 'liquid-ifversion-versions': {
210-
// // GHD022
211-
// severity: 'error',
212-
// 'partial-markdown-files': true,
213-
// 'yml-files': true,
214-
// },
209+
'liquid-ifversion-versions': {
210+
// GHD022
211+
severity: 'error',
212+
'partial-markdown-files': true,
213+
'yml-files': true,
214+
},
215215
'link-quotation': {
216216
// GHD043
217217
severity: 'error',

src/ghes-releases/scripts/version-utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,7 @@ export function isAllVersions(versions: FrontmatterVersions) {
5858
export function getFeatureVersionsObject(feature: string) {
5959
const featureDataDir = process.env.ROOT ? `${process.env.ROOT}/data/features` : 'data/features'
6060
const featureData = getDataDirectory(featureDataDir) as FeatureData
61+
const featureValue = featureData[feature]
62+
if (!featureValue) return {}
6163
return featureData[feature].versions
6264
}

src/versions/lib/get-applicable-versions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function getApplicableVersions(versionsObj, filepath, opts = {}) {
4040
(result, value, key) => {
4141
if (key === 'feature') {
4242
if (typeof value === 'string') {
43-
Object.assign(result, { ...featureData[value].versions })
43+
Object.assign(result, { ...featureData[value]?.versions })
4444
} else if (Array.isArray(value)) {
4545
value.forEach((str) => {
4646
Object.assign(result, { ...featureData[str].versions })

0 commit comments

Comments
 (0)