-
Notifications
You must be signed in to change notification settings - Fork 21
Add hash field to actions in CWS agent rules #2463
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 hash field to actions in CWS agent rules #2463
Conversation
Datadog ReportBranch report: ❌ 10 Failed (0 Known Flaky), 86 Passed, 1588 Skipped, 40.63s Total duration (35.31s time saved) ❌ Failed Tests (10)
|
ad27619 to
a689ccb
Compare
a689ccb to
d605aba
Compare
| # Calculates hash code according to all attributes. | ||
| # @return [Integer] Hash code | ||
| # @!visibility private | ||
| def hash |
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.
🔵 Code Quality Violation
Avoid nested methods (...read more)
The Ruby static analysis rule "Prevent nested method" discourages defining a method within another method. This practice is generally discouraged in Ruby because the inner method is not actually defined within the scope of the outer method as one might expect, but rather in the same scope as the outer method. This can lead to unexpected behavior and make code more difficult to understand and maintain.
This rule is important because it promotes good coding practices and helps to prevent potential bugs. Nested methods can lead to confusing code and unintended side effects, making your code more difficult to debug and maintain. Furthermore, nested methods are not a common practice in Ruby and can be surprising to other developers who read your code.
To avoid violating this rule, define all methods at the same level of scope. Instead of defining a method within another method, define each method separately and call them as needed. If you find that you are frequently defining methods within other methods, it may be a sign that your code could be structured more effectively, for example by using classes or modules.
| # check to see if the attribute exists and convert string to symbol for hash key | ||
| attributes = attributes.each_with_object({}) { |(k, v), h| | ||
| if (!self.class.attribute_map.key?(k.to_sym)) | ||
| fail ArgumentError, "`#{k}` is not a valid attribute in `DatadogAPIClient::V2::CloudWorkloadSecurityAgentRuleActionHash`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect |
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.
⚪ Code Quality Violation
Consider using string interpolation or formatting instead of concatenation. (...read more)
The rule "Avoid string concatenation" is an important coding practice in Ruby for ensuring efficient and clean code. String concatenation in Ruby using the '+' operator creates a new string object, which can lead to excessive memory usage and slower performance when dealing with large strings or performing the operation multiple times.
Instead, Ruby provides alternatives that are more efficient. The string interpolation syntax #{} allows you to insert variables directly into strings without creating new string objects. This is not only more memory efficient, but also provides cleaner and more readable code.
Another alternative is the format method, which allows you to create a formatted string with placeholders for variables. This method is particularly useful when dealing with more complex strings, as it provides a clear and concise way to format your strings.
By following this rule, you can write more efficient and cleaner Ruby code, leading to better performance and readability.
d605aba to
70ce251
Compare
See DataDog/datadog-api-spec#3957
Test branch datadog-api-spec/test/quentin.guillard/add-hash-field-to-cws-agent-rule