-
Notifications
You must be signed in to change notification settings - Fork 113
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: Add error handling in VariableCreateUpdateForm and wrap text in ItemValue #4443
Conversation
} | ||
} catch (e) { | ||
callback(new Error(this.$t('ExtraArgsFormatError'))) | ||
} | ||
callback() | ||
} |
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 provided code contains slight syntax errors which can cause issues during evaluation. Here are some corrections:
- At
@import
there should not be a space before the double quote symbol. - The function name inside brackets
{}
must start from an uppercase letter.
Here's the corrected version of the code according to these guidelines:
export default {
rules: [
{
validator: (rule, value, callback) => {
var arrayLines = value.split("\n");
// Regular Expression pattern will match line with exactly two ":" separated fields
const regex = /^\s*:?\S+: ?(\w*)$/;
for(let i=0; i < arrayLines.length;i++)
{
let val = arrayLines[i].replace(/\n/g,'');
let regMatch = arrayLines[i].match(regex);
if(!regMatch)return;
if(arrayLines[i] != ""){
return false;
This is where the first error resides; it suggests that each line needs to start with whitespace followed by either a colon on every field other than the second one. For example, "colon\ssomething". Also, ensure proper indentation and formatting within curly braces.
@@ -92,7 +92,7 @@ export default { | |||
) | |||
} | |||
return ( | |||
<span title={this.displayValue}>{this.displayValue}</span> | |||
<span style='white-space: pre-wrap;' title={this.displayValue}>{this.displayValue}</span> | |||
) | |||
} | |||
} |
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.
There's no error found with this line of code.
The difference between this modified version and the original could be:
- The
displayValue
prop is an optional property which can contain one or more values separated using commas.
And here's some general code style tips to improve readability:
- It often helps if you indent blocks that define rules rather than separate things with whitespace.
export default { ... // Define these variables outside their usage var displayValue = ''; if (value != null) { displayValue += value; } else { ...
2. Ensure that your props should have type annotation:
```
export default ({
...
}) => ({ ... }
- You need proper handling of edge cases where
null
may exist.if(value === null && hasNonNumericValue){ // handle non numeric value when `hasNonNumericValue` == true }
- Consider wrapping elements such as
<span>
's to prevent them from being interpreted as inline content, which makes them behave like block-level tags in JSX.return( <span> ... </span> )
- Also ensure that you're checking all properties on the object before doing anything with it:
Object.entries(propToCheck).forEach(([key, val]) =>{
if (!val || typeof val !== 'object'){
// Do something different...
}
})
Quality Gate passedIssues Measures |
fix: Add error handling in VariableCreateUpdateForm and wrap text in ItemValue