Skip to content

Commit b780c49

Browse files
committed
fix: add exclude paths to pre-commit date update; update test input dates;
1 parent 30eab18 commit b780c49

2 files changed

Lines changed: 41 additions & 9 deletions

File tree

tools/copyright/sync-header-years.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function run() {
2020
const changedFiles = [];
2121

2222
for (const file of stagedFiles) {
23-
if (!isFile(file)) {
23+
if (!isFile(file) || isExcluded(file)) {
2424
continue;
2525
}
2626
const absolutePath = resolve(process.cwd(), file);
@@ -77,6 +77,18 @@ function getStagedFiles() {
7777
return output.split('\n').filter(Boolean);
7878
}
7979

80+
export function isExcluded(filePath) {
81+
return EXCLUDE_PATTERNS.some((pattern) => pattern.test(filePath));
82+
}
83+
84+
const EXCLUDE_PATTERNS = [
85+
/\.test\.[cm]?[jt]sx?$/i,
86+
/\.spec\.[cm]?[jt]sx?$/i,
87+
/(^|[/\\])dist[/\\]/,
88+
/(^|[/\\])vendor[/\\]/,
89+
/(^|[/\\])node_modules[/\\]/,
90+
];
91+
8092
function isFile(filePath) {
8193
try {
8294
return statSync(filePath).isFile();

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
import assert from 'node:assert/strict';
22
import test from 'node:test';
33

4-
import { hasInvalidPingCopyrightHeader, updateCopyrightYears } from './sync-header-years.mjs';
4+
import {
5+
hasInvalidPingCopyrightHeader,
6+
isExcluded,
7+
updateCopyrightYears,
8+
} from './sync-header-years.mjs';
59

610
test('updates stale range end year and keeps start year', () => {
7-
const input = '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */';
11+
const input = '/* Copyright 2020-2024 Ping Identity. All Rights Reserved */';
812
const actual = updateCopyrightYears(input, 2026);
913
assert.equal(actual, '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */');
1014
});
1115

1216
test('normalizes separator on an already-current range', () => {
13-
const input = '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */';
17+
const input = '/* Copyright 2020-2026 Ping Identity. All Rights Reserved */';
1418
const actual = updateCopyrightYears(input, 2026);
1519
assert.equal(actual, '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */');
1620
});
1721

1822
test('expands stale single year to a range preserving start year', () => {
19-
const input = '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */';
23+
const input = '/* Copyright 2020 Ping Identity. All Rights Reserved */';
2024
const actual = updateCopyrightYears(input, 2026);
2125
assert.equal(actual, '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */');
2226
});
@@ -29,8 +33,8 @@ test('does not change an already-current spaced range', () => {
2933

3034
test('supports © and © variants', () => {
3135
const input = [
32-
'/* © Copyright 2020 - 2026 Ping Identity. */',
33-
'<!-- &copy; Copyright 2020 - 2026 Ping Identity. -->',
36+
'/* © Copyright 2020-2024 Ping Identity. */',
37+
'<!-- &copy; Copyright 2020-2024 Ping Identity. -->',
3438
].join('\n');
3539
const actual = updateCopyrightYears(input, 2026);
3640
assert.equal(
@@ -49,7 +53,7 @@ test('does not update non-Ping headers', () => {
4953
});
5054

5155
test('updates Ping Identity Corporation ranges with spaces and (c)', () => {
52-
const input = '/* Copyright (c) 2023 - 2026 Ping Identity Corporation. All right reserved. */';
56+
const input = '/* Copyright (c) 2023 - 2024 Ping Identity Corporation. All right reserved. */';
5357
const actual = updateCopyrightYears(input, 2026);
5458
assert.equal(
5559
actual,
@@ -58,7 +62,7 @@ test('updates Ping Identity Corporation ranges with spaces and (c)', () => {
5862
});
5963

6064
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. */';
65+
const input = '/* Copyright (c) 2023 Ping Identity Corporation. All right reserved. */';
6266
const actual = updateCopyrightYears(input, 2026);
6367
assert.equal(
6468
actual,
@@ -80,3 +84,19 @@ test('does not flag non-header Ping copyright text', () => {
8084
const input = 'This document is Copyright Ping Identity Corporation.';
8185
assert.equal(hasInvalidPingCopyrightHeader(input), false);
8286
});
87+
88+
test('excludes test files from processing', () => {
89+
assert.equal(isExcluded('src/foo.test.ts'), true);
90+
assert.equal(isExcluded('src/foo.test.mjs'), true);
91+
assert.equal(isExcluded('src/foo.spec.js'), true);
92+
});
93+
94+
test('excludes dist and vendor paths from processing', () => {
95+
assert.equal(isExcluded('dist/foo.js'), true);
96+
assert.equal(isExcluded('vendor/lib.js'), true);
97+
});
98+
99+
test('does not exclude regular source files', () => {
100+
assert.equal(isExcluded('src/foo.ts'), false);
101+
assert.equal(isExcluded('packages/sdk/src/index.ts'), false);
102+
});

0 commit comments

Comments
 (0)