react-scripts
Version:
Configuration and scripts for Create React App.
38 lines (28 loc) • 789 B
JavaScript
/**
* @fileoverview Enforce html element has lang prop.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
import { elementType, getProp, getPropValue } from 'jsx-ast-utils';
const errorMessage = '<html> elements must have the lang prop.';
module.exports = context => ({
JSXOpeningElement: node => {
const type = elementType(node);
if (type && type !== 'html') {
return;
}
const lang = getPropValue(getProp(node.attributes, 'lang'));
if (lang) {
return;
}
context.report({
node,
message: errorMessage,
});
},
});
module.exports.schema = [
{ type: 'object' },
];