googlearchive / polylint

Lint polymer!
BSD 3-Clause "New" or "Revised" License
116 stars 19 forks source link

Add exception for underscore-prefixed properties #103

Closed aendra-rininsland closed 8 years ago

aendra-rininsland commented 8 years ago

I frequently use "private" methods/properties (I put in quote marks because I mentioned this in the Polymer Slack and it started a half hour-long discussion about what "private" really means in JS...) that aren't defined in properties, but are instead defined in the ready lifecycle method. From what I can tell, this is a fairly accepted practice, as is prefixing such properties/methods with underscores.

Alas, Polylint still throws the Property x not found in 'properties' for an-element warning because I haven't declared them in properties. Is there any way an exception could be written for properties prefixed with _?

Thanks!

aendra-rininsland commented 8 years ago

Additionally, could also throw a warning if an underscore-prefixed property is defined in properties to enforce the convention.

rictic commented 8 years ago

The underscore is enough to delineate the intended level of privacy, there's no reason to leave the property out of the properties block. e.g. https://github.com/PolymerElements/paper-input/blob/master/paper-input-behavior.html#L354 - the privacy is also respected in the docs, e.g. https://elements.polymer-project.org/elements/paper-input

There's good reasons to do initialization inside of properties, as it allows the data binding system to handle initialization, which can mean fewer data binding round trips, as well as less surprising behavior when a default value conflicts with an explicitly set value.

aendra-rininsland commented 8 years ago

@rictic Cool, thanks for the explanation! Have always been a bit confused by that in particular. Guess I'll start populating properties more than I have? :sweat_smile: