Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Flat config doesn't allow uppercase severities #17570

Closed
1 task done
mdjermanovic opened this issue Sep 16, 2023 · 6 comments · Fixed by #17619
Closed
1 task done

Bug: Flat config doesn't allow uppercase severities #17570

mdjermanovic opened this issue Sep 16, 2023 · 6 comments · Fixed by #17619
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly repro:yes

Comments

@mdjermanovic
Copy link
Member

Environment

Node version: v16.14.0
npm version: v8.3.1
Local ESLint version: v8.49.0
Global ESLint version:
Operating System: windows

What parser are you using?

Default (Espree)

What did you do?

Configuration
// eslint.config.js

module.exports = [{
    rules: {
        "no-undef": "Error"
    }
}];
foo();

What did you expect to happen?

I'd expect uppercase severities to work.

eslintrc allows severities such as "Error" or "eRRoR".

flat config validation aims to allow them too:

function assertIsRuleSeverity(ruleId, value) {
const severity = typeof value === "string"
? ruleSeverities.get(value.toLowerCase())
: ruleSeverities.get(value);
if (typeof severity === "undefined") {
throw new InvalidRuleSeverityError(ruleId, value);
}
}

What actually happened?

Oops! Something went wrong! :(

ESLint: 8.49.0

Configuration for rule "no-undef" is invalid. Expected severity of "off", 0, "warn", 1, "error", or 2.

You passed 'undefined'.

See https://eslint.org/docs/latest/use/configure/rules#using-configuration-files for configuring rules.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/stackblitz-starters-arttsx?file=eslint.config.js

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

Validation works as intended, but normalizeRuleOptions, which is used while merging, returns undefined, and then the subsequent validation on the next merge fails. That's why the error message at the end says You passed 'undefined'.

@mdjermanovic mdjermanovic added bug ESLint is working incorrectly repro:needed labels Sep 16, 2023
@mdjermanovic mdjermanovic changed the title Bug: (fill in) Bug: Flat config doesn't allow uppercase severities Sep 16, 2023
@Rec0iL99
Copy link
Member

Can reproduce 👍.

@fasttime
Copy link
Member

The constructor option reportUnusedDisableDirectives also handles string values in a case-sensitive manner, which seems a bit inconsistent with the intent to allow uppercase severities for rules.

const { FlatESLint } = require('eslint/use-at-your-own-risk');

const eslint = new FlatESLint({
    reportUnusedDisableDirectives: 'Error' // throws ESLintInvalidOptionsError
});

@fasttime
Copy link
Member

There is also a reportUnusedDisableDirectives severity setting in flat config. Personally, I think that a consistent handling of severity strings (either case-sensitive or case-insensitive everywhere) would be the least surprising behavior.

@nzakas
Copy link
Member

nzakas commented Sep 18, 2023

eslintrc allows severities such as "Error" or "eRRoR".

I intentionally did not want to support these in flat config. I was trying to be more strict where possible to clean up some of the weirdness in eslintrc. So, this part isn't a bug, but the "undefined" in the error message definitely is.

My preference is to keep the severities in all places as case-sensitive.

@nzakas
Copy link
Member

nzakas commented Oct 3, 2023

@mdjermanovic are you okay with closing this?

@mdjermanovic
Copy link
Member Author

I'd like to fix flat-config-schema as in some places it treats rule severities as case-insensitive while in other places as case-sensitive, and that results in the confusing "undefined" in the error message.

Looks like the consensus is that rule severities should be case-sensitive. I'm working on this now.

@mdjermanovic mdjermanovic added the accepted There is consensus among the team that this change meets the criteria for inclusion label Oct 4, 2023
@mdjermanovic mdjermanovic self-assigned this Oct 4, 2023
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Apr 4, 2024
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Apr 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly repro:yes
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants