ember-template-lint
Version:
Linter for Ember or Handlebars templates.
31 lines (29 loc) • 929 B
JavaScript
import Rule from './_base.js';
import { builders as b } from 'ember-template-recast';
import replaceNode from '../helpers/replace-node.js';
export default class NoUnnecessaryCurlyStrings extends Rule {
/**
* @returns {import('./types.js').VisitorReturnType<NoUnnecessaryCurlyStrings>}
*/
visitor() {
return {
MustacheStatement(node, { parentNode, parentKey }) {
if (node.path.type === 'StringLiteral') {
if (this.mode === 'fix') {
if (parentNode.type === 'AttrNode') {
parentNode.quoteType = node.path.quoteType;
}
const newNode = b.text(node.path.original);
replaceNode(node, parentNode, parentKey, newNode);
} else {
this.log({
node,
message: 'Unnecessary curly braces around string',
isFixable: true,
});
}
}
},
};
}
}