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

Using template rules with pug #880

Closed
undsoft opened this issue Aug 22, 2019 · 2 comments
Closed

Using template rules with pug #880

undsoft opened this issue Aug 22, 2019 · 2 comments

Comments

@undsoft
Copy link

undsoft commented Aug 22, 2019

Hey,

I'm trying to use template rules, such as 'template-use-track-by-function' on my project.
The problem is that I'm using pug in my templates.

I'm using https://github.com/danguilherme/ng-cli-pug-loader.

Is there any way for me to make template rules work with pug?
I'm willing do extend the rules if that's necessary, but would need some direction to do that.

Thanks.

@mgechev
Copy link
Owner

mgechev commented Aug 22, 2019

Hey @undsoft, you can check the advanced config section in the readme. The functionality exists in codelyzer, but hasn't been exhaustively tested yet.

Let me know how it goes.

@undsoft
Copy link
Author

undsoft commented Aug 26, 2019

It seems to be working okay more or less.
Here's my .codelyzer.js config:

const pug = require('pug');

module.exports = {
  /**
   * Transforming pug templates for codelyzer.
   */
  transformTemplate(code, url) {
    const result = {code: code, url: url};

    if (url && /\.pug$/.test(url)) {
      const transformed = pug.render(code);
      result.source = code;
      result.code = transformed;
    }
    return result;
  },
};

Unfortunately I wasn't able to find anything that would generate proper sourcemaps, which means that numbers in tslint logs are off, but that's something I can live with.

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

2 participants