Skip to content

Commit b1e5502

Browse files
committed
fix(deno-lint): add tsx: true when path endsWith .tsx
1 parent 9a714a3 commit b1e5502

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

packages/deno-lint/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ napi = { version = "0.4" }
1414
napi-derive = { version = "0.4" }
1515
serde = "1"
1616
serde_json = "1"
17+
swc_ecmascript = { version = "=0.6.3", features = ["parser", "transforms", "utils", "visit"] }
1718
termcolor = "1.1"
1819

1920
[target.'cfg(all(unix, not(target_env = "musl")))'.dependencies]

packages/deno-lint/bin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
const { binding } = require('@node-rs/deno-lint')
44

5-
const enableAllRules = process.argv.includes('--all') || process.argv.includes('-a')
5+
const { argv } = process
6+
7+
const enableAllRules = argv.includes('--all') || argv.includes('-a')
68

79
const hasError = binding.denolint(__dirname, enableAllRules)
810

packages/deno-lint/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use deno_lint::swc_util::get_default_ts_config;
1616
use ignore::types::TypesBuilder;
1717
use ignore::WalkBuilder;
1818
use napi::{CallContext, Error, JsBoolean, JsBuffer, JsObject, JsString, Module, Result, Status};
19+
use swc_ecmascript::parser::Syntax;
20+
use swc_ecmascript::parser::TsConfig;
1921
use termcolor::Color::{Ansi256, Red};
2022
use termcolor::{Ansi, ColorSpec, WriteColor};
2123

@@ -224,6 +226,12 @@ fn lint_command(ctx: CallContext) -> Result<JsBoolean> {
224226
if !p.is_dir() {
225227
let file_content = fs::read_to_string(&p)
226228
.map_err(|e| Error::from_reason(format!("Read file {:?} failed: {}", p, e)))?;
229+
230+
let mut ts_config = TsConfig::default();
231+
ts_config.dynamic_import = true;
232+
ts_config.decorators = true;
233+
ts_config.tsx = p.ends_with(".tsx");
234+
Syntax::Typescript(ts_config);
227235
let mut linter = LinterBuilder::default()
228236
.rules(if enable_all_rules {
229237
get_all_rules()

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"suppressImplicitAnyIndexErrors": true,
2020
"suppressExcessPropertyErrors": true,
2121
"forceConsistentCasingInFileNames": true,
22-
"target": "ES5",
22+
"target": "ES2018",
2323
"inlineSourceMap": true,
2424
"esModuleInterop": true,
2525
"stripInternal": true,

0 commit comments

Comments
 (0)