Skip to content

Instantly share code, notes, and snippets.

@acestudiooleg
Created December 24, 2018 14:02
Show Gist options
  • Select an option

  • Save acestudiooleg/435fcb90ae3424a07efc0b208673d0ab to your computer and use it in GitHub Desktop.

Select an option

Save acestudiooleg/435fcb90ae3424a07efc0b208673d0ab to your computer and use it in GitHub Desktop.
Ember Template linter - rules for angle bracket components
'use strict';
const linter = require('ember-template-lint');
const Rule = linter.Rule;
const helpers = linter.ASTHelpers;
const tagNames = [
"a",
"abbr",
"acronym",
"address",
"applet",
"area",
"article",
"aside",
"audio",
"b",
"base",
"basefont",
"bdi",
"bdo",
"bgsound",
"big",
"blink",
"blockquote",
"br",
"button",
"canvas",
"caption",
"center",
"cite",
"code",
"col",
"colgroup",
"command",
"content",
"data",
"datalist",
"dd",
"del",
"details",
"dfn",
"dialog",
"dir",
"div",
"dl",
"dt",
"element",
"em",
"embed",
"fieldset",
"figcaption",
"figure",
"font",
"footer",
"form",
"frame",
"frameset",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"head",
"header",
"hgroup",
"hr",
"html",
"i",
"iframe",
"image",
"img",
"input",
"ins",
"isindex",
"kbd",
"keygen",
"label",
"legend",
"li",
"link",
"listing",
"main",
"map",
"mark",
"marquee",
"math",
"menu",
"menuitem",
"meta",
"meter",
"multicol",
"nav",
"nextid",
"nobr",
"noembed",
"noframes",
"noscript",
"object",
"ol",
"optgroup",
"option",
"output",
"p",
"param",
"picture",
"plaintext",
"pre",
"progress",
"q",
"rb",
"rbc",
"rp",
"rt",
"rtc",
"ruby",
"s",
"samp",
"script",
"section",
"select",
"shadow",
"slot",
"small",
"source",
"spacer",
"span",
"strike",
"strong",
"style",
"sub",
"summary",
"sup",
"svg",
"table",
"tbody",
"td",
"template",
"textarea",
"tfoot",
"th",
"thead",
"time",
"title",
"tr",
"track",
"tt",
"u",
"ul",
"var",
"video",
"wbr",
"xmp"
];
class NoTagNamesAsVariable extends Rule {
visitor() {
return {
BlockStatement(node) {
if (!helpers.isTextNode(node)) {
(node.program && node.program.blockParams || []).forEach(prohName => {
if (tagNames.indexOf(prohName) !== -1) {
this.log({
message: `{{#${node.path.original} ... as |${node.program.blockParams.join(' ')}|}} expression has prohibited name -> "${prohName}";`,
line: node.program.loc && node.program.loc.start.line,
column: node.program.loc && node.program.loc.start.column,
source: this.sourceForNode(node)
});
}
});
}
}
};
}
};
module.exports = {
// Name of plugin
name: 'no-tag-names-as-variable-plugin',
// Define rules for this plugin. Each path should map to a plugin rule
rules: {
'no-tag-names-as-variable': NoTagNamesAsVariable
}
};
/* eslint-env node */
'use strict';
//rules https://github.com/ember-template-lint/ember-template-lint/blob/master/lib/rules/index.js
module.exports = {
extends: 'recommended',
plugins: ['./.no-tag-names-as-variable'],
rules: {
'block-indentation': 'tab',
'no-invalid-interactive': false,
'no-bare-strings': false,
'no-tag-names-as-variable': true
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment