oxc/crates
Guillaume Piedigrossi 3d5f0a1a0c
feat(linter/no_restricted_imports): add the no_restricted_imports rules (#7629)
add first test cases related to the 'paths' config

Note that the test cases and configuration format is not the same as the
original ESLint rule.
What is the oxc team strategy to develop such a rule? Is it ok to adapt
the config format ?

---

I started a discussion here :
https://github.com/oxc-project/oxc/discussions/7534#discussion-7574282
I copy/paste the content here. Maybe it is more relevant?

I am working to implement [this no-restricted-imports
rule](https://eslint.org/docs/latest/rules/no-restricted-imports).
I have several problems:

How to handle multiple format configuration in rust?
The eslint config can be: "fs", ["fs"], or {paths: [{name: "fs"}]}. But
Rust needs only one type. I don't know how to do this in rust.

Is it ok to cover only the {paths: [{name: "fs"}]} case ?

How to parse this config with the from_configuration method?
Here is what I have done:

```
   fn from_configuration(value: serde_json::Value) -> Self {
        let mut paths = Vec::new();
        let mut patterns = Vec::new();

        if let Some(obj) = value.as_object() {
            // Handle paths array
            if let Some(paths_value) = obj.get("paths") {
                if let Some(paths_array) = paths_value.as_array() {
                    for path_value in paths_array {
                        if let Ok(path) = serde_json::from_value(path_value.clone()) {
                            paths.push(path);
                        }
                    }
                }
            }

            // Handle patterns array
            if let Some(patterns_value) = obj.get("patterns") {
                if let Some(patterns_array) = patterns_value.as_array() {
                    for pattern_value in patterns_array {
                        if let Ok(pattern) = serde_json::from_value(pattern_value.clone()) {
                            patterns.push(pattern);
                        }
                    }
                }
            }
        }

        Self { paths, patterns }
    }
````
But here is my result:
```
[RestrictedPath { name: "foo", import_names: None, message: None }]

-------- rule config --------
{
  "paths": [
    {
      "name": "foo",
      "importNames": [
        "AllowedObject"
      ]
    }
  ]
}
```
Note the "None" values
2024-12-10 17:00:15 +08:00
..
oxc release(crates): v0.39.0 (#7643) 2024-12-04 19:43:22 +08:00
oxc_allocator release(crates): v0.39.0 (#7643) 2024-12-04 19:43:22 +08:00
oxc_ast feat(parser)!: stage 3 import source and import defer (#7706) 2024-12-06 16:15:52 +00:00
oxc_ast_macros release(crates): v0.39.0 (#7643) 2024-12-04 19:43:22 +08:00
oxc_cfg release(crates): v0.39.0 (#7643) 2024-12-04 19:43:22 +08:00
oxc_codegen fix(codegen): print delete 2e308 as delete (0, Infinity) (#7761) 2024-12-10 08:37:50 +00:00
oxc_data_structures release(crates): v0.39.0 (#7643) 2024-12-04 19:43:22 +08:00
oxc_diagnostics feat(napi/transform,napi/parser): return structured error object (#7724) 2024-12-08 14:11:56 +00:00
oxc_ecmascript release(crates): v0.39.0 (#7643) 2024-12-04 19:43:22 +08:00
oxc_estree release(crates): v0.39.0 (#7643) 2024-12-04 19:43:22 +08:00
oxc_isolated_declarations refactor(isolated_declarations): use NONE in AST builder calls (#7752) 2024-12-09 16:36:27 +00:00
oxc_language_server refactor(linter): add capability of adding semantic data to module record (#7561) 2024-12-01 08:14:43 +00:00
oxc_linter feat(linter/no_restricted_imports): add the no_restricted_imports rules (#7629) 2024-12-10 17:00:15 +08:00
oxc_macros feat(linter): allow lint rules with the same name (#7496) 2024-11-27 04:25:05 +00:00
oxc_mangler release(crates): v0.39.0 (#7643) 2024-12-04 19:43:22 +08:00
oxc_minifier refactor(ast)!: change 'raw' from &str to Option<Atom> (#7547) 2024-12-05 00:34:45 +00:00
oxc_napi feat(napi/transform,napi/parser): return structured error object (#7724) 2024-12-08 14:11:56 +00:00
oxc_parser feat(parser)!: stage 3 import source and import defer (#7706) 2024-12-06 16:15:52 +00:00
oxc_prettier refactor(ast)!: change 'raw' from &str to Option<Atom> (#7547) 2024-12-05 00:34:45 +00:00
oxc_regular_expression release(crates): v0.39.0 (#7643) 2024-12-04 19:43:22 +08:00
oxc_semantic feat(semantic): add SymbolTable::symbol_is_mutated method (#7755) 2024-12-10 02:28:23 +00:00
oxc_span release(crates): v0.39.0 (#7643) 2024-12-04 19:43:22 +08:00
oxc_syntax refactor(linter): remove unused serde features (#7738) 2024-12-09 09:16:32 +00:00
oxc_transformer feat(transformer/class-properties): support private_fields_as_properties assumption (#7717) 2024-12-10 02:28:31 +00:00
oxc_traverse refactor(traverse)!: remove TraverseCtx::is_static (#7760) 2024-12-10 02:28:30 +00:00
oxc_wasm refactor(linter): add capability of adding semantic data to module record (#7561) 2024-12-01 08:14:43 +00:00