-
Notifications
You must be signed in to change notification settings - Fork 160
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
Add contribution formatter parameter validation #54
Add contribution formatter parameter validation #54
Conversation
…posible output format options that the chosen format exists, and if not, it outputs a console error.
solhint.js
Outdated
'table', | ||
'tap', | ||
'unix', | ||
'visualstudio']; |
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.
Since we delegate the formatting to eslint, instead of hardcoding the list of possible formatters I think a better option is to handle this in the catch
block when the formatter is required.
The downside of this approach is that the error will be throw after the linter is executed, and that wastes user time unnecessarily. But I think it's OK for now. (A possible improvement to avoid this is to get the formatter before the linter is run.)
…uiet and --max-warnings options.
Update repository with --quiet option new feature
…uiet and --max-warnings options
…-parameter-validation
solhint.js
Outdated
} | ||
|
||
function getFormatter(formatter){ | ||
const formatterName = formatter || 'stylish'; | ||
if (typeof formatterName === 'string' && formatterOptions.includes(formatterName)) { | ||
if (typeof formatterName === '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.
Is this check necessary? In which situations can formatterName
not be a string? And even if it is, I think the try-catch
below will handle things correctly anyway.
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.
Yes, I think so. The try-catch will be enough.
try { // to check if is a valid formatter before execute linter | ||
formatterFn = getFormatter(program.formatter); | ||
} catch (ex) { | ||
console.error(ex.message); |
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.
Can we make this error message more clear? Maybe prefixing it with There was a problem loading the specified formatter "${program.formatter}": ${ex.message}
(or something like 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.
Yes, sure, so I will add ${program.formatter} to show the input too.
Description
It PR add an input parameter validation in format option.
The motivation appeared when I noticed that in the case of a invalid formatter input, it not handle any exception.
So, to validate the input, I decided to check it into an array with all the valid options. Also, it handle exception if appears an error when try to look for the required module.
To reproduce the changes:
--format option with a valid parameter (eg. -- format table [file])
--format option with an invalid parameter (eg. -- format tabe [file])
Fixes #(issue)
There are no previous issues related.
Type of change
Checklist: