Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add copyright_checker tool and add the missing copyright of … #17285

Merged
merged 8 commits into from
Jan 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
lint
  • Loading branch information
attila-lin committed Jan 7, 2023
commit b7598343581b953d89588e4a367665dec86640f6
27 changes: 14 additions & 13 deletions tools/copyright_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@

import { getSources, ROOT_PATH } from "./util.js";

const buffer = new Uint8Array(1024);
const textDecoder = new TextDecoder();

async function readFirstPartOfFile(filePath) {
const file = await Deno.open(filePath, { read: true });
try {
const byteCount = await file.read(buffer);
return textDecoder.decode(buffer.slice(0, byteCount ?? 0));
} finally {
file.close();
}
}

async function checkCopyright() {
attila-lin marked this conversation as resolved.
Show resolved Hide resolved
const sourceFiles = await getSources(ROOT_PATH, [
// js and ts
Expand All @@ -27,21 +40,9 @@ async function checkCopyright() {
]);

let totalCount = 0;
let sourceFilesSet = new Set(sourceFiles);
const buffer = new Uint8Array(1024);
const textDecoder = new TextDecoder();
const sourceFilesSet = new Set(sourceFiles);

for (const file of sourceFilesSet) {
async function readFirstPartOfFile(filePath) {
const file = await Deno.open(filePath, { read: true });
try {
const byteCount = await file.read(buffer);
return textDecoder.decode(buffer.slice(0, byteCount ?? 0));
} finally {
file.close();
}
}

const ERROR_MSG = "Copyright header is missing: ";

const fileText = await readFirstPartOfFile(file);
Expand Down