8000 feat(eslint-plugin-template): [no-restricted-syntax] add rule by rafaelss95 · Pull Request #698 · angular-eslint/angular-eslint · GitHub
[go: up one dir, main page]

Skip to content
8000

feat(eslint-plugin-template): [no-restricted-syntax] add rule #698

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
280 changes: 280 additions & 0 deletions packages/eslint-plugin-template/docs/rules/no-restricted-syntax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
<!--

DO NOT EDIT.

This markdown file was autogenerated using a mixture of the following files as the source of truth for its data:
- ../../src/rules/no-restricted-syntax.ts
- ../../tests/rules/no-restricted-syntax/cases.ts

In order to update this file, it is therefore those files which need to be updated, as well as potentially the generator script:
- ../../../../tools/scripts/generate-rule-docs.ts

-->

<br>

# `@angular-eslint/template/no-restricted-syntax`

Disallows specified syntax.

- Type: suggestion
- Category: Stylistic Issues

<br>

## Rule Options

The rule does not have any configuration options.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


<br>

## Usage Examples

> The following examples are generated automatically from the actual unit tests within the plugin, so you can be assured that their behavior is accurate based on the current commit.

<br>

<details>
<summary>❌ - Toggle examples of <strong>incorrect</strong> code for this rule</summary>

<br>

#### Custom Config

```json
{
"rules": {
"@angular-eslint/template/no-restricted-syntax": [
"error",
"Interpolation"
]
}
}
```

<br>

#### ❌ Invalid Code

```html
<article>{{readSomethingPlease}}</article>
~~~~~~~~~~~~~~~~~~~~~~~
```

<br>

---

<br>

#### Custom Config

```json
{
"rules": {
"@angular-eslint/template/no-restricted-syntax": [
"error",
{
"selector": "Element[name='button']:not(:has(:matches(BoundAttribute, TextAttribute)[name='type']))",
"message": "Missing an explicit type attribute for button"
}
]
}
}
```

<br>

#### ❌ Invalid Code

```html
<button>Click me!</button>
~~~~~~~~~~~~~~~~~~~~~~~~~~
```

<br>

---

<br>

#### Custom Config

```json
{
"rules": {
"@angular-eslint/template/no-restricted-syntax": [
"error",
{
"selector": "Element[name='button'] :matches(BoundAttribute, TextAttribute)[name='type'][value!=/^(button|reset|submit)$/]"
}
]
}
}
```

<br>

#### ❌ Invalid Code

```html
<button type="invalidType">Click me!</button>
~~~~~~~~~~~~~~~~~~
```

<br>

---

<br>

#### Custom Config

```json
{
"rules": {
"@angular-eslint/template/no-restricted-syntax": [
"error",
"BoundAttribute[name=\"ngClass\"]"
]
}
}
```

<br>

#### ❌ Invalid Code

```html
<button [ngClass]="classes?.class1">Click me!</button>
~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

</details>

<br>

---

<br>

<details>
<summary>✅ - Toggle examples of <strong>correct</strong> code for this rule</summary>

<br>

#### Custom Config

```json
{
"rules": {
"@angular-eslint/template/no-restricted-syntax": [
"error",
"Binary[operation=/^(==|!=)$/]"
]
}
}
```

<br>

#### ✅ Valid Code

```html
{{ amIUsingStrictEquality === true ? 'Yes' : 'No' }}
```

<br>

---

<br>

#### Custom Config

```json
{
"rules": {
"@angular-eslint/template/no-restricted-syntax": [
"error",
"Template[children.length=0]"
]
}
}
```

<br>

#### ✅ Valid Code

```html
<input [formControl]="formControl">
<textarea [ngModel]="formControl"></textarea>
<ng-template>Child here!</ng-template>
```

<br>

---

<br>

#### Custom Config

```json
{
"rules": {
"@angular-eslint/template/no-restricted-syntax": [
"error",
{
"selector": ":matches(BoundAttribute, TextAttribute)[name='ngClass']"
}
]
}
}
```

<br>

#### ✅ Valid Code

```html
<div [class]="classes"></div>
```

<br>

---

<br>

#### Custom Config

```json
{
"rules": {
"@angular-eslint/template/no-restricted-syntax": [
"error",
{
"message": "Do not use `| json`.",
"selector": "BindingPipe[name='json']"
}
]
}
}
```

<br>

#### ✅ Valid Code

```html
<ng-container *translator="let translator">
{{ translator | async }}
</ng-container>
{{ one ?? other }}
```

</details>

<br>
1 change: 1 addition & 0 deletions packages/eslint-plugin-template/src/configs/all.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@angular-eslint/template/no-duplicate-attributes": "error",
"@angular-eslint/template/no-negated-async": "error",
"@angular-eslint/template/no-positive-tabindex": "error",
"@angular-eslint/template/no-restricted-syntax": "error",
"@angular-eslint/template/use-track-by-function": "error"
}
}
4 changes: 4 additions & 0 deletions packages/eslint-plugin-template/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ import noNegatedAsync, {
import noPositiveTabindex, {
RULE_NAME as noPositiveTabindexRuleName,
} from './rules/no-positive-tabindex';
import noRestrictedSyntax, {
RULE_NAME as noRestrictedSyntaxRuleName,
} from './rules/no-restricted-syntax';
import useTrackByFunction, {
RULE_NAME as useTrackByFunctionRuleName,
} from './rules/use-track-by-function';
Expand Down Expand Up @@ -91,6 +94,7 @@ export default {
[noDuplicateAttributesRuleName]: noDuplicateAttributes,
[noNegatedAsyncRuleName]: noNegatedAsync,
[noPositiveTabindexRuleName]: noPositiveTabindex,
[noRestrictedSyntaxRuleName]: noRestrictedSyntax,
[useTrackByFunctionRuleName]: useTrackByFunction,
},
};
Loading
0