aurelia / template-lint

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

Support baseURL compiler option #167

Open RomkeVdMeulen opened 7 years ago

RomkeVdMeulen commented 7 years ago

resolution:

original:

Not very common, but sometimes I have something like: src/components/my-widget.ts:

import {Toggle} from "src/components/toggle";

export class MyWidget extends Toggle {
  myProp = "Lorem Ipsum";
}

src/components/toggle.ts:

export class Toggle {
  toggled = false;

  toggle() {
    this.toggled = !this.toggled;
  }
}

src/components/my-widget.html:

<template>
  <button click.trigger="toggle()">Toggle me</button>
  <p if.bind="toggled">${myProp}</p>
</template>

In which case the linter should not report WARNING: cannot find 'toggle' in type 'MyWidget' Ln 2 Col 3 my-widget.html or WARNING: cannot find 'toggled' in type 'MyWidget' Ln 3 Col 3 my-widget.html.

MeirionHughes commented 7 years ago

Its possible your import statement is the problem as inheritance should be supported: https://github.com/MeirionHughes/aurelia-template-lint/commit/7f941b9f05b8b3dd458d98f20594f11342883dc5

RomkeVdMeulen commented 7 years ago

That could be it: I'm not importing with a relative path. I have updated my original post to show how I import Toggle.

MeirionHughes commented 7 years ago

Yes, that's it. I think you'll need to use relative paths. Unless I'm mistaken "src/components/toggle" means /components/toggle from within src module. If this is what you're trying doing then support for modules at the moment is done via setting the typings path - not tested with node_modules/@types though.

RomkeVdMeulen commented 7 years ago

Using relative paths isn't a good option for my project. src isn't an external module in my case, it refers to code under the src dir in my codebase. I'm using the TypeScript baseURL compiler option to make this work.

In this case the module path I'm importing from matches what I passed to reflectionOpts.sourceFileGlob. Which is:

config.reflectionOpts.sourceFileGlob = "src/**/*.ts";

I can understand that following complex module resolution logic is a bit out of scope for a template linter. But perhaps it might be a useful feature to try to resolve non-relative imports that match the sourceFileGlob?