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

feat(eslint-plugin-template): [i18n] add allowMarkupInContent option #1795

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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