It seems this was implemented in past by #8352 and was reverted in #8411. I'm not sure what was buggy, but one difference with this PR is that the previous PR doesn't check whether the identifier is a global reference or not.
Addresses #8491.
Essentially, the fix was ensuring that we track the indentation of a
`StatementExpression` or `BreakStatement` when we apply a fix for this
lint rule, and to make sure we add these statements on a new line with
the proper indentation. I also made sure we're indenting the closing
case brackets correctly.
To do this, I added a `get_preceding_indent_str` fn to the `ast_utils`
that handles getting the preceding indentation of a `Span` in a
`source_text` &str. It returns an Option in case no indentation is
found, or if the statement is not the only one on a given line.
This new fn was useful when addressing this particular bug, but I figure
it might be useful for other fixer use cases, too. I added some
documentation for this fn for clarity.
Tried to add documentation and examples for as many of the remaining AST
methods as I could. There are still around 30 or so remaining in this
file, but this PR adds around 50 documentation comments.
I tried my best to check that each comment is correct, but I was
inferring from the source and usage, so it may not be 100% accurate.
Please take a quick look over the comments and see if it looks right.
Co-authored-by: camchenry <1514176+camchenry@users.noreply.github.com>
Related to #8790
For the configuration `"eqeqeq": ["warn", "alw", { "null": "ignore" }]`,
we should default `"alw"` to `"always"` and correctly handle the option
`{ "null": "ignore" }`.
The rounding logic between Rust and JavaScript differs, necessitating manual handling.
Furthermore, there is a potential risk of being eliminated from the test suite. Consequently, we must implement an approach that assigns to `x` to mitigate this risk.
Previously, #8634 visualized each spec result, but this was not enough.
If the implementation has been updated but the spec still fails, there
is no way to know if there is an improvement or not.
This time, finally, all progress is visualized! 🤩

e.g. here `arrow_function_expression` is mostly passing, except for
comment handling.
Welcome to the new testing area for oxlint CLI 🥳
There is still one test left to be snapshotted (for invalid options), but everything else works great.
I put some comments on code which I think are the key points of the PR
Just noticed that we can use a static list here. I think this has no downsides. To have better compression, we can actually count the characters, but I guess there won't be much difference normally.
To override the TS type of a struct field in ESTree AST, use `#[estree(ts_type = "Identifier")]` instead of `#[estree(type = "Identifier")]`.
This is clearer, and avoids using the keyword `type`, which makes the attributes simpler to parse.
To rename a type in ESTree AST, use `#[estree(rename = "Identifier")]` instead of `#[estree(type = "Identifier")]`.
This aligns with `serde`'s attribute, and avoids using the keyword `type`, which makes the attributes simpler to parse.
```js
var foo = (a) => {
if (!(a == null ? void 0 : a.b))
return
a.b(to);
};
foo(null)
```
was minified into
```js
var foo = (a) => {
if (a == null && a.b) return;
a.b(to);
};
foo(null);
```
which is incorrect (no error happens before and error happens after).
I found this while trying rolldown-vite with ecosystem-ci.
refs #8651
The special behavior of `typeof` is only for the identifier, so it should be safe to compress `typeof a.b === 'undefined'` (and other expressions) to `a.b === void 0`.