-
Notifications
You must be signed in to change notification settings - Fork 100
Properly use ruleSeverity
properties of rule converters during conversion
#1468
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
Properly use ruleSeverity
properties of rule converters during conversion
#1468
Conversation
ruleSeverity
properties of rule converters in conversionruleSeverity
properties of rule converters during conversion
ruleSeverity
properties of rule converters during conversionruleSeverity
properties of rule converters during conversion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great so far, thanks for starting this!
Just requesting changes on an additional test. Everything else is nitpicking 😄 .
const conversionResult: { | ||
rules: { ruleName: string; ruleSeverity: ESLintRuleSeverity }[]; | ||
} = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the array type there is the ConvertedRuleChanges
exported by ruleConverter.ts
.
const conversionResult: { | |
rules: { ruleName: string; ruleSeverity: ESLintRuleSeverity }[]; | |
} = { | |
const conversionResult: { | |
rules: ConvertedRuleChanges[]; | |
} = { |
Although, I think this would be a bit cleaner:
const rules: ConvertedRuleChanges[] = [
{
ruleName: "eslint-rule-a",
ruleSeverity: "off",
},
];
const { tslintRule, converters, mergers } = setupConversionEnvironment({
ruleSeverity: "error",
conversionResult: { rules },
ruleToMerge: rules[0].ruleName,
});
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll incorporate those changes - agree that it looks cleaner! :)
const { converted } = convertRules( | ||
{ ruleConverters: converters, ruleMergers: mergers }, | ||
{ [tslintRule.ruleName]: tslintRule }, | ||
new Map<string, string[]>(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the type arguments can be inferred here.
new Map<string, string[]>(), | |
new Map(), |
Eventually we'll have a no-inferrable-type-arguments
rule or some such in typescript-eslint... one day!
@@ -353,6 +353,45 @@ describe("convertRules", () => { | |||
]).toContainEqual(converted); | |||
}); | |||
|
|||
it("merges when a rule's ruleSeverity explicitly differs from its TSLint equivalent", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case looks good and we should include it. Great!
But I think we should also test for the case described in the issue: that there are two output rules from the converter, one turned off and one with the original rule severity. Could you please add a test case for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure! I'll incorporate that new test case in my upcoming modifications ^w^
Thank you for your feedback! I'll be pushing the new changes within the next day EDIT: Done! I also edited the test name to make it sound a bit better |
This additionally ensures that the ruleSeverities during the conversion aren't always treated exactly the same. Moreover, it tests the case that if ruleSeverity isn't specified, the default (its respective TSLint equivalent) is used instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look great, thanks as always @hyperupcall! ✨
PR Checklist
status: accepting prs
Overview
It seems that if
ruleSeverity
is specified within a rule of a converter, it is not properly applied when converting to the ESLint rules. The linked page mentions it specifically forsemicolon
, but it seems to be more generalFor example, the following TSLint rules will both have a
ruleSeverity
oferror
sincetrue
is the first array elementThis translates directly to the following ESLint, even though we do
{ ruleName: "semi", ruleSeverity: "off" }
, etc. in the convertersThe patches fix this by setting the converted
ruleSeverity
with the explicitly specifiedrule.ruleSeverity
if it is truthyThe following show the full resulting ESLint configs before and after the code changes (using the aforementioned TSLint config)
Before:
.eslintrc.json
After:
.eslintrc.json