Skip to content

Commit 3b6e6f5

Browse files
authored
Merge pull request #205 from effigies/feat/additional-columns
feat: Default to more permissive for additional columns in TSV
2 parents 0d8f824 + ab30b99 commit 3b6e6f5

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
<!--
9+
### Added
10+
11+
- A bullet item for the Added category.
12+
13+
-->
14+
### Changed
15+
16+
- Handle TSV schema rules with missing or `n/a` values for `additional_columns`.
17+
18+
<!--
19+
### Fixed
20+
21+
- A bullet item for the Fixed category.
22+
23+
-->
24+
<!--
25+
### Deprecated
26+
27+
- A bullet item for the Deprecated category.
28+
29+
-->
30+
<!--
31+
### Removed
32+
33+
- A bullet item for the Removed category.
34+
35+
-->
36+
<!--
37+
### Security
38+
39+
- A bullet item for the Security category.
40+
41+
-->
42+
<!--
43+
### Infrastructure
44+
45+
- A bullet item for the Infrastructure category.
46+
47+
-->

src/schema/tables.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ export function evalAdditionalColumns(
239239
if (context.extension !== '.tsv') return
240240
const headers = Object.keys(context?.columns)
241241
if (rule.columns) {
242+
if (!rule.additional_columns || rule.additional_columns === 'n/a' ) {
243+
// Old schemas might be missing the field, so be permissive.
244+
// New schemas indicate it is not applicable with 'n/a'.
245+
return
246+
}
242247
const ruleHeadersNames = Object.keys(rule.columns).map(
243248
// @ts-expect-error
244249
(x) => schema.objects.columns[x].name,
@@ -250,11 +255,11 @@ export function evalAdditionalColumns(
250255
if (rule.additional_columns?.startsWith('allowed')) {
251256
extraCols = extraCols.filter((header) => !(header in context.sidecar))
252257
}
253-
const code = rule.additional_columns === 'allowed'
254-
? 'TSV_ADDITIONAL_COLUMNS_UNDEFINED'
258+
const code = rule.additional_columns === 'not_allowed'
259+
? 'TSV_ADDITIONAL_COLUMNS_NOT_ALLOWED'
255260
: rule.additional_columns === 'allowed_if_defined'
256261
? 'TSV_ADDITIONAL_COLUMNS_MUST_DEFINE'
257-
: 'TSV_ADDITIONAL_COLUMNS_NOT_ALLOWED'
262+
: 'TSV_ADDITIONAL_COLUMNS_UNDEFINED'
258263
const issue = {
259264
code,
260265
location: context.path,

0 commit comments

Comments
 (0)