mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
chore: Ensure copyright line is the first in the file (#19608)
The copyright checker was allowing files with code above the copyright line in a few places, mainly as a result of IDEs ordering imports improperly. This makes the check more robust, and adds a whitelist of valid lines that may appear before the copyright line.
This commit is contained in:
parent
801b9ec62d
commit
fa935e553a
4 changed files with 32 additions and 16 deletions
|
@ -1,4 +1,3 @@
|
||||||
use super::MacroConfig;
|
|
||||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||||
use super::generator_state::GeneratorState;
|
use super::generator_state::GeneratorState;
|
||||||
use super::signature::Arg;
|
use super::signature::Arg;
|
||||||
|
@ -6,6 +5,7 @@ use super::signature::NumericArg;
|
||||||
use super::signature::ParsedSignature;
|
use super::signature::ParsedSignature;
|
||||||
use super::signature::RetVal;
|
use super::signature::RetVal;
|
||||||
use super::signature::Special;
|
use super::signature::Special;
|
||||||
|
use super::MacroConfig;
|
||||||
use super::V8MappingError;
|
use super::V8MappingError;
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use num_bigint::BigInt;
|
|
||||||
|
|
||||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||||
use super::buffer::JsBuffer;
|
use super::buffer::JsBuffer;
|
||||||
use super::transl8::FromV8;
|
use super::transl8::FromV8;
|
||||||
|
@ -7,6 +5,7 @@ use super::transl8::ToV8;
|
||||||
use crate::magic::transl8::impl_magic;
|
use crate::magic::transl8::impl_magic;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use crate::ToJsBuffer;
|
use crate::ToJsBuffer;
|
||||||
|
use num_bigint::BigInt;
|
||||||
|
|
||||||
/// An untagged enum type that can be any of number, string, bool, bigint, or
|
/// An untagged enum type that can be any of number, string, bool, bigint, or
|
||||||
/// buffer.
|
/// buffer.
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
/// Generate a unit test factory verified and backed by a glob.
|
/// Generate a unit test factory verified and backed by a glob.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|
|
@ -42,29 +42,47 @@ export async function checkCopyright() {
|
||||||
|
|
||||||
const errors = [];
|
const errors = [];
|
||||||
const sourceFilesSet = new Set(sourceFiles);
|
const sourceFilesSet = new Set(sourceFiles);
|
||||||
|
const ERROR_MSG = "Copyright header is missing: ";
|
||||||
|
|
||||||
|
// Acceptable content before the copyright line
|
||||||
|
const ACCEPTABLE_LINES =
|
||||||
|
/^(\/\/ deno-lint-.*|\/\/ Copyright.*|\/\/ Ported.*|\s*|#!\/.*)\n/;
|
||||||
|
const COPYRIGHT_LINE =
|
||||||
|
"Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.";
|
||||||
|
const TOML_COPYRIGHT_LINE = "# " + COPYRIGHT_LINE;
|
||||||
|
const C_STYLE_COPYRIGHT_LINE = "// " + COPYRIGHT_LINE;
|
||||||
|
|
||||||
for (const file of sourceFilesSet) {
|
for (const file of sourceFilesSet) {
|
||||||
const ERROR_MSG = "Copyright header is missing: ";
|
|
||||||
|
|
||||||
const fileText = await readFirstPartOfFile(file);
|
const fileText = await readFirstPartOfFile(file);
|
||||||
if (file.endsWith("Cargo.toml")) {
|
if (file.endsWith("Cargo.toml")) {
|
||||||
if (
|
if (
|
||||||
!fileText.startsWith(
|
!fileText.startsWith(TOML_COPYRIGHT_LINE)
|
||||||
"# Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.",
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
errors.push(ERROR_MSG + file);
|
errors.push(ERROR_MSG + file);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// use .includes(...) because the first line might be a shebang
|
|
||||||
if (
|
if (
|
||||||
!fileText.includes(
|
!fileText.startsWith(C_STYLE_COPYRIGHT_LINE)
|
||||||
"// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.",
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
errors.push(ERROR_MSG + file);
|
let trimmedText = fileText;
|
||||||
|
// Attempt to trim accceptable lines
|
||||||
|
while (
|
||||||
|
ACCEPTABLE_LINES.test(trimmedText) &&
|
||||||
|
!trimmedText.startsWith(C_STYLE_COPYRIGHT_LINE)
|
||||||
|
) {
|
||||||
|
trimmedText = trimmedText.split("\n").slice(1).join("\n");
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!trimmedText.startsWith(C_STYLE_COPYRIGHT_LINE)
|
||||||
|
) {
|
||||||
|
errors.push(
|
||||||
|
`${ERROR_MSG}${file} (incorrect line is '${
|
||||||
|
trimmedText.split("\n", 1)
|
||||||
|
}')`,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue