UNPKG

stylelint-taro-rn

Version:

A collection of React Native specific rules for stylelint

63 lines (60 loc) 2.21 kB
import { allCSS2RNProps } from 'react-native-known-styling-properties'; import stylelint from 'stylelint'; import { isCustomProperty } from '../../utils/isCustomProperty.js'; import { isExportBlock } from '../../utils/isExportBlock.js'; import { isStandardSyntaxDeclaration } from '../../utils/isStandardSyntaxDeclaration.js'; import { isStandardSyntaxProperty } from '../../utils/isStandardSyntaxProperty.js'; import { isString } from '../../utils/isString.js'; import { kebabCase } from '../../utils/kebabCase.js'; import { namespace } from '../../utils/namespace.js'; import { optionsMatches } from '../../utils/optionsMatches.js'; const ruleName = namespace('css-property-no-unknown'); const messages = stylelint.utils.ruleMessages(ruleName, { rejected: (property) => `无效的 React Native 样式属性 "${property}"` }); const props = allCSS2RNProps.map(kebabCase); function cssPropertyNoUnknown (actual, options) { return function (root, result) { const validOptions = stylelint.utils.validateOptions(result, ruleName, { actual }, { actual: options, possible: { ignoreProperties: [isString] }, optional: true }); if (!validOptions) { return; } root.walkDecls((decl) => { const prop = decl.prop; if (!isStandardSyntaxProperty(prop)) { return; } if (!isStandardSyntaxDeclaration(decl)) { return; } if (isCustomProperty(prop)) { return; } if (isExportBlock(decl.parent)) { return; } if (optionsMatches(options, 'ignoreProperties', prop)) { return; } if (props.indexOf(prop.toLowerCase()) !== -1) { return; } stylelint.utils.report({ message: messages.rejected(prop), node: decl, result, ruleName }); }); }; } export { cssPropertyNoUnknown as default, messages, ruleName }; //# sourceMappingURL=index.js.map