Skip to content

linter: "multi-or-nest", "consistent" conflicts #18566

@Mister-Hope

Description

@Mister-Hope

What version of Oxlint are you using?

latest

What command did you run?

oxlint

What does your .oxlintrc.json config file look like?

{
  // ...
  "rules": {
        "curly": ["warn", "multi-or-nest", "consistent"],
  }
} 

What happened?

A nested if/else if with:

  • if multiline
  • else if single line

will never pass curly rule.

  while (state.pos < max) {
    if (dividerPosition) {
      if (
        state.src.charCodeAt(state.pos) === 125 /* } */ &&
        state.src.charCodeAt(state.pos - 1) !== 92 /* \ */
      ) {
        closePos = state.pos;
        break;
      }
    } else if (
      state.src.charCodeAt(state.pos) === 58 /* : */ &&
      state.src.charCodeAt(state.pos - 1) !== 92 /* \ */
    ) {
      dividerPosition = state.pos;
    }

    state.pos++;
  }
Image

multi-or-nest will suggest the else if removing the braces.

  while (state.pos < max) {
    if (dividerPosition) {
      if (
        state.src.charCodeAt(state.pos) === 125 /* } */ &&
        state.src.charCodeAt(state.pos - 1) !== 92 /* \ */
      ) {
        closePos = state.pos;
        break;
      }
    } else if (
      state.src.charCodeAt(state.pos) === 58 /* : */ &&
      state.src.charCodeAt(state.pos - 1) !== 92 /* \ */
    ) 
      dividerPosition = state.pos;


    state.pos++;
  }

The consistent will suggest adding the braces.

Image

In short, case 1 is a false positive which curly rule should recognize the brance is necessary and not try to auto fix by removing braces.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions