@@ -7,8 +7,10 @@ extern crate napi_derive;
7
7
use std:: env;
8
8
use std:: fs;
9
9
use std:: path;
10
+ use std:: path:: Path ;
10
11
use std:: str;
11
12
13
+ use deno_ast:: MediaType ;
12
14
use deno_lint:: linter:: LinterBuilder ;
13
15
use deno_lint:: rules:: { get_all_rules, get_recommended_rules} ;
14
16
use ignore:: types:: TypesBuilder ;
@@ -36,6 +38,17 @@ fn init(mut exports: JsObject) -> Result<()> {
36
38
Ok ( ( ) )
37
39
}
38
40
41
+ #[ inline( always) ]
42
+ fn get_media_type ( p : & Path ) -> MediaType {
43
+ match p. extension ( ) . and_then ( |e| e. to_str ( ) ) {
44
+ Some ( "tsx" ) => MediaType :: Tsx ,
45
+ Some ( "jsx" ) => MediaType :: Jsx ,
46
+ Some ( "js" ) | Some ( "mjs" ) => MediaType :: JavaScript ,
47
+ Some ( "ts" ) => MediaType :: TypeScript ,
48
+ _ => MediaType :: Tsx ,
49
+ }
50
+ }
51
+
39
52
#[ js_function( 3 ) ]
40
53
fn lint ( ctx : CallContext ) -> Result < JsObject > {
41
54
let file_name = ctx. get :: < JsString > ( 0 ) ?. into_utf8 ( ) ?;
@@ -47,6 +60,7 @@ fn lint(ctx: CallContext) -> Result<JsObject> {
47
60
} else {
48
61
get_recommended_rules ( )
49
62
} )
63
+ . media_type ( get_media_type ( Path :: new ( file_name. as_str ( ) ?) ) )
50
64
. ignore_diagnostic_directive ( "eslint-disable-next-line" )
51
65
. build ( ) ;
52
66
@@ -147,7 +161,7 @@ fn lint_command(ctx: CallContext) -> Result<JsBoolean> {
147
161
. types ( types)
148
162
. follow_links ( true ) ;
149
163
for i in cfg_ignore_files {
150
- dir_walker. add_custom_ignore_filename ( i) ;
164
+ dir_walker. add_ignore ( i) ;
151
165
}
152
166
for entry in dir_walker. build ( ) . filter_map ( |v| v. ok ( ) ) {
153
167
let p = entry. path ( ) ;
@@ -157,6 +171,7 @@ fn lint_command(ctx: CallContext) -> Result<JsBoolean> {
157
171
158
172
let linter = LinterBuilder :: default ( )
159
173
. rules ( rules. clone ( ) )
174
+ . media_type ( get_media_type ( p) )
160
175
. ignore_file_directive ( "eslint-disable" )
161
176
. ignore_diagnostic_directive ( "eslint-disable-next-line" )
162
177
. build ( ) ;
0 commit comments