<commit_before>/**
 * Copyright (c) 2016-present, <NAME>.
 * Copyright (c) 2015-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @providesModule StyleSheetValidation
 * @flow
 */

import ImageStylePropTypes from '../Image/ImageStylePropTypes';
import TextInputStylePropTypes from '../TextInput/TextInputStylePropTypes';
import TextStylePropTypes from '../Text/TextStylePropTypes';
import ViewStylePropTypes from '../View/ViewStylePropTypes';
import warning from 'fbjs/lib/warning';
import { number, oneOf, string } from 'prop-types';

// Hardcoded because this is a legit case but we don't want to load it from
// a private API. We might likely want to unify style sheet creation with how it
// is done in the DOM so this might move into React. I know what I'm doing so
// plz don't fire me.
const ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';

export default class StyleSheetValidation {
  static validateStyleProp(prop: string, style: Object, caller: string) {
    if (process.env.NODE_ENV !== 'production') {
      const isCustomProperty = prop.indexOf('--') === 0;
      if (isCustomProperty) return;

      if (allStylePropTypes[prop] === undefined) {
        const message1 = '"' + prop + '" is not a valid style property.';
        const message2 =
          '\nValid style props: ' +
          JSON.stringify(Object.keys(allStylePropTypes).sort(), null, '  ');
        styleError(message1, style, caller, message2);
      } else {
        const error = allStylePropTypes[prop](
          style,
          prop,
          caller,
          'prop',
          null,
          ReactPropTypesSecret
        );
        if (error) {
          styleError(error.message, style, caller);
        }
      }
    }
  }

  static validateStyle(name: string, styles: Object) {
    if (process.env.NODE_ENV !== 'production') {
      for (const prop in styles[name]) {
        StyleSheetValidation.validateStyleProp(prop, styles[name], 'StyleSheet ' + name);
      }
    }
  }

  static addValidStylePropTypes(stylePropTypes: Object) {
    for (const key in stylePropTypes) {
      allStylePropTypes[key] = stylePropTypes[key];
    }
  }
}<commit_msg>[add] development warning about using '!important' in styles<commit_after>/**
 * Copyright (c) 2016-present, <NAME>.
 * Copyright (c) 2015-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @providesModule StyleSheetValidation
 * @flow
 */

import ImageStylePropTypes from '../Image/ImageStylePropTypes';
import TextInputStylePropTypes from '../TextInput/TextInputStylePropTypes';
import TextStylePropTypes from '../Text/TextStylePropTypes';
import ViewStylePropTypes from '../View/ViewStylePropTypes';
import warning from 'fbjs/lib/warning';
import { number, oneOf, string } from 'prop-types';

// Hardcoded because this is a legit case but we don't want to load it from
// a private API. We might likely want to unify style sheet creation with how it
// is done in the DOM so this might move into React. I know what I'm doing so
// plz don't fire me.
const ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';

export default class StyleSheetValidation {
  static validateStyleProp(prop: string, style: Object, caller: string) {
    if (process.env.NODE_ENV !== 'production') {
      const value = style[prop];

      const isCustomProperty = prop.indexOf('--') === 0;
      if (isCustomProperty) return;

      if (allStylePropTypes[prop] === undefined) {
        const message1 = '"' + prop + '" is not a valid style property.';
        const message2 =
          '\nValid style props: ' +
          JSON.stringify(Object.keys(allStylePropTypes).sort(), null, '  ');
        styleError(message1, style, caller, message2);
      } else if (typeof value === 'string' && value.indexOf('!important') > -1) {
        styleError(
          `Invalid value of "${value}" set on prop "${prop}". Values cannot include "!important"`,
          style,
          caller
        );
      } else {
        const error = allStylePropTypes[prop](
          style,
          prop,
          caller,
          'prop',
          null,
          ReactPropTypesSecret
        );
        if (error) {
          styleError(error.message, style, caller);
        }
      }
    }
  }

  static validateStyle(name: string, styles: Object) {
    if (process.env.NODE_ENV !== 'production') {
      for (const prop in styles[name]) {
        StyleSheetValidation.validateStyleProp(prop, styles[name], 'StyleSheet ' + name);
      }
    }
  }

  static addValidStylePropTypes(stylePropTypes: Object) {
    for (const key in stylePropTypes) {
      allStylePropTypes[key] = stylePropTypes[key];
    }
  }
}
{'fraction_non_alphanumeric': 0.11206719934439664, 'fraction_numerical': 0.005531653349723417, 'mean_word_length': 2.97557003257329, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3836940', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1368, 'n_words': 435}