MCPcopy Index your code
hub / github.com/github/docs / validateIfversionConditionals

Function validateIfversionConditionals

tests/linting/lint-versioning.js:119–198  ·  view source on GitHub ↗
(conds)

Source from the content-addressed store, hash-verified

117}
118
119function validateIfversionConditionals(conds) {
120 const errors = []
121
122 conds.forEach((cond) => {
123 // Where `cond` is an array of strings, where each string may have one of the following space-separated formats:
124 // * Length 1: `<version>` (example: `fpt`)
125 // * Length 2: `not <version>` (example: `not ghae`)
126 // * Length 3: `<version> <operator> <release>` (example: `ghes > 3.0`)
127 //
128 // Note that Lengths 1 and 2 may be used with feature-based versioning, but NOT Length 3.
129 const condParts = cond.split(/ (or|and) /).filter((part) => !(part === 'or' || part === 'and'))
130
131 condParts.forEach((str) => {
132 const strParts = str.split(' ')
133 // if length = 1, this should be a valid short version or feature version name.
134 if (strParts.length === 1) {
135 const version = strParts[0]
136 // TODO: This is temporary, see comment on the function.
137 checkForDeprecatedGhaeVersioning(version, errors)
138 // END TODO.
139 const isValidVersion = validateVersion(version)
140 if (!isValidVersion) {
141 errors.push(`"${version}" is not a valid short version or feature version name`)
142 }
143 }
144
145 // if length = 2, this should be 'not' followed by a valid short version name.
146 if (strParts.length === 2) {
147 const [notKeyword, version] = strParts
148 // TODO: This is temporary, see comment on the function.
149 checkForDeprecatedGhaeVersioning(version, errors)
150 // END TODO.
151 const isValidVersion = validateVersion(version)
152 const isValid = notKeyword === 'not' && isValidVersion
153 if (!isValid) {
154 errors.push(`"${cond}" is not a valid conditional`)
155 }
156 }
157
158 // if length = 3, this should be a range in the format: ghes > 3.0
159 // where the first item is `ghes` (currently the only version with numbered releases),
160 // the second item is a supported operator, and the third is a supported GHES release.
161 if (strParts.length === 3) {
162 const [version, operator, release] = strParts
163 const hasSemanticVersioning = Object.values(allVersions).some(
164 (v) => (v.hasNumberedReleases || v.internalLatestRelease) && v.shortName === version
165 )
166 if (!hasSemanticVersioning) {
167 errors.push(
168 `Found "${version}" inside "${cond}" with a "${operator}" operator, but "${version}" does not support semantic comparisons"`
169 )
170 }
171 if (!allowedVersionOperators.includes(operator)) {
172 errors.push(
173 `Found a "${operator}" operator inside "${cond}", but "${operator}" is not supported`
174 )
175 }
176 // Check that the versions in conditionals are supported

Callers 1

lint-versioning.jsFile · 0.85

Calls 2

validateVersionFunction · 0.85

Tested by

no test coverage detected