From 19b888c2bd5c474c7ddded82e3e4dc680f056ef2 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 19 Jan 2024 11:18:31 +0800 Subject: [PATCH] feat(denolint): upgrade denolint crate (#762) --- .eslintignore | 1 + .prettierignore | 6 +++++- packages/bcrypt/__tests__/bcrypt.spec.ts | 2 +- packages/deno-lint/Cargo.toml | 6 +++--- packages/deno-lint/cli.ts | 2 +- packages/deno-lint/index.js | 14 ++++++++++++++ packages/deno-lint/src/lib.rs | 19 ++++++++++++------- packages/jsonwebtoken/index.js | 14 ++++++++++++++ 8 files changed, 51 insertions(+), 13 deletions(-) diff --git a/.eslintignore b/.eslintignore index d1dd98c5..e9822943 100644 --- a/.eslintignore +++ b/.eslintignore @@ -13,3 +13,4 @@ packages/*/*.wasi.cjs packages/*/wasi-worker.mjs packages/*/index.js packages/*/index.d.ts +packages/bcrypt/binding.js diff --git a/.prettierignore b/.prettierignore index 1002ac18..d338204c 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,6 +3,10 @@ node_modules lib .yarn yarn.lock -packages/*/*.wasi.js +packages/*/*.wasi.cjs packages/*/index.js +packages/*/browser.js +packages/*/wasi-worker* packages/*/index.d.ts +packages/*/binding.js +packages/*/binding.d.ts diff --git a/packages/bcrypt/__tests__/bcrypt.spec.ts b/packages/bcrypt/__tests__/bcrypt.spec.ts index c875d3be..4d5882f6 100644 --- a/packages/bcrypt/__tests__/bcrypt.spec.ts +++ b/packages/bcrypt/__tests__/bcrypt.spec.ts @@ -23,7 +23,7 @@ test('genSalt should return a string', async (t) => { t.is(typeof (await genSalt(10, '2b')), 'string') t.is(typeof (await genSalt(10, '2y')), 'string') t.is(typeof (await genSalt(10, '2x')), 'string') - await t.throwsAsync(async () => genSalt(10, 'invalid' as any)) + t.throws(() => genSalt(10, 'invalid' as any)) }) test('verifySync hashed password from bcrypt should be true', (t) => { diff --git a/packages/deno-lint/Cargo.toml b/packages/deno-lint/Cargo.toml index 15065c7a..337c7b1e 100644 --- a/packages/deno-lint/Cargo.toml +++ b/packages/deno-lint/Cargo.toml @@ -8,10 +8,10 @@ version = "0.1.0" crate-type = ["cdylib"] [dependencies] -annotate-snippets = { version = "0.9", features = ["color"] } +annotate-snippets = { version = "0.10" } anyhow = "1" -deno_ast = "=0.31.6" -deno_lint = "=0.52.2" +deno_ast = "=1.0.1" +deno_lint = "=0.53.0" env_logger = "0.10" global_alloc = { path = "../../crates/alloc" } globwalk = "0.9" diff --git a/packages/deno-lint/cli.ts b/packages/deno-lint/cli.ts index c9b23db4..4d5823f8 100644 --- a/packages/deno-lint/cli.ts +++ b/packages/deno-lint/cli.ts @@ -12,7 +12,7 @@ class LintCommand extends Command { private readonly checkOnly = Option.Boolean('--check-only', { required: false }) - async execute() { + execute() { const hasError = denolint(this.cwd ?? __dirname, this.configPath ?? '.denolint.json') return Promise.resolve(hasError && !this.checkOnly ? 1 : 0) } diff --git a/packages/deno-lint/index.js b/packages/deno-lint/index.js index 4e8e25f6..91e365ed 100644 --- a/packages/deno-lint/index.js +++ b/packages/deno-lint/index.js @@ -298,6 +298,20 @@ switch (platform) { } } break + case 's390x': + localFileExisted = existsSync( + join(__dirname, 'deno-lint.linux-s390x-gnu.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./deno-lint.linux-s390x-gnu.node') + } else { + nativeBinding = require('@node-rs/deno-lint-linux-s390x-gnu') + } + } catch (e) { + loadError = e + } + break default: throw new Error(`Unsupported architecture on Linux: ${arch}`) } diff --git a/packages/deno-lint/src/lib.rs b/packages/deno-lint/src/lib.rs index 701af911..8b20dd2d 100644 --- a/packages/deno-lint/src/lib.rs +++ b/packages/deno-lint/src/lib.rs @@ -11,6 +11,7 @@ use std::path::Path; use std::str; use deno_ast::MediaType; +use deno_lint::linter::LintFileOptions; use deno_lint::linter::LinterBuilder; use deno_lint::rules::{get_all_rules, get_recommended_rules}; use ignore::overrides::OverrideBuilder; @@ -56,7 +57,6 @@ fn lint( }, None => get_recommended_rules(), }) - .media_type(get_media_type(Path::new(file_name.as_str()))) .ignore_diagnostic_directive("eslint-disable-next-line") .build(); @@ -71,7 +71,11 @@ fn lint( }; let (s, file_diagnostics) = linter - .lint(file_name.clone(), source_string.to_owned()) + .lint_file(LintFileOptions { + media_type: get_media_type(Path::new(file_name.as_str())), + filename: file_name.clone(), + source_code: source_string.to_owned(), + }) .map_err(|e| { Error::new( Status::GenericFailure, @@ -171,17 +175,18 @@ fn denolint(__dirname: String, config_path: String) -> Result { let linter = LinterBuilder::default() .rules(rules.clone()) - .media_type(get_media_type(p)) .ignore_file_directive("eslint-disable") .ignore_diagnostic_directive("eslint-disable-next-line") .build(); let (s, file_diagnostics) = linter - .lint( - p.to_str() + .lint_file(LintFileOptions { + source_code: file_content, + filename: p + .to_str() .ok_or_else(|| Error::from_reason(format!("Convert path to string failed: {:?}", &p)))? .to_owned(), - file_content.clone(), - ) + media_type: get_media_type(p), + }) .map_err(|e| { Error::new( Status::GenericFailure, diff --git a/packages/jsonwebtoken/index.js b/packages/jsonwebtoken/index.js index 544fabb3..6cadf495 100644 --- a/packages/jsonwebtoken/index.js +++ b/packages/jsonwebtoken/index.js @@ -298,6 +298,20 @@ switch (platform) { } } break + case 's390x': + localFileExisted = existsSync( + join(__dirname, 'jsonwebtoken.linux-s390x-gnu.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./jsonwebtoken.linux-s390x-gnu.node') + } else { + nativeBinding = require('@node-rs/jsonwebtoken-linux-s390x-gnu') + } + } catch (e) { + loadError = e + } + break default: throw new Error(`Unsupported architecture on Linux: ${arch}`) }