Skip to content

Commit

Permalink
feat(eslint-plugin-template): [i18n] add allowMarkupInContent option (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
m-akinc committed May 22, 2024
1 parent 977f0b9 commit bb8470d
Show file tree
Hide file tree
Showing 3 changed files with 416 additions and 11 deletions.
292 changes: 292 additions & 0 deletions packages/eslint-plugin-template/docs/rules/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ The rule accepts an options object with the following properties:

```ts
interface Options {
/**
* Default: `true`
*/
allowMarkupInContent?: boolean;
boundTextAllowedPattern?: string;
/**
* Default: `true`
Expand Down Expand Up @@ -130,6 +134,33 @@ interface Options {

<br>

#### Default Config

```json
{
"rules": {
"@angular-eslint/template/i18n": [
"error"
]
}
}
```

<br>

#### ❌ Invalid Code

```html
{ value, plural, =0 {No elements} =1 {111} }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

<br>

---

<br>

#### Custom Config

```json
Expand Down Expand Up @@ -1098,6 +1129,111 @@ interface Options {
</div>
```

<br>

---

<br>

#### Custom Config

```json
{
"rules": {
"@angular-eslint/template/i18n": [
"error",
{
"allowMarkupInContent": false,
"checkId": false
}
]
}
}
```

<br>

#### ❌ Invalid Code

```html
<div i18n>
Text to translate
<foo></foo>
~~~~~~~~~~~
</div>
```

<br>

---

<br>

#### Custom Config

```json
{
"rules": {
"@angular-eslint/template/i18n": [
"error",
{
"allowMarkupInContent": false,
"checkId": false
}
]
}
}
```

<br>

#### ❌ Invalid Code

```html
<ng-template i18n>
Text to translate
<foo></foo>
~~~~~~~~~~~
</ng-template>
```

<br>

---

<br>

#### Custom Config

```json
{
"rules": {
"@angular-eslint/template/i18n": [
"error",
{
"allowMarkupInContent": false,
"checkId": false
}
]
}
}
```

<br>

#### ❌ Invalid Code

```html
<div i18n>
<div i18n>
~~~~~~~~~~
Text to translate
~~~~~~~~~~~~~~~~~
</div>
~~~~~~
</div>
```

</details>

<br>
Expand Down Expand Up @@ -1551,6 +1687,34 @@ interface Options {

#### ✅ Valid Code

```html
<ng-container i18n="@@description">
{ value, plural, =0 {No elements} =1 {111} }
</ng-container>
```

<br>

---

<br>

#### Default Config

```json
{
"rules": {
"@angular-eslint/template/i18n": [
"error"
]
}
}
```

<br>

#### ✅ Valid Code

```html
<ng-container i18n="@@description">
{ value, plural, =0 {<div>No elements</div>} =1 {111} }
Expand Down Expand Up @@ -2124,6 +2288,134 @@ interface Options {

<br>

#### Custom Config

```json
{
"rules": {
"@angular-eslint/template/i18n": [
"error",
{
"allowMarkupInContent": false,
"checkId": false
}
]
}
}
```

<br>

#### ✅ Valid Code

```html
<div i18n>
Text to translate{{ Bound }}
</div>
```

<br>

---

<br>

#### Custom Config

```json
{
"rules": {
"@angular-eslint/template/i18n": [
"error",
{
"allowMarkupInContent": false,
"checkId": false
}
]
}
}
```

<br>

#### ✅ Valid Code

```html
<ng-template i18n>
Text to translate{{ Bound }}
</ng-template>
```

<br>

---

<br>

#### Custom Config

```json
{
"rules": {
"@angular-eslint/template/i18n": [
"error",
{
"allowMarkupInContent": false,
"checkId": false
}
]
}
}
```

<br>

#### ✅ Valid Code

```html
<div i18n>
{ value, plural, =0 {No elements} =1 {111} }
</div>
```

<br>

---

<br>

#### Custom Config

```json
{
"rules": {
"@angular-eslint/template/i18n": [
"error",
{
"allowMarkupInContent": false,
"checkId": false
}
]
}
}
```

<br>

#### ✅ Valid Code

```html
<div i18n>
{ value, plural, =0 {<div>No elements</div>} =1 {111} }
</div>
```

<br>

---

<br>

#### Default Config

```json
Expand Down

0 comments on commit bb8470d

Please sign in to comment.