Skip to content

Commit 2c7f8b3

Browse files
committed
feat: validate space around dates; update tests;
1 parent cbfc87b commit 2c7f8b3

2 files changed

Lines changed: 35 additions & 14 deletions

File tree

tools/copyright/sync-header-years.mjs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,22 @@ export function updateCopyrightYears(content, year) {
101101
const start = Number.parseInt(startYear, 10);
102102
const end = endYear ? Number.parseInt(endYear, 10) : start;
103103

104-
if (Number.isNaN(start) || Number.isNaN(end) || end >= year) {
104+
if (Number.isNaN(start) || Number.isNaN(end)) {
105105
return `${prefix}${startYear}${endYear ? `${separator}${endYear}` : ''}${suffix}`;
106106
}
107+
108+
const resolvedEnd = end >= year ? end : year;
109+
107110
if (!endYear) {
108-
return `${prefix}${startYear} - ${year}${suffix}`;
111+
// Single year already current — no range needed
112+
if (resolvedEnd === start) {
113+
return `${prefix}${startYear}${suffix}`;
114+
}
115+
return `${prefix}${startYear} - ${resolvedEnd}${suffix}`;
109116
}
110-
return `${prefix}${startYear}${separator}${year}${suffix}`;
117+
118+
// Always normalize separator to ' - ' and bump end year when stale
119+
return `${prefix}${startYear} - ${resolvedEnd}${suffix}`;
111120
});
112121
}
113122

tools/copyright/sync-header-years.test.mjs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,40 @@ import test from 'node:test';
44
import { hasInvalidPingCopyrightHeader, updateCopyrightYears } from './sync-header-years.mjs';
55

66
test('updates stale range end year and keeps start year', () => {
7-
const input = '/* Copyright 2020-2026 Ping Identity. All Rights Reserved */';
7+
const input = '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */';
88
const actual = updateCopyrightYears(input, 2026);
9-
assert.equal(actual, '/* Copyright 2020-2026 Ping Identity. All Rights Reserved */');
9+
assert.equal(actual, '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */');
1010
});
1111

12-
test('updates stale single year to a range preserving start year', () => {
12+
test('normalizes separator on an already-current range', () => {
13+
const input = '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */';
14+
const actual = updateCopyrightYears(input, 2026);
15+
assert.equal(actual, '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */');
16+
});
17+
18+
test('expands stale single year to a range preserving start year', () => {
19+
const input = '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */';
20+
const actual = updateCopyrightYears(input, 2026);
21+
assert.equal(actual, '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */');
22+
});
23+
24+
test('does not change an already-current spaced range', () => {
1325
const input = '/* Copyright 2025 - 2026 Ping Identity. All Rights Reserved */';
1426
const actual = updateCopyrightYears(input, 2026);
15-
assert.equal(actual, '/* Copyright 2025 - 2026 Ping Identity. All Rights Reserved */');
27+
assert.equal(actual, input);
1628
});
1729

1830
test('supports © and © variants', () => {
1931
const input = [
20-
'/* © Copyright 2020-2026 Ping Identity. */',
21-
'<!-- &copy; Copyright 2020-2026 Ping Identity. -->',
32+
'/* © Copyright 2020 - 2026 Ping Identity. */',
33+
'<!-- &copy; Copyright 2020 - 2026 Ping Identity. -->',
2234
].join('\n');
2335
const actual = updateCopyrightYears(input, 2026);
2436
assert.equal(
2537
actual,
2638
[
27-
'/* © Copyright 2020-2026 Ping Identity. */',
28-
'<!-- &copy; Copyright 2020-2026 Ping Identity. -->',
39+
'/* © Copyright 2020 - 2026 Ping Identity. */',
40+
'<!-- &copy; Copyright 2020 - 2026 Ping Identity. -->',
2941
].join('\n'),
3042
);
3143
});
@@ -45,12 +57,12 @@ test('updates Ping Identity Corporation ranges with spaces and (c)', () => {
4557
);
4658
});
4759

48-
test('updates Ping Identity Corporation stale single year with (c) to range', () => {
49-
const input = '/* Copyright (c) 2025 - 2026 Ping Identity Corporation. All right reserved. */';
60+
test('expands stale single year with (c) to a range for Ping Identity Corporation', () => {
61+
const input = '/* Copyright (c) 2023 - 2026 Ping Identity Corporation. All right reserved. */';
5062
const actual = updateCopyrightYears(input, 2026);
5163
assert.equal(
5264
actual,
53-
'/* Copyright (c) 2025 - 2026 Ping Identity Corporation. All right reserved. */',
65+
'/* Copyright (c) 2023 - 2026 Ping Identity Corporation. All right reserved. */',
5466
);
5567
});
5668

0 commit comments

Comments
 (0)