-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Too strict: non_constant_identifier_names #57394
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
Comments
consts shouldn't be all-uppercase https://www.dartlang.org/guides/language/effective-dart/style#prefer-using-lowercamelcase-for-constant-names |
Since nothing is expected to be screaming-snake anymore... is this request stale? |
This stops us from enabling this lint in google3; there's no practical way we can get rid of UPPER_CASE finals, since it used to be recommended and is still allowed by effective dart. Could the analyzer team please comment on whether it makes more sense to fix or fork? Thanks! |
I think there are two questions here: whether some As for the first, neither constant_identifier_names nor non_constant_identifier_names currently treat any That said, it's impossible for the linter to always accurately determine when a variable is effectively constant. The class An alternative we might want to consider is to change the immutable classes in question so that they do have As for the second, the style guide does allows the use of all cap names under one condition:
The linter can't check for "consistency with existing code", but could check for the specific cases listed. Specifically, it could allow it when:
I think it would be less harmful for users that are trying to use constant_identifier_names to prevent the use of SCREAMING_CAPS for constants if we special case only those situations that are explicitly listed. Given that constraint, I have no problem updating constant_identifier_names to sometimes allow SCREAMING_CAPS. |
Treating final declarations as constants for the purpose of this lint moves the SCREAMING_CAPS discussion out of this lint, which is sufficient to unblock us :) Looking at pre-existing violations in google3 there are plenty that are neither consts/finals and could benefit from this lint. Here (google internal only, sorry!): http://go/non_constant_identifier_names_prios What do you think, please? |
I think this is stale at this point, though /cc @davidmorgan if you disagree and want to re-open. |
When code (such as but not limited to tests - it's also true for static final fields on a class and real-top level final variables), it's common to define constant-like identifiers as such:
non_constant_identifier_names
triggers saying:Conceptually however, a
final
is used similar toconst
- things likeInt64
,RegExp
, etc, do not haveconst
constructors - but they are immutable objects wherefinal
is used. This seems to conflict with constant_identifier_names, where it's legal to usefinal
.Suggestions:
(There is a lot of existing code, including in the SDK, that uses ALL_CAPS)
The text was updated successfully, but these errors were encountered: