mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-07-22 01:46:48 -04:00
Address Copilot review: anchor regex, normalise paths, don't stack on MIT files
- 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) <noreply@anthropic.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user