aurelia / template-lint

Sanity check of Aurelia-flavor template HTML
Apache License 2.0
56 stars 17 forks source link

Support custom element attributes with checking #67

Open zakjan opened 8 years ago

zakjan commented 8 years ago

item.ts

import {bindable} from "aurelia-templating";

export class ItemCustomElement {
    @bindable value: string;
}

item.html

<template>
    ${value}
</template>

page.ts

export class PageViewModel {
    value: number;
}

page.html

<template>
    <require from="./item"></require>

    <item title.bind="value" value.bind="value"></item>
</template>

This should throw two errors, the first for missing bindable title attribute in ItemCustomElement, the second for mismatching type of value attribute.

atsu85 commented 7 years ago

@MeirionHughes, currently this issue is assigned to 0.11 milestone, but i think that this issue has actually the most impact for this project (mostly for newcomers, but it could have saved some of my time as well last week because of copy-past from camelCaseProperty that should have been converted to kebab-case when used as attribute)

MeirionHughes commented 7 years ago

Unfortunately, the rework stuff is slow going (0.10) as its taken a while to decide how to structure it --I'm favoring chain-of-responsiblity style for the rules that operate on the ast - thus abstracting away the parser entirely.

So... I will take a look at this to see if something can be done asap.

atsu85 commented 7 years ago

Am I correct that currently the missing prerequisite for this task is ability to check/resolve references to other files via <require from="..."? So probably a components that would

would be smth in the beginning of the responsiblity chain? Is that smth You have in mind?

MeirionHughes commented 7 years ago

Yeah something like that; basically you pass the file result along and they add extra processed data to the result/ast. not entirely there yet. the idea is to make it generic enough so I can throw any file type at the chain.

However, for now, I could probably to grab the source when <require from='./item'' comes up. see if there the first export has the custom element decorator, define a custom element resource, and finally, attach the resource to the ast. that should allow me to check the bindables at least exist and get the type reflection for both the left and right side.

One thing I need to workout is how to get typescript to determine if one type can be assigned to another.

atsu85 commented 7 years ago

I created a checklist (containing two ideas from @zakjan, one from @zakjan and added couple from myself):

zakjan commented 7 years ago

Another idea: If --strictNullCheck is enabled, it could also check if all required bindable attributes are passed, meaning only those explicitly typed with X | undefined or with a default value could be left unassigned.

MeirionHughes commented 7 years ago

okay-doky, I've added something basic (bit ugly too). its limited to './foo' having a first class with FooSomeThingCustomElement and the resulting element being foo-some-thing. also if you bind to the DOM parts of the element, it will complain at the moment. Will need a way to figure out how to get the reflection information for the base dom element.

zakjan commented 7 years ago

More ideas: