Files
old-slucajna-televizija/web/node_modules/eslint-plugin-react/lib/rules/jsx-no-literals.js
2017-10-16 11:19:46 +02:00

57 lines
1.3 KiB
JavaScript
Executable File

/**
* @fileoverview Prevent using string literals in React component definition
* @author Caleb Morris
*/
'use strict';
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description: 'Prevent using string literals in React component definition',
category: 'Stylistic Issues',
recommended: false
},
schema: [{
type: 'object',
properties: {},
additionalProperties: false
}]
},
create: function(context) {
function reportLiteralNode(node) {
context.report({
node: node,
message: 'Missing JSX expression container around literal string'
});
}
// --------------------------------------------------------------------------
// Public
// --------------------------------------------------------------------------
return {
Literal: function(node) {
if (
!/^[\s]+$/.test(node.value) &&
node.parent &&
node.parent.type !== 'JSXExpressionContainer' &&
node.parent.type !== 'JSXAttribute' &&
node.parent.type.indexOf('JSX') !== -1
) {
reportLiteralNode(node);
}
}
};
}
};