Skip to content

Commit

Permalink
fix(deno-lint): add tsx: true when path endsWith .tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Aug 31, 2020
1 parent 9a714a3 commit b1e5502
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/deno-lint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ napi = { version = "0.4" }
napi-derive = { version = "0.4" }
serde = "1"
serde_json = "1"
swc_ecmascript = { version = "=0.6.3", features = ["parser", "transforms", "utils", "visit"] }
termcolor = "1.1"

[target.'cfg(all(unix, not(target_env = "musl")))'.dependencies]
Expand Down
4 changes: 3 additions & 1 deletion packages/deno-lint/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

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

const enableAllRules = process.argv.includes('--all') || process.argv.includes('-a')
const { argv } = process

const enableAllRules = argv.includes('--all') || argv.includes('-a')

const hasError = binding.denolint(__dirname, enableAllRules)

Expand Down
8 changes: 8 additions & 0 deletions packages/deno-lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use deno_lint::swc_util::get_default_ts_config;
use ignore::types::TypesBuilder;
use ignore::WalkBuilder;
use napi::{CallContext, Error, JsBoolean, JsBuffer, JsObject, JsString, Module, Result, Status};
use swc_ecmascript::parser::Syntax;
use swc_ecmascript::parser::TsConfig;
use termcolor::Color::{Ansi256, Red};
use termcolor::{Ansi, ColorSpec, WriteColor};

Expand Down Expand Up @@ -224,6 +226,12 @@ fn lint_command(ctx: CallContext) -> Result<JsBoolean> {
if !p.is_dir() {
let file_content = fs::read_to_string(&p)
.map_err(|e| Error::from_reason(format!("Read file {:?} failed: {}", p, e)))?;

let mut ts_config = TsConfig::default();
ts_config.dynamic_import = true;
ts_config.decorators = true;
ts_config.tsx = p.ends_with(".tsx");
Syntax::Typescript(ts_config);
let mut linter = LinterBuilder::default()
.rules(if enable_all_rules {
get_all_rules()
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"suppressImplicitAnyIndexErrors": true,
"suppressExcessPropertyErrors": true,
"forceConsistentCasingInFileNames": true,
"target": "ES5",
"target": "ES2018",
"inlineSourceMap": true,
"esModuleInterop": true,
"stripInternal": true,
Expand Down

0 comments on commit b1e5502

Please sign in to comment.