From b2e4ced15c1f856ae56605b2dfd7888c408a3a73 Mon Sep 17 00:00:00 2001 From: mattgodbolt-molty Date: Thu, 2 Jul 2026 12:57:55 -0500 Subject: [PATCH] Address Copilot review: anchor regex, normalise paths, don't stack on MIT files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Drop the /m flag from the copyright regex so the banner must be the first line (post-shebang), not merely present somewhere in the file head. - Normalise incoming paths to repo-relative POSIX before matching. lint-staged passes absolute (and on Windows, backslashed) paths, which never matched the include-dir prefixes — so the per-file invocation was silently a no-op. Now it actually enforces headers on staged files. - Three CE-authored files (lib/stack-usage-transformer.ts, test/stack-usage-transformer-test.ts, test/library-tests.ts) carry an MIT header rather than the repo-standard BSD-2; the backfill had stacked a BSD-2 banner on top, leaving two conflicting licenses. Revert those to their original single MIT header and exempt them from the check. Relicensing them to BSD-2 is a separate maintainer decision. Co-Authored-By: Claude Opus 4.8 (1M context) --- etc/scripts/check-license-headers.js | 19 +++++++++++++++++-- lib/stack-usage-transformer.ts | 24 ------------------------ test/library-tests.ts | 24 ------------------------ test/stack-usage-transformer-test.ts | 24 ------------------------ 4 files changed, 17 insertions(+), 74 deletions(-) diff --git a/etc/scripts/check-license-headers.js b/etc/scripts/check-license-headers.js index 3c39134a5..6f4c9dd2b 100644 --- a/etc/scripts/check-license-headers.js +++ b/etc/scripts/check-license-headers.js @@ -11,6 +11,7 @@ import {execSync} from 'node:child_process'; import fs from 'node:fs'; +import path from 'node:path'; // Directories/globs whose source files must carry the banner. const INCLUDE_DIRS = ['lib', 'static', 'shared', 'types', 'test', 'cypress']; @@ -27,16 +28,30 @@ const EXCLUDE_PATTERNS = [ /^static\/ansi-to-html\.ts$/, // MIT, Rob Burns /^lib\/node-graceful\.ts$/, // MIT, node-graceful /^shared\/rison\.ts$/, // Nanonid/rison port + // CE-authored files that pre-date this check and carry an MIT header rather than + // the repo-standard BSD-2. Exempt for now; relicensing them to BSD-2 is a separate + // call for a maintainer. + /^lib\/stack-usage-transformer\.ts$/, + /^test\/stack-usage-transformer-test\.ts$/, + /^test\/library-tests\.ts$/, ]; // A file "has an appropriate banner" if, ignoring an optional shebang, it opens // with a `// Copyright (c) ...` line and contains the BSD-2-Clause disclaimer. // The year and copyright holder are intentionally not constrained: the tree has // many holders (Compiler Explorer Authors, Arm Ltd, Microsoft, individuals, ...). -const COPYRIGHT_RE = /^\/\/ Copyright \([cC]\) .+/m; +// No /m flag: the copyright line must be the very first line (post-shebang), not +// merely present somewhere in the head. +const COPYRIGHT_RE = /^\/\/ Copyright \([cC]\) .+/; // A couple of older files quote AS IS with single quotes; accept either. const DISCLAIMER_RE = /THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ["']AS IS["']/; +// Normalise to a repo-relative POSIX path so matching works whether we're handed +// tracked paths from `git ls-files` or absolute/backslashed paths from lint-staged. +function toRepoRelative(file) { + return path.relative(process.cwd(), path.resolve(file)).split(path.sep).join('/'); +} + function isIncluded(file) { if (!INCLUDE_EXTENSIONS.some(ext => file.endsWith(ext))) return false; if (EXCLUDE_PATTERNS.some(re => re.test(file))) return false; @@ -67,7 +82,7 @@ function hasBanner(file) { } const args = process.argv.slice(2); -const candidates = (args.length > 0 ? args : listTrackedFiles()).filter(isIncluded); +const candidates = (args.length > 0 ? args : listTrackedFiles()).map(toRepoRelative).filter(isIncluded); const missing = candidates.filter(file => fs.existsSync(file) && !hasBanner(file)); if (missing.length > 0) { diff --git a/lib/stack-usage-transformer.ts b/lib/stack-usage-transformer.ts index 8975f4e3c..dfdecdfc4 100644 --- a/lib/stack-usage-transformer.ts +++ b/lib/stack-usage-transformer.ts @@ -1,27 +1,3 @@ -// Copyright (c) 2023, Compiler Explorer Authors -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - // Copyright (c) 2023, Compiler Explorer Authors // // Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/library-tests.ts b/test/library-tests.ts index 0c5fd7d83..fe9db376f 100644 --- a/test/library-tests.ts +++ b/test/library-tests.ts @@ -1,27 +1,3 @@ -// Copyright (c) 2024, Compiler Explorer Authors -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - // Copyright (c) 2024, Compiler Explorer Authors // // Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/stack-usage-transformer-test.ts b/test/stack-usage-transformer-test.ts index 4db27b006..94affe280 100644 --- a/test/stack-usage-transformer-test.ts +++ b/test/stack-usage-transformer-test.ts @@ -1,27 +1,3 @@ -// Copyright (c) 2023, Compiler Explorer Authors -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - // Copyright (c) 2023, Compiler Explorer Authors // // Permission is hereby granted, free of charge, to any person obtaining a copy