Skip to content
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

[Feature Request] - Force output fields to be readonly #515

Closed
pgrm opened this issue Feb 13, 2018 · 3 comments
Closed

[Feature Request] - Force output fields to be readonly #515

pgrm opened this issue Feb 13, 2018 · 3 comments

Comments

@pgrm
Copy link

pgrm commented Feb 13, 2018

I'm not sure if this is 100% correct, since I don't recall seeing it anywhere else, but in our Angular project, we are marking all @Output fields readonly because really, there is no need to ever re-assign them.

Unless there are some edge cases, which we aren't aware of right now, it would be great if codelyzer could do the check, if all @Output fields are marked as readonly for us, otherwise we always need to check for it manually in code reviews.

Similarly it could be also checked that @Input is never marked as readonly (I have seen it sometimes in our code base and typescript never complained about it, even though it was definitely wrong and set at a later point).

I've never implemented a tslint rule myself, but if you think this one makes sense and you know of some which I could basically copy/paste with few adjustments, to achieve those checks, I'd be fine with contributing the rule as well.

@wKoza
Copy link
Collaborator

wKoza commented Feb 13, 2018

Usually, we use readonly when there is a functional risk that our property is overwritten. What is your fear ?

@pgrm
Copy link
Author

pgrm commented Feb 13, 2018

Well basically, I'd love to use https://www.npmjs.com/package/tslint-immutable - but we're not quite there yet unfortunately, that's why we started just to enforce readonly markings on anything we don't intend to change, which are mostly Observables, just to prevent if somebody unfamiliar with observables might assign a new value to a field, instead of emitting a new value.

Those issues already happened, and that's just why we're trying to mark fields like that as readonly.

@wKoza
Copy link
Collaborator

wKoza commented Feb 14, 2018

I don't see the link between immutable and @output. Your problematic seems to be specific. I'm not sure that this proposal has its place in Codelyzer but let's see other opinions.

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

No branches or pull requests

3 participants