Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Class constants naming #47

Open
socram8888 opened this issue Nov 24, 2021 · 4 comments
Open

Class constants naming #47

socram8888 opened this issue Nov 24, 2021 · 4 comments

Comments

@socram8888
Copy link

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.

@EdJoPaTo
Copy link

#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!

@socram8888
Copy link
Author

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.

@sindresorhus
Copy link
Member

I'm fine with allowing upper case static properties, but it should also camel case.

@fregante
Copy link
Member

fregante commented Aug 6, 2022

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…)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants