safe-string-coercion-test.internal.js — react Source File
Architecture documentation for safe-string-coercion-test.internal.js, a javascript file in the react codebase.
Entity Profile
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/
'use strict';
const rule = require('../safe-string-coercion');
const {RuleTester} = require('eslint');
RuleTester.setDefaultConfig({
parser: require.resolve('babel-eslint'),
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
},
});
const ruleTester = new RuleTester();
const missingDevCheckMessage =
'Missing DEV check before this string coercion.' +
' Check should be in this format:\n' +
' if (__DEV__) {\n' +
' checkXxxxxStringCoercion(value);\n' +
' }';
const prevStatementNotDevCheckMessage =
'The statement before this coercion must be a DEV check in this format:\n' +
' if (__DEV__) {\n' +
' checkXxxxxStringCoercion(value);\n' +
' }';
const message =
"Using `'' + value` or `value + ''` is fast to coerce strings, but may throw." +
' For prod code, add a DEV check from shared/CheckStringCoercion immediately' +
' before this coercion.' +
' For non-prod code and prod error handling, use `String(value)` instead.';
ruleTester.run('eslint-rules/safe-string-coercion', rule, {
valid: [
{
code: 'String(obj)',
options: [{isProductionUserAppCode: false}],
},
'String(obj)',
"'a' + obj",
`
function getValueForAttribute(
node,
name,
expected
) {
if (__DEV__) {
var value = node.getAttribute(name);
if (__DEV__) {
checkAttributeStringCoercion(expected, name);
}
// ... (228 more lines)
Source
Frequently Asked Questions
What does safe-string-coercion-test.internal.js do?
safe-string-coercion-test.internal.js is a source file in the react codebase, written in javascript.
Where is safe-string-coercion-test.internal.js in the architecture?
safe-string-coercion-test.internal.js is located at scripts/eslint-rules/__tests__/safe-string-coercion-test.internal.js (directory: scripts/eslint-rules/__tests__).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free