UNPKG

react-native-ui-lib

Version:

[![Build Status](https://travis-ci.org/wix/react-native-ui-lib.svg?branch=master)](https://travis-ci.org/wix/react-native-ui-lib) [![npm](https://img.shields.io/npm/v/react-native-ui-lib.svg)](https://www.npmjs.com/package/react-native-ui-lib) [![NPM Down

46 lines (41 loc) 1.28 kB
const utils = require('../utils'); const { findAndReportHardCodedValues, isPropFont } = utils; module.exports = { meta: { docs: { description: 'disallow hard coded font style', category: 'Best Practices', recommended: true, }, messages: { avoidName: 'Please do not use hard coded font style objects.', }, fixable: 'code', schema: [], // no options }, create(context) { function reportAndFixHardCodedFont(node) { if (node.value) { context.report({ node, message: `Found value '${node.value}' in font style prop. Use UILib typography instead of hardcoded font styles.`, }); } } function noHardCodedFont(node) { node.properties.forEach((property) => { if (property.key) { const propName = property.key.name; if (isPropFont(propName)) { findAndReportHardCodedValues(property.value, reportAndFixHardCodedFont, context.getScope()); } } }); } return { 'CallExpression[callee.object.name=StyleSheet][callee.property.name=create] ObjectExpression': node => noHardCodedFont(node), 'JSXAttribute[name.name = style] ObjectExpression': node => noHardCodedFont(node), }; }, };