@@ -585,7 +585,7 @@ declare_lint_rule! {
585
585
pub struct RestrictedImportsOptions {
586
586
/// A list of import paths that should trigger the rule.
587
587
#[ serde( skip_serializing_if = "FxHashMap::is_empty" ) ]
588
- paths : FxHashMap < Box < str > , CustomRestrictedImport > ,
588
+ paths : FxHashMap < Box < str > , Paths > ,
589
589
590
590
/// A list of gitignore-style patterns or regular expressions that should trigger the rule.
591
591
#[ serde( skip_serializing_if = "Option::is_none" ) ]
@@ -633,7 +633,7 @@ impl ImportRestrictionStatus {
633
633
) ]
634
634
#[ cfg_attr( feature = "schema" , derive( schemars:: JsonSchema ) ) ]
635
635
#[ serde( rename_all = "camelCase" , deny_unknown_fields, default ) ]
636
- pub struct CustomRestrictedImportOptions {
636
+ pub struct PathOptions {
637
637
/// The message to display when this module is imported.
638
638
#[ serde( skip_serializing_if = "str::is_empty" ) ]
639
639
message : Box < str > ,
@@ -647,7 +647,7 @@ pub struct CustomRestrictedImportOptions {
647
647
allow_import_names : Box < [ Box < str > ] > ,
648
648
}
649
649
650
- impl CustomRestrictedImportOptions {
650
+ impl PathOptions {
651
651
pub fn has_import_name_patterns ( & self ) -> bool {
652
652
!self . import_names . is_empty ( ) || !self . allow_import_names . is_empty ( )
653
653
}
@@ -703,27 +703,27 @@ impl CustomRestrictedImportOptions {
703
703
#[ derive( Clone , Debug , Deserialize , Eq , PartialEq , Serialize ) ]
704
704
#[ cfg_attr( feature = "schema" , derive( schemars:: JsonSchema ) ) ]
705
705
#[ serde( untagged) ]
706
- pub enum CustomRestrictedImport {
706
+ pub enum Paths {
707
707
/// The message to display when this module is imported.
708
708
Plain ( Box < str > ) ,
709
709
/// Additional options to configure the message and allowed/disallowed import names.
710
- WithOptions ( CustomRestrictedImportOptions ) ,
710
+ WithOptions ( PathOptions ) ,
711
711
}
712
712
713
- impl From < CustomRestrictedImport > for CustomRestrictedImportOptions {
714
- fn from ( options : CustomRestrictedImport ) -> Self {
715
- match options {
716
- CustomRestrictedImport :: Plain ( message) => Self {
713
+ impl From < Paths > for PathOptions {
714
+ fn from ( paths : Paths ) -> Self {
715
+ match paths {
716
+ Paths :: Plain ( message) => Self {
717
717
message,
718
718
import_names : [ ] . into ( ) ,
719
719
allow_import_names : [ ] . into ( ) ,
720
720
} ,
721
- CustomRestrictedImport :: WithOptions ( options ) => options ,
721
+ Paths :: WithOptions ( path_options ) => path_options ,
722
722
}
723
723
}
724
724
}
725
725
726
- impl Deserializable for CustomRestrictedImport {
726
+ impl Deserializable for Paths {
727
727
fn deserialize (
728
728
ctx : & mut impl DeserializationContext ,
729
729
value : & impl DeserializableValue ,
@@ -814,7 +814,7 @@ impl Deserializable for Patterns {
814
814
815
815
struct RestrictedImportVisitor < ' a > {
816
816
import_source : & ' a str ,
817
- restricted_import : CustomRestrictedImportOptions ,
817
+ path_options : PathOptions ,
818
818
results : Vec < RestrictedImportMessage > ,
819
819
}
820
820
@@ -1213,7 +1213,7 @@ impl RestrictedImportVisitor<'_> {
1213
1213
fn visit_imported_identifier ( & mut self , name_token : & SyntaxToken < JsLanguage > ) -> Option < ( ) > {
1214
1214
// TODO: inner_string_text removes quotes but does not e.g. decode escape sequences.
1215
1215
// If the imported name uses e.g. Unicode escape sequences, this may cause
1216
- // problems because restricted_import .(allow_)import_names contains decoded
1216
+ // problems because path_options .(allow_)import_names contains decoded
1217
1217
// strings, while inner_string_text(name_token) returns encoded strings.
1218
1218
self . visit_special_import_token ( name_token, inner_string_text ( name_token) . text ( ) )
1219
1219
}
@@ -1225,19 +1225,19 @@ impl RestrictedImportVisitor<'_> {
1225
1225
import_node : & SyntaxNode < JsLanguage > ,
1226
1226
name_or_alias : & str ,
1227
1227
) -> Option < ( ) > {
1228
- let status = self . restricted_import . is_import_allowed ( name_or_alias) ;
1228
+ let status = self . path_options . is_import_allowed ( name_or_alias) ;
1229
1229
if status. is_allowed ( ) {
1230
1230
return None ;
1231
1231
}
1232
1232
self . results . push ( RestrictedImportMessage {
1233
1233
location : import_node. text_trimmed_range ( ) ,
1234
- message : self . restricted_import . get_message_for_restriction (
1234
+ message : self . path_options . get_message_for_restriction (
1235
1235
self . import_source ,
1236
1236
name_or_alias,
1237
1237
status. reason ( ) ,
1238
1238
) ,
1239
1239
import_source : self . import_source . to_string ( ) ,
1240
- allowed_import_names : self . restricted_import . allow_import_names . clone ( ) ,
1240
+ allowed_import_names : self . path_options . allow_import_names . clone ( ) ,
1241
1241
} ) ;
1242
1242
Some ( ( ) )
1243
1243
}
@@ -1249,19 +1249,19 @@ impl RestrictedImportVisitor<'_> {
1249
1249
import_token : & SyntaxToken < JsLanguage > ,
1250
1250
name_or_alias : & str ,
1251
1251
) -> Option < ( ) > {
1252
- let status = self . restricted_import . is_import_allowed ( name_or_alias) ;
1252
+ let status = self . path_options . is_import_allowed ( name_or_alias) ;
1253
1253
if status. is_allowed ( ) {
1254
1254
return None ;
1255
1255
}
1256
1256
self . results . push ( RestrictedImportMessage {
1257
1257
location : import_token. text_trimmed_range ( ) ,
1258
- message : self . restricted_import . get_message_for_restriction (
1258
+ message : self . path_options . get_message_for_restriction (
1259
1259
self . import_source ,
1260
1260
name_or_alias,
1261
1261
status. reason ( ) ,
1262
1262
) ,
1263
1263
import_source : self . import_source . to_string ( ) ,
1264
- allowed_import_names : self . restricted_import . allow_import_names . clone ( ) ,
1264
+ allowed_import_names : self . path_options . allow_import_names . clone ( ) ,
1265
1265
} ) ;
1266
1266
Some ( ( ) )
1267
1267
}
@@ -1292,17 +1292,16 @@ impl Rule for NoRestrictedImports {
1292
1292
let import_source = import_source_text. text ( ) ;
1293
1293
let options = ctx. options ( ) ;
1294
1294
1295
- if let Some ( restricted_import_settings) = options. paths . get ( import_source) {
1296
- let restricted_import: CustomRestrictedImportOptions =
1297
- restricted_import_settings. clone ( ) . into ( ) ;
1295
+ if let Some ( paths) = options. paths . get ( import_source) {
1296
+ let path_options: PathOptions = paths. clone ( ) . into ( ) ;
1298
1297
1299
1298
match node {
1300
1299
AnyJsImportLike :: JsModuleSource ( module_source_node) => {
1301
- if !restricted_import . has_import_name_patterns ( ) {
1300
+ if !path_options . has_import_name_patterns ( ) {
1302
1301
// All imports disallowed, add diagnostic to the import source
1303
1302
vec ! [ RestrictedImportMessage {
1304
1303
location: module_name. text_trimmed_range( ) ,
1305
- message: restricted_import . get_message_for_restriction(
1304
+ message: path_options . get_message_for_restriction(
1306
1305
import_source,
1307
1306
"" ,
1308
1307
ImportRestrictionCause :: ImportSource ,
@@ -1314,7 +1313,7 @@ impl Rule for NoRestrictedImports {
1314
1313
// Check (and possibly report) each imported name individually
1315
1314
let mut visitor = RestrictedImportVisitor {
1316
1315
import_source,
1317
- restricted_import ,
1316
+ path_options ,
1318
1317
results : vec ! [ ] ,
1319
1318
} ;
1320
1319
visitor. visit_import ( module_source_node) ;
@@ -1326,11 +1325,11 @@ impl Rule for NoRestrictedImports {
1326
1325
// which exports are being used/whether this should be considered a
1327
1326
// namespace import, a side-effect import (the two of which may
1328
1327
// be difficult to distinguish) or a collection of named imports.
1329
- if !restricted_import . has_import_name_patterns ( ) {
1328
+ if !path_options . has_import_name_patterns ( ) {
1330
1329
// All imports disallowed, add diagnostic to the import source
1331
1330
vec ! [ RestrictedImportMessage {
1332
1331
location: module_name. text_trimmed_range( ) ,
1333
- message: restricted_import . get_message_for_restriction(
1332
+ message: path_options . get_message_for_restriction(
1334
1333
import_source,
1335
1334
"" ,
1336
1335
ImportRestrictionCause :: ImportSource ,
@@ -1342,23 +1341,23 @@ impl Rule for NoRestrictedImports {
1342
1341
// Check (and possibly report) each imported name individually
1343
1342
let mut visitor = RestrictedImportVisitor {
1344
1343
import_source,
1345
- restricted_import ,
1344
+ path_options ,
1346
1345
results : vec ! [ ] ,
1347
1346
} ;
1348
1347
visitor. visit_import_call ( import_call) ;
1349
1348
visitor. results
1350
1349
}
1351
1350
}
1352
1351
AnyJsImportLike :: JsCallExpression ( _expression) => {
1353
- let status = restricted_import
1352
+ let status = path_options
1354
1353
. is_import_allowed ( RestrictedImportVisitor :: DEFAULT_IMPORT_ALIAS ) ;
1355
1354
1356
1355
if status. is_forbidden ( ) {
1357
1356
// require() calls can only import the default import, so
1358
1357
// there are no individual import names to check or report on.
1359
1358
vec ! [ RestrictedImportMessage {
1360
1359
location: module_name. text_trimmed_range( ) ,
1361
- message: restricted_import . get_message_for_restriction(
1360
+ message: path_options . get_message_for_restriction(
1362
1361
import_source,
1363
1362
"" ,
1364
1363
ImportRestrictionCause :: ImportSource ,
0 commit comments