codelyzer icon indicating copy to clipboard operation
codelyzer copied to clipboard

i18n (check-text) returning false positives

Open rafaelss95 opened this issue 6 years ago • 10 comments

Config:

{
  "rules": {
    "i18n": [
      true,
      "check-id",
      "check-text"
    ]
  }
}
@Component({
  template: `
    <button type="button" mat-raised-button color="primary">
      <mat-icon>add</mat-icon> <!-- unexpected failure reported here -->
    </button>
    <button type="button" mat-raised-button color="primary">
      <mat-icon>
        visibility{{ passwordType === 'text' ? '_off' : '' }} <!-- unexpected failure reported here -->
      </mat-icon>
    </button>
  `
})
class Test {}

rafaelss95 avatar May 14 '18 02:05 rafaelss95

perhaps a config option could be added to provide a list of elements to ignore (eg: ["mat-icon"]).

jaufgang avatar Jun 13 '18 14:06 jaufgang

I'm afraid we can't add this option without breaking changes. Thoughts @mgechev?

rafaelss95 avatar Jul 29 '18 19:07 rafaelss95

{
  "rules": {
    "i18n": [
      true,
      "check-id",
      "check-text",
      {
        "blacklist": ["mat-icon"]
      }
    ]
  }
}

Looks fine to me.

mgechev avatar Jul 29 '18 20:07 mgechev

Any progress on this? Using @mgechev's solution above makes the i18n rule not work at all rather than just ignoring mat-icon elements (using tsling 5.11.0 & codelyzer 4.5.0).

jonsamwell avatar Nov 27 '18 09:11 jonsamwell

Would appreaciate the blacklist rule. As by the moment this produces unnesscassary i18n attributes.

Karamuto avatar Dec 05 '18 07:12 Karamuto

This would be awesome, unfortunately the blacklist property seems to break the template-i18n rule entirely. Does anyone happen to have the blacklist property suggested by @mgechev above working..? I'm wondering if there's something obvious I'm missing. Going through the codelyzer source code I don't think a blacklist property on this rule is possible, but I could be mistaken.

To recap, this works but picks up the mat-icon content in a false positive result:

"template-i18n": [true, "check-id", "check-text"]

This causes the rule itself to be inert (defeating the entire point of having the rule in the first place):

"template-i18n": [
  true,
  "check-id",
  "check-text",
  {
    "blacklist": ["mat-icon"]
  }
]

wescopeland avatar Jul 14 '19 16:07 wescopeland

i can also confirm that blacklisting causes the rule to become inert

angular 8.1.3 tslint 5.18.0 codelyzer 5.1.0

fulls1z3 avatar Jul 28 '19 20:07 fulls1z3

I am pretty sure @mgechev was just replying to @rafaelss95, suggesting a potential "non breaking change" solution and not pointing to the existing solution for the problem at hand.

I however would love to see this rule being updated with blacklist :+1:

klemenoslaj avatar Sep 06 '19 18:09 klemenoslaj

any progress on this? I'm meanwhile thinking about writing a custom linter rule based on that one...

seawave23 avatar Sep 18 '20 15:09 seawave23

Would be nice to have the configuration option. I worked around the problem by using string interpolation and a string literal.

So something like this:

- <mat-icon>arrow_back</mat-icon>
+ <mat-icon>{{'arrow_back'}}</mat-icon>

I have to be honest though. I have no idea if this has any downsides to it.

konstantinhatvan avatar May 18 '22 14:05 konstantinhatvan