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
fix space-before-function-paren
#293
fix space-before-function-paren
#293
Conversation
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.
LGTM, thanks for re-tackling this converter @bouzuya!
If you have time to address the requests soon, that'd be swell - otherwise I can take care of them myself.
const ruleName = "space-before-function-paren"; | ||
if (argument === "always" || argument === "never") { | ||
return { rules: [{ ruleArguments: [argument], ruleName }] }; | ||
} else if (typeof argument === "object" && argument !== null) { |
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.
The contents in the body of this else if
are a little substantial to read through. Would you mind splitting them into a separate function? That'd be helpful for readability IMO.
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'm sorry. I can't read English well. In this what you mean?
const isObject = (o: unknown): o is Record<string, "always" | "never"> =>
typeof o === "object" && o !== null;
// ...
} else if (isObject(argument)) {
// ...
Alternatively, I think it would be better to use typeof argument === "undefined"
if tslint.json
is valid.
// ...
} else if (typeof argument === "undefined") {
return { rules: [{ ruleName }] };
}
const notices = Object.keys(argument)
.filter(option => !SUPPORTED_OPTIONS.includes(option))
.map(option => `Option "${option}" is not supported by ESLint.`);
const filtered = Object.keys(argument)
.filter(option => SUPPORTED_OPTIONS.includes(option))
.reduce<Record<string, "always" | "never">>((obj, option) => {
return { ...obj, [option]: argument[option] };
}, {});
return {
rules: [
{
...(notices.length !== 0 && { notices }),
...(Object.keys(filtered).length !== 0 && { ruleArguments: [filtered] }),
ruleName,
},
],
};
What would you like to do specifically?
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.
Oh sorry for the ambiguity in my comments! Yes, your second suggestion around using typeof
seems great.
My overall goal was to reduce the amount of logic placed inside the else
statement, since that can be confusing to read through. Moving that stuff into a separate function can be helpful to split the code up so each individual portion is understandable.
f5dbe8d
to
de0edc8
Compare
de0edc8
to
d39e097
Compare
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.
As before @bouzuya - I'll apply the discussed changes soon if you don't have the time. Thanks! 🙌
Can I ask to fix them? |
Sure! I'll merge this in now and send a separate PR. Thanks for all your work! 🙌 |
Actually, wait, @bouzuya I think I missed a commit - you applied all the changes I asked for. I think I'm just confusing you unnecessarily. Sorry! 😅 |
PR Checklist
status: accepting prs
Overview
See: #292