Skip to content

Commit

Permalink
feat(denolint): upgrade denolint crate (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Jan 19, 2024
1 parent 5cf454d commit 19b888c
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 13 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ packages/*/*.wasi.cjs
packages/*/wasi-worker.mjs
packages/*/index.js
packages/*/index.d.ts
packages/bcrypt/binding.js
6 changes: 5 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion packages/bcrypt/__tests__/bcrypt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/deno-lint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion packages/deno-lint/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 14 additions & 0 deletions packages/deno-lint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
Expand Down
19 changes: 12 additions & 7 deletions packages/deno-lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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,
Expand Down Expand Up @@ -171,17 +175,18 @@ fn denolint(__dirname: String, config_path: String) -> Result<bool> {

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,
Expand Down
14 changes: 14 additions & 0 deletions packages/jsonwebtoken/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
Expand Down

0 comments on commit 19b888c

Please sign in to comment.