-
Notifications
You must be signed in to change notification settings - Fork 10
Added rule for "_" suffix for internal variables #31
Added rule for "_" suffix for internal variables #31
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.
Thank you @viquezclaudio!
This is very close to be green.
Please add tests for internal and private explicit declarations.
I'm inclined to reject public state variables with underscore prefix, but maybe later. What do you think about this?
And about the rule name, I think it should either be called internal-state-underscore-suffix, or receive the suffix as an argument, with _
being the default.
README.md
Outdated
@@ -41,6 +41,9 @@ In the .soliumrc.json file, add: | |||
], | |||
"zeppelin/no-unused-imports": [ | |||
"warning" | |||
], | |||
"zeppelin/internal-state-suffix":[ |
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.
please add a space after the colon.
rules/internal-state-suffix.js
Outdated
if (emitted.exit) { | ||
return; | ||
} | ||
emitted.node.params.forEach(param => { |
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.
in this case, there are no params. So remove this forEach loop.
We just need to check:
emitted.node.name.charAt(emitted.node.name.length - 1) !== "_"
The function inspectStateVariableDeclaration
will be called for each declaration, so the loop is already happening, but one level higher.
test/internal-state-suffix.js
Outdated
errors.should.be.instanceof(Array); | ||
errors.length.should.equal(1); | ||
errors[0].message.should.equal( | ||
"'internal_no_underscore_suffix' does not have an underscore suffix."); |
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 error message you defined says "underscore AS suffix"
64b94ae
to
86ec63a
Compare
86ec63a
to
d8ff9c2
Compare
@ElOpio You are right, I will add tests for explicit internal and private declarations. Regarding your question, do you mean creating a rule to reject public variables with underscore suffix ? |
Thanks @viquezclaudio. With your help and after a few iterations with this rules, we realized that if we required all state variables to be private, we could prefix them with an underscore (like on python), and there will be no conflict with function parameters that will be without underscore. I'm closing this one in favor of #32. I copied your code with a few tweaks, so it would be nice if you can review it. |
New rule for "_" suffix for internal variables: variables with no visibility qualifier or private or internal variables. Does not apply for variables in a function