Note: This uses a regex to replace multiple instances of whitespace with
` .`. May not be the most performant, so if there's a simple alternative
I can change to that instead.
cc @camc314, I know this was assigned to you but I just wanted to throw
something quick together while I had a minute. Feel free to use this, or
decline it and write your own.
Fixes#7794.
---------
Co-authored-by: Cameron Clark <cameron.clark@hey.com>
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
I added the test cases from
[eslint-plugin-react/jsx-uses-vars](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/tests/lib/rules/jsx-uses-vars.js)
to a `react.rs` file in the `no_unused_vars` tests module.
After adding the new tests, they immediately passed without any source
code changes required. It would seem that the linter already supported
this rule, but now there will be tests to support it.
---------
Co-authored-by: Cameron <cameron.clark@hey.com>
Although this rule is recommended by the React team,
it does not report incorrect or wrong code for the `correctness` category.
When turned on by default, I find false positive warnings confusing,
I cannot tell whether my code is wrong or the rule implementation is
wrong - see examples in the affine repo.
```
x eslint-plugin-react-hooks(rules-of-hooks): React Hook "use" cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function.
,-[packages/backend/server/src/config/affine.self.ts:80:1]
79 | /* Captcha Plugin Default Config */
80 | ,-> AFFiNE.use('captcha', {
81 | | turnstile: {},
82 | | challenge: {
83 | | bits: 20,
84 | | },
85 | `-> });
86 |
`----
```
Fix#7254
Changed all "raw" properties of literal types (if they have this property) to `Option<Atom>`.
---------
Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>