eslint-config-xo-typescript
eslint-config-xo-typescript copied to clipboard
Class constants naming
Currently, the ESlint configuration will mark constant properties on classes as errors. For example:
class FNV {
private static readonly PRIME = 16777619;
private static readonly OFFSET = 2166136261;
// ...
}
Will be considered an error, as they are expected to follow the camel case convention used for other mutable or instance-specific values, despite being an immutable constant.
Unless this is intentional, maybe it could make sense to add a rule to force attributes tagged with static readonly
to follow the same UPPER_CASE
format as the rest of the constants.
#42 is probably relevant here. I tried getting it to work for my interest which didnt seem to work for me. (unclear why) Would be nice to see improvements there!
Adding:
{
selector: 'classProperty',
modifiers: ['static', 'readonly'],
format: ['UPPER_CASE'],
},
Seems to do the job. Again, not sure if this should be added because I am not sure if the XO guideline considers this a constant or a class property.
I'm fine with allowing upper case static properties, but it should also camel case.
I’m not sure why this would be an exception to the current naming rule. The same request but for top-level constants was rejected, if I remember correctly. Either both should be allowed or neither.
(I’d prefer both, but…)