2 * @fileoverview Prevent usage of unknown DOM property
3 * @author Yannick Croissant
7 // ------------------------------------------------------------------------------
9 // ------------------------------------------------------------------------------
11 var UNKNOWN_MESSAGE = 'Unknown property \'{{name}}\' found, use \'{{standardName}}\' instead';
13 var DOM_ATTRIBUTE_NAMES = {
14 'accept-charset': 'acceptCharset',
17 'http-equiv': 'httpEquiv'
20 var DOM_PROPERTY_NAMES = [
21 'acceptCharset', 'accessKey', 'allowFullScreen', 'allowTransparency', 'autoComplete', 'autoFocus', 'autoPlay',
22 'cellPadding', 'cellSpacing', 'charSet', 'classID', 'className', 'colSpan', 'contentEditable', 'contextMenu',
23 'crossOrigin', 'dateTime', 'encType', 'formAction', 'formEncType', 'formMethod', 'formNoValidate', 'formTarget',
24 'frameBorder', 'hrefLang', 'htmlFor', 'httpEquiv', 'marginHeight', 'marginWidth', 'maxLength', 'mediaGroup',
25 'noValidate', 'radioGroup', 'readOnly', 'rowSpan', 'spellCheck', 'srcDoc', 'srcSet', 'tabIndex', 'useMap',
26 'itemProp', 'itemScope', 'itemType', 'itemRef', 'itemId'
29 // ------------------------------------------------------------------------------
31 // ------------------------------------------------------------------------------
34 * Checks if a node name match the JSX tag convention.
35 * @param {String} name - Name of the node to check.
36 * @returns {boolean} Whether or not the node name match the JSX tag convention.
38 var tagConvention = /^[a-z]|\-/;
39 function isTagName(name) {
40 return tagConvention.test(name);
44 * Get the standard name of the attribute.
45 * @param {String} name - Name of the attribute.
46 * @returns {String} The standard name of the attribute.
48 function getStandardName(name) {
49 if (DOM_ATTRIBUTE_NAMES[name]) {
50 return DOM_ATTRIBUTE_NAMES[name];
53 var found = DOM_PROPERTY_NAMES.some(function(element, index) {
55 return element.toLowerCase() === name;
57 return found ? DOM_PROPERTY_NAMES[i] : null;
60 // ------------------------------------------------------------------------------
62 // ------------------------------------------------------------------------------
64 module.exports = function(context) {
68 JSXAttribute: function(node) {
69 var standardName = getStandardName(node.name.name);
70 if (!isTagName(node.parent.name.name) || !standardName) {
73 context.report(node, UNKNOWN_MESSAGE, {
75 standardName: standardName