Skip to content

Commit

Permalink
fix(eslint-plugin): [use-component-selector] applies to template lite…
Browse files Browse the repository at this point in the history
…rals (#1468)
  • Loading branch information
hyperupcall committed Sep 17, 2023
1 parent b1d07bc commit cbe60d3
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
58 changes: 58 additions & 0 deletions packages/eslint-plugin/docs/rules/use-component-selector.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,64 @@ class Test {}
class Test {}
```

<br>

---

<br>

#### Default Config

```json
{
"rules": {
"@angular-eslint/use-component-selector": [
"error"
]
}
}
```

<br>

#### ✅ Valid Code

```ts
@Component({
selector: "sg-bar-foo"
})
class Test {}
```

<br>

---

<br>

#### Default Config

```json
{
"rules": {
"@angular-eslint/use-component-selector": [
"error"
]
}
}
```

<br>

#### ✅ Valid Code

```ts
@Component({
selector: `sg-bar-foo`
})
class Test {}
```

</details>

<br>
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/use-component-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export default createESLintRule<Options, MessageIds>({

if (
selector &&
ASTUtils.isStringLiteral(selector) &&
selector.value.length
((ASTUtils.isStringLiteral(selector) && selector.value.length) ||
ASTUtils.isTemplateLiteral(selector))
) {
return;
}
Expand Down
15 changes: 15 additions & 0 deletions packages/eslint-plugin/tests/rules/use-component-selector/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@ import type { MessageIds } from '../../../src/rules/use-component-selector';
const messageId: MessageIds = 'useComponentSelector';

export const valid = [
// It should succeed with single quotes
`
@Component({
selector: 'sg-bar-foo'
})
class Test {}
`,
// It should succeed with double quotes
`
@Component({
selector: "sg-bar-foo"
})
class Test {}
`,
// It should succeed with template literals
`
@Component({
selector: \`sg-bar-foo\`
})
class Test {}
`,
];

Expand Down

0 comments on commit cbe60d3

Please sign in to comment.