Codelyzer: Ionic 2 Support

Created on 2 Nov 2016  路  13Comments  路  Source: mgechev/codelyzer

I have been using Codelyzer with an Ng2 project and loving it. I have started an Ionic 2 project that uses Codelyzer and it works almost perfectly except for an issue with pages. In Ionic the Component decorator is used for pages but the class name is suffixed with "Page." For example the file hello-ionic.page.ts would be:

import { Component } from '@angular/core';

@Component({
  templateUrl: 'hello-ionic.page.html'
})
export class HelloIonicPage {
  constructor() {

  }
}

This causes Codelyzer to state that "The name of the class HelloIonicPage should end with the suffix Component".

Changing componentClassSuffixRule.js line 16 from:

return /.*Component$/.test(className);

to

return (/.*Component$/.test(className) || /.*Page$/.test(className));

Fixes the problem but I figure there is probably a more elegant solution. In Ionic projects there will still be components so is there a way of discerning between a page and component based on location (src/pages/* vs srv/components/*)? Or allowing custom component suffixes in the rules config?

enhancement P2

Most helpful comment

I think README.md should be updated with an example for using both, the single syntax and the array syntax, or at least mention it. :). Do you mind if I do it?

All 13 comments

I think it would be a great addition to let user's configure an optional regex that is used to test all naming conventions that Codelyzer checks. Then for your code you could allow either Component or Page. Some other people may have other conventions they want to allow. (for example we would like to allow "Panel" for some types of components)

This rule can be made configurable and by default the suffix will be Component. It is going to be part of the next release.

Thanks! Will follow this then. 馃憤

Great! Thanks for all your work on this project

Can you confirm that currently (beta3) it's not possible to specify an array of suffixes in tslint.json ?
Since Ionic 2 use both "Component" and "Page", we still got an error.

I saw there was a more recent commit allowing this.
Is the master version stable enough to use or do we need to wait for beta4 ?

Thanks

Beta3 doesn't support multiple suffixes. Yes, master is usually stable so you can give it a try.

@mgechev so this will support an array of suffixes? Thanks you. 馃憤

Yes, master does.

I think README.md should be updated with an example for using both, the single syntax and the array syntax, or at least mention it. :). Do you mind if I do it?

Reviewing this now, and still the docs lacks of examples of how to pass an array. Even the JSON Schema is lacking this options, throwing warnings in the tslint.json file if the array is passed as an option. (This is mostly because it's not an array of strings, but _n_ strings.

The JSON schema in maintained by third--party. I opened a PR sometimes back, at some point it will go upstream.

It'll be great if you open a PR with docs improvement.

I was just doing that, but found the actual documentation. I think that maybe the problem. As is right now it seems like all the docs are in README, cause there is no link to the documentation, nor a mention of it. Maybe less information of usage in README and instead a link to the docs?

http://codelyzer.com/rules/ generated from the source code.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lazarljubenovic picture lazarljubenovic  路  4Comments

davidanaya picture davidanaya  路  4Comments

fabioemoutinho picture fabioemoutinho  路  5Comments

snebjorn picture snebjorn  路  5Comments

mattlewis92 picture mattlewis92  路  5Comments