feat: add no-clr-alert rule to detect the usage of Clarity Angular alerts #5279
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lgtm. I had a couple of questions but nothing that seems like it should block.
return { | ||
'HTMLElement[tagName="clr-alert"]'(node: HTMLElement): void { | ||
context.report({ | ||
node: node as any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there issues that prevent this from being typed as HTMLElement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, the HTMLElement
type is incompatible with the TSESTree
type as defined by the @typescript/eslint
library.
const classes = classNode?.attributeValue?.value?.split(' ') || []; | ||
if (classes.includes('alert')) { | ||
context.report({ | ||
node: node as any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same questionas line #30.
@@ -1,24 +1,14 @@ | |||
import { ESLintUtils, TSESTree } from '@typescript-eslint/experimental-utils'; | |||
import { JSDOM } from 'jsdom'; | |||
import { SourceLocation } from '@typescript-eslint/eslint-plugin'; | |||
import { getDecoratorPropertyValue } from '../utils'; | |||
import { calculateLocation, getDecoratorTemplate } from '../utils'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
output?: string; | ||
} | ||
|
||
interface Location { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth using this type in the calculateLocation
utility function as something named
ElementLocation || TemplateLocation
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking into this for a while, I've found an appropriate type exported by @typescript-eslint
and used it instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…erts Signed-off-by: Stanimira Vlaeva <svlaeva@vmware.com>
651982d
to
03a7dee
Compare
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The usage of Clarity Angular alerts is not being detected.
What is the new behavior?
The ESLint plugin (
@clr/eslint-clarity-migration
) now has a rule detecting the usage of Clarity Angular alerts.Does this PR introduce a breaking change?
Other information