Skip to content

Commit

Permalink
fix(element-type): add autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
d0whc3r committed Sep 16, 2019
1 parent 5c52b74 commit 49d6b1b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/rules/element-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const rule: Rule.RuleModule = {

create(context): Rule.RuleListener {
const stencil = stencilComponentContext();
const parserServices = context.parserServices;

function parseTag(tag: string) {
let result = tag[0].toUpperCase() + tag.slice(1);
Expand All @@ -34,9 +35,16 @@ const rule: Rule.RuleModule = {
const [{ tag }] = parseDecorator(component);
const parsedTag = `HTML${parseTag(tag)}Element`;
if (tagType !== parsedTag) {
const originalNode = parserServices.esTreeNodeToTSNodeMap.get(node.parent);
const text = originalNode.getFullText();
const type = originalNode.type.typeName.escapedText;
context.report({
node: node,
message: `@Element type is not matching tag for component (${parsedTag})`
node: node.parent,
message: `@Element type is not matching tag for component (${parsedTag})`,
fix(fixer) {
const result = text.replace(`: ${type}`, `: ${parsedTag}`);
return fixer.replaceText(node, result);
}
});
}
}
Expand Down

0 comments on commit 49d6b1b

Please sign in to comment.