-
Notifications
You must be signed in to change notification settings - Fork 444
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(cli): add js file validation #1288
Conversation
if (!getScenarioFilePath(file)) { | ||
signale.error(`Scenario file ${file} not found.`) | ||
process.exit(1) | ||
} | ||
} | ||
} | ||
|
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.
with the code review
- The code is making sure that if a name and/or file is provided, it exists in the scenario list or file path respectively.
- It also checks to make sure that the file provided ends with .js, to ensure that it is a JavaScript file.
- If neither of these conditions are met, an error message is printed and the process is exited.
Overall, the code looks good and is properly checking the input. However, it might be worth adding a check to see if the name provided is actually a valid name, as opposed to an empty string or undefined.
if (path.extname(filePath) !== '.js') { | ||
throw new Error(`Invalid file type: ${filePath}. Only .js files are allowed.`) | ||
} | ||
|
||
const simulatorModule = require(filePath) | ||
|
||
if (typeof simulatorModule.generator !== 'function') { |
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.
with the code review.
First, I will check the readability of the code. The code is easy to read and understand. The indentation is correct and the variables are named appropriately.
Next, I will check for any errors or bugs. The code looks good and there are no errors or bugs that I can see.
Finally, I will check for any security issues. The code looks secure and there is a check in place to ensure that only .js files are allowed. This will help protect against malicious code being uploaded.
Overall, the code looks good and should work as expected.
If you have any questions, you can refer to the Contributing Guide
What is the current behavior?
Please describe the current behavior and link to a relevant issue.
Issue Number
Example: #123
What is the new behavior?
Please describe the new behavior or provide screenshots.
Does this PR introduce a breaking change?
Specific Instructions
Are there any specific instructions or things that should be known prior to review?
Other information