1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-22 06:09:25 -05:00

make std deno-lint clean (#6240)

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
Ryan Dahl 2020-06-12 09:19:29 -04:00 committed by GitHub
parent ca1c2ee822
commit d0970daacd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 70 additions and 30 deletions

View file

@ -31,6 +31,19 @@ fn std_tests() {
assert!(status.success()); assert!(status.success());
} }
#[test]
fn std_lint() {
let status = util::deno_cmd()
.arg("lint")
.arg("--unstable")
.arg(util::root_path().join("std"))
.spawn()
.unwrap()
.wait()
.unwrap();
assert!(status.success());
}
#[test] #[test]
fn x_deno_warning() { fn x_deno_warning() {
let g = util::http_server(); let g = util::http_server();

View file

@ -1417,7 +1417,7 @@ function readAlias(state: LoaderState): boolean {
const alias = state.input.slice(_position, state.position); const alias = state.input.slice(_position, state.position);
if ( if (
typeof state.anchorMap !== "undefined" && typeof state.anchorMap !== "undefined" &&
!state.anchorMap.hasOwnProperty(alias) !Object.prototype.hasOwnProperty.call(state.anchorMap, alias)
) { ) {
return throwError(state, `unidentified alias "${alias}"`); return throwError(state, `unidentified alias "${alias}"`);
} }

View file

@ -3,7 +3,7 @@
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Any = any; export type Any = any;
export function isNothing(subject: unknown): subject is never { export function isNothing(subject: unknown): subject is never {

View file

@ -221,7 +221,7 @@ class Printf {
flags.width += val; flags.width += val;
} // switch c } // switch c
break; break;
case State.PRECISION: case State.PRECISION: {
if (c === "*") { if (c === "*") {
this.handleWidthOrPrecisionRef(WorP.PRECISION); this.handleWidthOrPrecisionRef(WorP.PRECISION);
break; break;
@ -236,6 +236,7 @@ class Printf {
flags.precision *= 10; flags.precision *= 10;
flags.precision += val; flags.precision += val;
break; break;
}
default: default:
throw new Error("can't be here. bug."); throw new Error("can't be here. bug.");
} // switch state } // switch state
@ -627,8 +628,7 @@ class Printf {
switch (typeof val) { switch (typeof val) {
case "number": case "number":
return this.fmtNumber(val as number, 16, upper); return this.fmtNumber(val as number, 16, upper);
break; case "string": {
case "string":
const sharp = this.flags.sharp && val.length !== 0; const sharp = this.flags.sharp && val.length !== 0;
let hex = sharp ? "0x" : ""; let hex = sharp ? "0x" : "";
const prec = this.flags.precision; const prec = this.flags.precision;
@ -647,7 +647,7 @@ class Printf {
hex = hex.toUpperCase(); hex = hex.toUpperCase();
} }
return this.pad(hex); return this.pad(hex);
break; }
default: default:
throw new Error( throw new Error(
"currently only number and string are implemented for hex" "currently only number and string are implemented for hex"

View file

@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
/* eslint-disable @typescript-eslint/no-explicit-any */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
type Replacer = (key: string, value: any) => any; type Replacer = (key: string, value: any) => any;
export interface WriteJsonOptions { export interface WriteJsonOptions {
@ -10,6 +10,7 @@ export interface WriteJsonOptions {
/* Writes an object to a JSON file. */ /* Writes an object to a JSON file. */
export async function writeJson( export async function writeJson(
filePath: string, filePath: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
object: any, object: any,
options: WriteJsonOptions = {} options: WriteJsonOptions = {}
): Promise<void> { ): Promise<void> {
@ -32,6 +33,7 @@ export async function writeJson(
/* Writes an object to a JSON file. */ /* Writes an object to a JSON file. */
export function writeJsonSync( export function writeJsonSync(
filePath: string, filePath: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
object: any, object: any,
options: WriteJsonOptions = {} options: WriteJsonOptions = {}
): void { ): void {

View file

@ -235,13 +235,14 @@ export class Md5 {
switch (format) { switch (format) {
case "hex": case "hex":
return hex.encodeToString(new Uint8Array(hash)); return hex.encodeToString(new Uint8Array(hash));
case "base64": case "base64": {
const data = new Uint8Array(hash); const data = new Uint8Array(hash);
let dataString = ""; let dataString = "";
for (let i = 0; i < data.length; ++i) { for (let i = 0; i < data.length; ++i) {
dataString += String.fromCharCode(data[i]); dataString += String.fromCharCode(data[i]);
} }
return window.btoa(dataString); return window.btoa(dataString);
}
default: default:
throw new Error("md5: invalid format"); throw new Error("md5: invalid format");
} }

View file

@ -135,7 +135,9 @@ async function serveDir(
let fileInfo = null; let fileInfo = null;
try { try {
fileInfo = await stat(filePath); fileInfo = await stat(filePath);
} catch (e) {} } catch (e) {
// Pass
}
listEntry.push({ listEntry.push({
mode: modeToString(entry.isDirectory, fileInfo?.mode ?? null), mode: modeToString(entry.isDirectory, fileInfo?.mode ?? null),
size: entry.isFile ? fileLenToString(fileInfo?.size ?? 0) : "", size: entry.isFile ? fileLenToString(fileInfo?.size ?? 0) : "",

View file

@ -90,7 +90,9 @@ export class ServerRequest {
try { try {
// Eagerly close on error. // Eagerly close on error.
this.conn.close(); this.conn.close();
} catch {} } catch {
// Pass
}
err = e; err = e;
} }
// Signal that this request has been processed and the next pipelined // Signal that this request has been processed and the next pipelined
@ -108,7 +110,9 @@ export class ServerRequest {
// Consume unread body // Consume unread body
const body = this.body; const body = this.body;
const buf = new Uint8Array(1024); const buf = new Uint8Array(1024);
while ((await body.read(buf)) !== null) {} while ((await body.read(buf)) !== null) {
// Pass
}
this.finalized = true; this.finalized = true;
} }
} }

View file

@ -9,7 +9,9 @@ try {
// Need to initialize it here // Need to initialize it here
// otherwise it will be already initialized on Deno.test // otherwise it will be already initialized on Deno.test
logger = getLogger(); logger = getLogger();
} catch {} } catch {
// Pass
}
test("logger is initialized", function (): void { test("logger is initialized", function (): void {
assert(logger instanceof Logger); assert(logger instanceof Logger);

View file

@ -21,8 +21,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
/* eslint-disable @typescript-eslint/no-explicit-any */
const { test } = Deno; const { test } = Deno;
import { assert, assertStrictEquals } from "../../testing/asserts.ts"; import { assert, assertStrictEquals } from "../../testing/asserts.ts";
import { callbackify } from "./_util_callbackify.ts"; import { callbackify } from "./_util_callbackify.ts";
@ -107,8 +105,10 @@ test("callbackify passes the resolution value as the second argument to the call
}); });
}); });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function thenableFn(): PromiseLike<any> { function thenableFn(): PromiseLike<any> {
return { return {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
then(onfulfilled): PromiseLike<any> { then(onfulfilled): PromiseLike<any> {
assert(onfulfilled); assert(onfulfilled);
onfulfilled(value); onfulfilled(value);
@ -146,7 +146,9 @@ test("callbackify passes the rejection value as the first argument to the callba
if (err instanceof Error) { if (err instanceof Error) {
if ("reason" in err) { if ("reason" in err) {
assert(!value); assert(!value);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assertStrictEquals((err as any).code, "ERR_FALSY_VALUE_REJECTION"); assertStrictEquals((err as any).code, "ERR_FALSY_VALUE_REJECTION");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assertStrictEquals((err as any).reason, value); assertStrictEquals((err as any).reason, value);
} else { } else {
assertStrictEquals(String(value).endsWith(err.message), true); assertStrictEquals(String(value).endsWith(err.message), true);
@ -177,7 +179,9 @@ test("callbackify passes the rejection value as the first argument to the callba
if (err instanceof Error) { if (err instanceof Error) {
if ("reason" in err) { if ("reason" in err) {
assert(!value); assert(!value);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assertStrictEquals((err as any).code, "ERR_FALSY_VALUE_REJECTION"); assertStrictEquals((err as any).code, "ERR_FALSY_VALUE_REJECTION");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assertStrictEquals((err as any).reason, value); assertStrictEquals((err as any).reason, value);
} else { } else {
assertStrictEquals(String(value).endsWith(err.message), true); assertStrictEquals(String(value).endsWith(err.message), true);
@ -206,7 +210,9 @@ test("callbackify passes the rejection value as the first argument to the callba
if (err instanceof Error) { if (err instanceof Error) {
if ("reason" in err) { if ("reason" in err) {
assert(!value); assert(!value);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assertStrictEquals((err as any).code, "ERR_FALSY_VALUE_REJECTION"); assertStrictEquals((err as any).code, "ERR_FALSY_VALUE_REJECTION");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assertStrictEquals((err as any).reason, value); assertStrictEquals((err as any).reason, value);
} else { } else {
assertStrictEquals(String(value).endsWith(err.message), true); assertStrictEquals(String(value).endsWith(err.message), true);
@ -322,10 +328,12 @@ test("callbackify preserves the `this` binding", async () => {
test("callbackify throws with non-function inputs", () => { test("callbackify throws with non-function inputs", () => {
["foo", null, undefined, false, 0, {}, Symbol(), []].forEach((value) => { ["foo", null, undefined, false, 0, {}, Symbol(), []].forEach((value) => {
try { try {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
callbackify(value as any); callbackify(value as any);
throw Error("We should never reach this error"); throw Error("We should never reach this error");
} catch (err) { } catch (err) {
assert(err instanceof TypeError); assert(err instanceof TypeError);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assertStrictEquals((err as any).code, "ERR_INVALID_ARG_TYPE"); assertStrictEquals((err as any).code, "ERR_INVALID_ARG_TYPE");
assertStrictEquals(err.name, "TypeError"); assertStrictEquals(err.name, "TypeError");
assertStrictEquals( assertStrictEquals(
@ -342,6 +350,7 @@ test("callbackify returns a function that throws if the last argument is not a f
return 42; return 42;
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const cb = callbackify(asyncFn) as any; const cb = callbackify(asyncFn) as any;
const args: unknown[] = []; const args: unknown[] = [];
@ -353,6 +362,7 @@ test("callbackify returns a function that throws if the last argument is not a f
throw Error("We should never reach this error"); throw Error("We should never reach this error");
} catch (err) { } catch (err) {
assert(err instanceof TypeError); assert(err instanceof TypeError);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assertStrictEquals((err as any).code, "ERR_INVALID_ARG_TYPE"); assertStrictEquals((err as any).code, "ERR_INVALID_ARG_TYPE");
assertStrictEquals(err.name, "TypeError"); assertStrictEquals(err.name, "TypeError");
assertStrictEquals( assertStrictEquals(

View file

@ -69,7 +69,7 @@ export function promisify(original: Function): Function {
function fn(...args: unknown[]): Promise<unknown> { function fn(...args: unknown[]): Promise<unknown> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// @ts-ignore // @ts-ignore: 'this' implicitly has type 'any' because it does not have a type annotation
original.call(this, ...args, (err: Error, ...values: unknown[]) => { original.call(this, ...args, (err: Error, ...values: unknown[]) => {
if (err) { if (err) {
return reject(err); return reject(err);

View file

@ -16,10 +16,10 @@ export type MaybeDefined<T> = T | undefined;
export type MaybeEmpty<T> = T | null | undefined; export type MaybeEmpty<T> = T | null | undefined;
export function intoCallbackAPI<T>( export function intoCallbackAPI<T>(
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
func: (...args: any[]) => Promise<T>, func: (...args: any[]) => Promise<T>,
cb: MaybeEmpty<(err: MaybeNull<Error>, value: MaybeEmpty<T>) => void>, cb: MaybeEmpty<(err: MaybeNull<Error>, value: MaybeEmpty<T>) => void>,
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
...args: any[] ...args: any[]
): void { ): void {
func(...args) func(...args)
@ -28,11 +28,11 @@ export function intoCallbackAPI<T>(
} }
export function intoCallbackAPIWithIntercept<T1, T2>( export function intoCallbackAPIWithIntercept<T1, T2>(
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
func: (...args: any[]) => Promise<T1>, func: (...args: any[]) => Promise<T1>,
interceptor: (v: T1) => T2, interceptor: (v: T1) => T2,
cb: MaybeEmpty<(err: MaybeNull<Error>, value: MaybeEmpty<T2>) => void>, cb: MaybeEmpty<(err: MaybeNull<Error>, value: MaybeEmpty<T2>) => void>,
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
...args: any[] ...args: any[]
): void { ): void {
func(...args) func(...args)

View file

@ -226,7 +226,8 @@ export default class EventEmitter {
rawListener: Function; rawListener: Function;
context: EventEmitter; context: EventEmitter;
}, },
...args: any[] // eslint-disable-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
...args: any[]
): void { ): void {
this.context.removeListener(this.eventName, this.rawListener); this.context.removeListener(this.eventName, this.rawListener);
this.listener.apply(this.context, args); this.listener.apply(this.context, args);
@ -434,7 +435,6 @@ export function on(
const unconsumedEventValues: any[] = []; const unconsumedEventValues: any[] = [];
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
const unconsumedPromises: any[] = []; const unconsumedPromises: any[] = [];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let error: Error | null = null; let error: Error | null = null;
let finished = false; let finished = false;

View file

@ -659,7 +659,9 @@ function readPackage(requestPath: string): PackageInfo | null {
json = new TextDecoder().decode( json = new TextDecoder().decode(
Deno.readFileSync(path.toNamespacedPath(jsonPath)) Deno.readFileSync(path.toNamespacedPath(jsonPath))
); );
} catch {} } catch {
// pass
}
if (json === undefined) { if (json === undefined) {
packageJsonCache.set(jsonPath, null); packageJsonCache.set(jsonPath, null);
@ -839,7 +841,7 @@ function applyExports(basePath: string, expansion: string): string {
} }
if (typeof pkgExports === "object") { if (typeof pkgExports === "object") {
if (pkgExports.hasOwnProperty(mappingKey)) { if (Object.prototype.hasOwnProperty.call(pkgExports, mappingKey)) {
const mapping = pkgExports[mappingKey]; const mapping = pkgExports[mappingKey];
return resolveExportsTarget( return resolveExportsTarget(
pathToFileURL(basePath + "/"), pathToFileURL(basePath + "/"),
@ -910,7 +912,6 @@ function resolveExports(
return path.resolve(nmPath, request); return path.resolve(nmPath, request);
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function resolveExportsTarget( function resolveExportsTarget(
pkgPath: URL, pkgPath: URL,
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
@ -959,7 +960,7 @@ function resolveExportsTarget(
} }
} else if (typeof target === "object" && target !== null) { } else if (typeof target === "object" && target !== null) {
// removed experimentalConditionalExports // removed experimentalConditionalExports
if (target.hasOwnProperty("default")) { if (Object.prototype.hasOwnProperty.call(target, "default")) {
try { try {
return resolveExportsTarget( return resolveExportsTarget(
pkgPath, pkgPath,
@ -1012,7 +1013,7 @@ const CircularRequirePrototypeWarningProxy = new Proxy(
}, },
getOwnPropertyDescriptor(target, prop): PropertyDescriptor | undefined { getOwnPropertyDescriptor(target, prop): PropertyDescriptor | undefined {
if (target.hasOwnProperty(prop)) { if (Object.prototype.hasOwnProperty.call(target, prop)) {
return Object.getOwnPropertyDescriptor(target, prop); return Object.getOwnPropertyDescriptor(target, prop);
} }
emitCircularRequireWarning(prop); emitCircularRequireWarning(prop);
@ -1114,7 +1115,6 @@ interface RequireResolveFunction extends RequireResolve {
} }
interface RequireFunction extends Require { interface RequireFunction extends Require {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
resolve: RequireResolveFunction; resolve: RequireResolveFunction;
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
extensions: { [key: string]: (module: Module, filename: string) => any }; extensions: { [key: string]: (module: Module, filename: string) => any };

View file

@ -1,6 +1,6 @@
// Copyright the Browserify authors. MIT License. // Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/ // Ported from https://github.com/browserify/path-browserify/
/* eslint-disable @typescript-eslint/no-explicit-any */
// TODO(kt3k): fix any types in this file // TODO(kt3k): fix any types in this file
const { test } = Deno; const { test } = Deno;
@ -80,6 +80,7 @@ const unixSpecialCaseFormatTests = [
[{}, ""], [{}, ""],
]; ];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function checkParseFormat(path: any, paths: any): void { function checkParseFormat(path: any, paths: any): void {
paths.forEach(function (p: Array<Record<string, unknown>>) { paths.forEach(function (p: Array<Record<string, unknown>>) {
const element = p[0]; const element = p[0];
@ -96,6 +97,7 @@ function checkParseFormat(path: any, paths: any): void {
}); });
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function checkSpecialCaseParseFormat(path: any, testCases: any): void { function checkSpecialCaseParseFormat(path: any, testCases: any): void {
testCases.forEach(function (testCase: Array<Record<string, unknown>>) { testCases.forEach(function (testCase: Array<Record<string, unknown>>) {
const element = testCase[0]; const element = testCase[0];
@ -107,6 +109,7 @@ function checkSpecialCaseParseFormat(path: any, testCases: any): void {
}); });
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function checkFormat(path: any, testCases: unknown[][]): void { function checkFormat(path: any, testCases: unknown[][]): void {
testCases.forEach(function (testCase) { testCases.forEach(function (testCase) {
assertEquals(path.format(testCase[0]), testCase[1]); assertEquals(path.format(testCase[0]), testCase[1]);

View file

@ -114,7 +114,9 @@ export class TextProtoReader {
// example: "Audio Mode" => invalid due to space in the key // example: "Audio Mode" => invalid due to space in the key
try { try {
m.append(key, value); m.append(key, value);
} catch {} } catch {
// Pass
}
} }
} }

View file

@ -262,7 +262,7 @@ class WebSocketImpl implements WebSocket {
payloadsLength = 0; payloadsLength = 0;
} }
break; break;
case OpCode.Close: case OpCode.Close: {
// [0x12, 0x34] -> 0x1234 // [0x12, 0x34] -> 0x1234
const code = (frame.payload[0] << 8) | frame.payload[1]; const code = (frame.payload[0] << 8) | frame.payload[1];
const reason = decode( const reason = decode(
@ -271,6 +271,7 @@ class WebSocketImpl implements WebSocket {
await this.close(code, reason); await this.close(code, reason);
yield { code, reason }; yield { code, reason };
return; return;
}
case OpCode.Ping: case OpCode.Ping:
await this.enqueue({ await this.enqueue({
opcode: OpCode.Pong, opcode: OpCode.Pong,