swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.23k stars 1.23k forks source link

[ecma_lints] Report level should be decided by users, not rule it self #3881

Open g-plane opened 2 years ago

g-plane commented 2 years ago

Describe the bug

The ecma linter has a rule no-use-before-define, but its report level is decided by the rule itself, which will override users' config:

https://github.com/swc-project/swc/blob/main/crates/swc_ecma_lints/src/rules/no_use_before_define.rs#L115-L119

As a configurable linter rule or even a linter tool, reporting a problem as an error or a warning should be decided and controlled by users, not the rule itself. If we want this rule to report errors only, we should make this rule unconfigurable.

Input code

No response

Config

{
  "lints": {
    "no-use-before-define": ["warning"]
  }
}

Playground link

No response

Expected behavior

If we use the config above, that rule should report problems as warnings.

Actual behavior

If we use the config above, that rule will report problems as errors, which is unexpected for users. Because users are confused: Why it report me errors although I set "warning" in configuration? Is my configuration wrong?

Version

1.2.149

Additional context

No response

magic-akari commented 2 years ago

Is it possible for swc to emit warning reports now?

kdy1 commented 2 years ago

It's stored at the handler

https://github.com/swc-project/swc/blob/43744c9eeda386058efda800e212faa994ea5e58/crates/swc_error_reporters/src/handler.rs#L90-L118

but it's dropped without emitting to stderr, because it's a function designed for general usecases. Maybe we can add an option to emit them to stderr or return the printed diagnostic even in case of success