refactor(archive,expect,io,log,toml,yaml): remove private and public access modifiers (#5077)

* replaced public and private access modifiers #5066

* fix: run `deno fmt`

* fix: apply suggestions

* fix

---------

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
Madhav Ganesan 2024-06-21 09:43:08 +05:30 committed by GitHub
parent 15ec8df047
commit ab458a38fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 141 additions and 101 deletions

View File

@ -67,12 +67,15 @@ const USTAR_MAGIC_HEADER = "ustar\u000000" as const;
*/
class FileReader implements Reader {
#file?: Deno.FsFile;
#filePath: string;
constructor(private filePath: string) {}
constructor(filePath: string) {
this.#filePath = filePath;
}
public async read(p: Uint8Array): Promise<number | null> {
async read(p: Uint8Array): Promise<number | null> {
if (!this.#file) {
this.#file = await Deno.open(this.filePath, { read: true });
this.#file = await Deno.open(this.#filePath, { read: true });
}
const res = await this.#file.read(p);
if (res === null) {

View File

@ -3,8 +3,8 @@
import { expect } from "./expect.ts";
class Duration {
public time: number;
public unit: "H" | "M" | "S";
time: number;
unit: "H" | "M" | "S";
constructor(time: number, unit: "H" | "M" | "S") {
this.time = time;

View File

@ -10,7 +10,7 @@ declare module "./_types.ts" {
}
class Author {
public name: string;
name: string;
constructor(name: string) {
this.name = name;
@ -18,8 +18,8 @@ class Author {
}
class Book {
public name: string;
public authors: Array<Author>;
name: string;
authors: Array<Author>;
constructor(name: string, authors: Array<Author>) {
this.name = name;

View File

@ -221,7 +221,7 @@ Deno.test("expect().toEqual() does not throw when a key with undfined value exis
Deno.test("expect().toEqual() align to jest test cases", () => {
function create() {
class Person {
constructor(public readonly name = "deno") {}
constructor(readonly name = "deno") {}
}
return new Person();
}

View File

@ -243,8 +243,8 @@ export function expect(value: unknown, customMessage?: string): Expected {
* import { expect } from "@std/expect";
*
* class Volume {
* public amount: number;
* public unit: "L" | "mL";
* amount: number;
* unit: "L" | "mL";
*
* constructor(amount: number, unit: "L" | "mL") {
* this.amount = amount;

View File

@ -3,7 +3,7 @@
import type { Reader } from "./types.ts";
export const MIN_READ_BUFFER_SIZE = 16;
export const bufsizes: number[] = [
export const bufsizes = [
0,
MIN_READ_BUFFER_SIZE,
23,
@ -18,11 +18,14 @@ export const bufsizes: number[] = [
export class BinaryReader implements Reader {
index = 0;
#bytes: Uint8Array;
constructor(private bytes: Uint8Array = new Uint8Array(0)) {}
constructor(bytes = new Uint8Array(0)) {
this.#bytes = bytes;
}
read(p: Uint8Array): Promise<number | null> {
p.set(this.bytes.subarray(this.index, p.byteLength));
p.set(this.#bytes.subarray(this.index, p.byteLength));
this.index += p.byteLength;
return Promise.resolve(p.byteLength);
}

View File

@ -15,8 +15,10 @@ const LF = "\n".charCodeAt(0);
*/
export class BufferFullError extends Error {
override name = "BufferFullError";
constructor(public partial: Uint8Array) {
partial: Uint8Array;
constructor(partial: Uint8Array) {
super("Buffer full");
this.partial = partial;
}
}
@ -50,8 +52,6 @@ export class BufReader implements Reader {
#r = 0; // buf read position.
#w = 0; // buf write position.
#eof = false;
// private lastByte: number;
// private lastCharSize: number;
/** return new BufReader unless r is BufReader */
static create(r: Reader, size: number = DEFAULT_BUF_SIZE): BufReader {

View File

@ -309,12 +309,18 @@ const testOutput = encoder.encode("0123456789abcdefghijklmnopqrstuvwxy");
// TestReader wraps a Uint8Array and returns reads of a specific length.
class TestReader implements Reader {
constructor(private data: Uint8Array, private stride: number) {}
#data: Uint8Array;
#stride: number;
constructor(data: Uint8Array, stride: number) {
this.#data = data;
this.#stride = stride;
}
read(buf: Uint8Array): Promise<number | null> {
let nread = this.stride;
if (nread > this.data.byteLength) {
nread = this.data.byteLength;
let nread = this.#stride;
if (nread > this.#data.byteLength) {
nread = this.#data.byteLength;
}
if (nread > buf.byteLength) {
nread = buf.byteLength;
@ -322,8 +328,8 @@ class TestReader implements Reader {
if (nread === 0) {
return Promise.resolve(null);
}
copy(this.data, buf as Uint8Array);
this.data = this.data.subarray(nread);
copy(this.#data, buf as Uint8Array);
this.#data = this.#data.subarray(nread);
return Promise.resolve(nread);
}
}

View File

@ -13,7 +13,13 @@ import type { Reader } from "./types.ts";
* @deprecated This will be removed in 1.0.0. Use the {@link https://developer.mozilla.org/en-US/docs/Web/API/Streams_API | Web Streams API} instead.
*/
export class LimitedReader implements Reader {
constructor(public reader: Reader, public limit: number) {}
reader: Reader;
limit: number;
constructor(reader: Reader, limit: number) {
this.reader = reader;
this.limit = limit;
}
async read(p: Uint8Array): Promise<number | null> {
if (this.limit <= 0) {

View File

@ -41,11 +41,13 @@ export class StringWriter implements Writer, WriterSync {
#chunks: Uint8Array[] = [];
#byteLength = 0;
#cache: string | undefined;
#base: string;
constructor(private base: string = "") {
constructor(base = "") {
const c = new TextEncoder().encode(base);
this.#chunks.push(c);
this.#byteLength += c.byteLength;
this.#base = base;
}
write(p: Uint8Array): Promise<number> {

View File

@ -2,7 +2,7 @@
import { BaseHandler } from "./base_handler.ts";
export class TestHandler extends BaseHandler {
public messages: string[] = [];
messages: string[] = [];
override log(msg: string) {
this.messages.push(msg);

View File

@ -5,15 +5,15 @@ import { type LevelName, LogLevels } from "./levels.ts";
import { BaseHandler } from "./base_handler.ts";
class TestHandler extends BaseHandler {
public messages: string[] = [];
public records: LogRecord[] = [];
messages: string[] = [];
records: LogRecord[] = [];
override handle(record: LogRecord) {
this.records.push(record);
super.handle(record);
}
public override log(str: string) {
override log(str: string) {
this.messages.push(str);
}
}

View File

@ -36,14 +36,18 @@ export class TOMLParseError extends Error {}
export class Scanner {
#whitespace = /[ \t]/;
#position = 0;
constructor(private source: string) {}
#source: string;
constructor(source: string) {
this.#source = source;
}
/**
* Get current character
* @param index - relative index from current position
*/
char(index = 0) {
return this.source[this.#position + index] ?? "";
return this.#source[this.#position + index] ?? "";
}
/**
@ -52,7 +56,7 @@ export class Scanner {
* @param end - end position relative from current position
*/
slice(start: number, end: number): string {
return this.source.slice(this.#position + start, this.#position + end);
return this.#source.slice(this.#position + start, this.#position + end);
}
/**
@ -105,7 +109,7 @@ export class Scanner {
* Position reached EOF or not
*/
eof() {
return this.position() >= this.source.length;
return this.position() >= this.#source.length;
}
/**

View File

@ -88,23 +88,23 @@ export interface DumperStateOptions {
}
export class DumperState extends State {
public indent: number;
public noArrayIndent: boolean;
public skipInvalid: boolean;
public flowLevel: number;
public sortKeys: boolean | ((a: Any, b: Any) => number);
public lineWidth: number;
public noRefs: boolean;
public noCompatMode: boolean;
public condenseFlow: boolean;
public implicitTypes: Type[];
public explicitTypes: Type[];
public tag: string | null = null;
public result = "";
public duplicates: Any[] = [];
public usedDuplicates: Any[] = []; // changed from null to []
public styleMap: ArrayObject<StyleVariant>;
public dump: Any;
indent: number;
noArrayIndent: boolean;
skipInvalid: boolean;
flowLevel: number;
sortKeys: boolean | ((a: Any, b: Any) => number);
lineWidth: number;
noRefs: boolean;
noCompatMode: boolean;
condenseFlow: boolean;
implicitTypes: Type[];
explicitTypes: Type[];
tag: string | null = null;
result = "";
duplicates: Any[] = [];
usedDuplicates: Any[] = []; // changed from null to []
styleMap: ArrayObject<StyleVariant>;
dump: Any;
constructor({
schema,

View File

@ -14,7 +14,7 @@ export class YAMLError extends Error {
this.name = this.constructor.name;
}
public override toString(_compact: boolean): string {
override toString(): string {
return `${this.name}: ${this.message} ${this.mark}`;
}
}

View File

@ -26,31 +26,32 @@ export interface LoaderStateOptions {
export type ResultType = any[] | Record<string, any> | string;
export class LoaderState extends State {
public documents: Any[] = [];
public length: number;
public lineIndent = 0;
public lineStart = 0;
public position = 0;
public line = 0;
public filename?: string;
public onWarning?: (...args: Any[]) => void;
public legacy: boolean;
public json: boolean;
public listener?: ((...args: Any[]) => void) | null;
public implicitTypes: Type[];
public typeMap: TypeMap;
input: string;
documents: Any[] = [];
length: number;
lineIndent = 0;
lineStart = 0;
position = 0;
line = 0;
filename?: string;
onWarning?: (...args: Any[]) => void;
legacy: boolean;
json: boolean;
listener?: ((...args: Any[]) => void) | null;
implicitTypes: Type[];
typeMap: TypeMap;
public version?: string | null;
public checkLineBreaks?: boolean;
public tagMap?: ArrayObject;
public anchorMap?: ArrayObject;
public tag?: string | null;
public anchor?: string | null;
public kind?: string | null;
public result: ResultType | null = "";
version?: string | null;
checkLineBreaks?: boolean;
tagMap?: ArrayObject;
anchorMap?: ArrayObject;
tag?: string | null;
anchor?: string | null;
kind?: string | null;
result: ResultType | null = "";
constructor(
public input: string,
input: string,
{
filename,
schema,
@ -61,6 +62,7 @@ export class LoaderState extends State {
}: LoaderStateOptions,
) {
super(schema);
this.input = input;
this.filename = filename;
this.onWarning = onWarning;
this.legacy = legacy;

View File

@ -6,15 +6,26 @@
import { repeat } from "./_utils.ts";
export class Mark {
name: string;
buffer: string;
position: number;
line: number;
column: number;
constructor(
public name: string,
public buffer: string,
public position: number,
public line: number,
public column: number,
) {}
name: string,
buffer: string,
position: number,
line: number,
column: number,
) {
this.name = name;
this.buffer = buffer;
this.position = position;
this.line = line;
this.column = column;
}
public getSnippet(indent = 4, maxLength = 75): string | null {
getSnippet(indent = 4, maxLength = 75): string | null {
if (!this.buffer) return null;
let head = "";
@ -56,7 +67,7 @@ export class Mark {
}^`;
}
public toString(compact?: boolean): string {
toString(compact?: boolean): string {
let snippet;
let where = "";

View File

@ -7,5 +7,8 @@ import type { SchemaDefinition } from "./schema.ts";
import { DEFAULT_SCHEMA } from "./schema/mod.ts";
export abstract class State {
constructor(public schema: SchemaDefinition = DEFAULT_SCHEMA) {}
schema: SchemaDefinition;
constructor(schema: SchemaDefinition = DEFAULT_SCHEMA) {
this.schema = schema;
}
}

View File

@ -55,15 +55,15 @@ function compileMap(...typesList: Type[][]): TypeMap {
}
export class Schema implements SchemaDefinition {
public static SCHEMA_DEFAULT?: Schema;
static SCHEMA_DEFAULT?: Schema;
public implicit: Type[];
public explicit: Type[];
public include: Schema[];
implicit: Type[];
explicit: Type[];
include: Schema[];
public compiledImplicit: Type[];
public compiledExplicit: Type[];
public compiledTypeMap: TypeMap;
compiledImplicit: Type[];
compiledExplicit: Type[];
compiledTypeMap: TypeMap;
constructor(definition: SchemaDefinition) {
this.explicit = definition.explicit || [];
@ -87,7 +87,7 @@ export class Schema implements SchemaDefinition {
}
/* Returns a new extended schema from current schema */
public extend(definition: SchemaDefinition): Schema {
extend(definition: SchemaDefinition): Schema {
return new Schema({
implicit: [
...new Set([...this.implicit, ...(definition?.implicit ?? [])]),
@ -99,7 +99,7 @@ export class Schema implements SchemaDefinition {
});
}
public static create() {}
static create() {}
}
export interface SchemaDefinition {

View File

@ -26,14 +26,14 @@ function checkTagFormat(tag: string): string {
}
export class Type {
public tag: string;
public kind: KindType | null = null;
public instanceOf: Any;
public predicate?: (data: Record<string, unknown>) => boolean;
public represent?: RepresentFn | ArrayObject<RepresentFn>;
public defaultStyle?: StyleVariant;
public styleAliases?: ArrayObject;
public loadKind?: KindType;
tag: string;
kind: KindType | null = null;
instanceOf: Any;
predicate?: (data: Record<string, unknown>) => boolean;
represent?: RepresentFn | ArrayObject<RepresentFn>;
defaultStyle?: StyleVariant;
styleAliases?: ArrayObject;
loadKind?: KindType;
constructor(tag: string, options?: TypeOptions) {
this.tag = checkTagFormat(tag);
@ -48,6 +48,6 @@ export class Type {
this.styleAliases = options.styleAliases;
}
}
public resolve: (data?: Any) => boolean = (): boolean => true;
public construct: (data?: Any) => Any = (data): Any => data;
resolve: (data?: Any) => boolean = (): boolean => true;
construct: (data?: Any) => Any = (data): Any => data;
}