stylelint-taro-rn
Version:
A collection of React Native specific rules for stylelint
57 lines (56 loc) • 1.63 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
exports.ruleName = exports.messages = void 0;
var _reactNativeKnownStylingProperties = require("react-native-known-styling-properties");
var _stylelint = require("stylelint");
var _utils = require("../../utils");
const ruleName = (0, _utils.namespace)('style-property-no-unknown');
exports.ruleName = ruleName;
const messages = _stylelint.utils.ruleMessages(ruleName, {
rejected: property => `无效的 React Native 样式属性 "${property}"`
});
exports.messages = messages;
const props = _reactNativeKnownStylingProperties.allProps.map(_utils.kebabCase);
function _default(actual, options) {
return function (root, result) {
const validOptions = _stylelint.utils.validateOptions(result, ruleName, {
actual
}, {
actual: options,
possible: {
ignoreProperties: [_utils.isString]
},
optional: true
});
if (!validOptions) {
return;
}
root.walkDecls(decl => {
const prop = decl.prop;
if (!(0, _utils.isStandardSyntaxProperty)(prop)) {
return;
}
if (!(0, _utils.isStandardSyntaxDeclaration)(decl)) {
return;
}
if ((0, _utils.isCustomProperty)(prop)) {
return;
}
if ((0, _utils.optionsMatches)(options, 'ignoreProperties', prop)) {
return;
}
if (props.indexOf(prop.toLowerCase()) !== -1) {
return;
}
_stylelint.utils.report({
message: messages.rejected(prop),
node: decl,
result,
ruleName
});
});
};
}
;