All files / src/rules/css-property-no-unknown index.js

96% Statements 24/25
93.75% Branches 15/16
100% Functions 4/4
96% Lines 24/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83                          3x   3x 30x     3x     39x 39x                             39x       39x 55x   55x 5x     50x 1x     49x 1x     48x 2x     46x 3x     43x 27x     16x 1x     15x                  
import { allCSS2RNProps } from "react-native-known-styling-properties";
import { utils } from "stylelint";
import {
  isCustomProperty,
  isExportBlock,
  isStandardSyntaxDeclaration,
  isStandardSyntaxProperty,
  isString,
  kebabCase,
  namespace,
  optionsMatches
} from "../../utils";
 
export const ruleName = namespace("css-property-no-unknown");
 
export const messages = utils.ruleMessages(ruleName, {
  rejected: (property) => `Unexpected unknown property "${property}"`
});
 
const props = allCSS2RNProps.map(kebabCase);
 
export default function (actual, options) {
  return function (root, result) {
    const validOptions = utils.validateOptions(
      result,
      ruleName,
      {
        actual
      },
      {
        actual: options,
        possible: {
          ignoreProperties: [isString]
        },
        optional: true
      }
    );
 
    Iif (!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;
      }
 
      if (/^-styled-mixin\d+/.test(prop.toLowerCase())) {
        return;
      }
 
      utils.report({
        message: messages.rejected(prop),
        node: decl,
        result,
        ruleName
      });
    });
  };
}