template-lint icon indicating copy to clipboard operation
template-lint copied to clipboard

Ideas for Rules

Open MeirionHughes opened this issue 8 years ago • 9 comments

Any ideas for more rules would be welcome.

MeirionHughes avatar May 31 '16 18:05 MeirionHughes

Fantastic initiative, I've created an issue to Aurelia tools repo about the ideas long time ago. It would be nice, it this project eventually evolves/moves to official Aurelia subproject to gain more attraction and help from the Aurelia community.

atsu85 avatar Jun 10 '16 19:06 atsu85

Static type checking of templates would move Aurelia projects to a completely different level of correctness. Most likely connected with TS interfaces/classes.

zakjan avatar Jun 10 '16 20:06 zakjan

Thanks for the feedback! I'm afraid all these rules have been my best guess and so I'm more than happy to make fixes, if the linter conflicts with what people know to work.

MeirionHughes avatar Jun 11 '16 06:06 MeirionHughes

awesome project! :100:

how about a rule that uses aurelia-binding's parser to validate binding expressions are well formed? Taking that a step further, the resulting AST could be analyzed and assigned a complexity score, potentially emitting warnings if the score exceeds some configured threshold.

I suppose at some point we'll be able to use the ViewCompiler in aurelia-templating server-side which would probably make this kind of thing even easier.

jdanyow avatar Jun 21 '16 11:06 jdanyow

Yes, that could be done. :)

I've chosen to avoid ViewCompiler for the time being, firstly because the linter is build on a stream parser and secondly because I was only interested in matching binding paths with known types.

MeirionHughes avatar Jun 21 '16 13:06 MeirionHughes

Another idea: Check that neither constructor nor activate method tries to use element referenced from the template.

Sample

Html:

<div ref="myDiv" >...</div>

ES/TypeScript:

...
    myDiv: Element;
    constructor() {
        this.myDiv.innerHTML; // <--- illegal, myDiv not set
    }

    activate(params, routeConfig: RouterConfiguration, navigationInstruction: NavigationInstruction) {
        this.myDiv.innerHTML; // <--- illegal, myDiv not set
    }

    attached() {
        this.myDiv.innerHTML; // <--- OK
    }
...

atsu85 avatar Jun 27 '16 07:06 atsu85

Another idea: Check that ViewModel and CustomElement classes are not used directly from other application TypeScript files. I'd consider it a bad design and would use some other communication pattern instead.

atsu85 avatar Jul 04 '16 09:07 atsu85

@atsu85 Good idea. Unfortunately there is an official exception for this: view model used for aurelia-dialog. https://github.com/aurelia/dialog#using-the-plugin

zakjan avatar Jul 04 '16 09:07 zakjan

Yeah, i guess this would need to be whitelisted somehow (as string in configuration or perhaps using a decorator)

atsu85 avatar Jul 04 '16 09:07 atsu85