Ignore:
Timestamp:
12/12/24 17:06:06 (5 weeks ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Parents:
d565449
Message:

Pred finalna verzija

File:
1 edited

Legend:

Unmodified
Added
Removed
  • imaps-frontend/node_modules/eslint-plugin-react/lib/rules/no-string-refs.js

    rd565449 r0c6b92a  
    99const docsUrl = require('../util/docsUrl');
    1010const report = require('../util/report');
     11const testReactVersion = require('../util/version').testReactVersion;
    1112
    1213// ------------------------------------------------------------------------------
     
    4344
    4445  create(context) {
     46    const checkRefsUsage = testReactVersion(context, '< 18.3.0'); // `this.refs` is writable in React 18.3.0 and later, see https://github.com/facebook/react/pull/28867
    4547    const detectTemplateLiterals = context.options[0] ? context.options[0].noTemplateLiterals : false;
    4648    /**
    4749     * Checks if we are using refs
    4850     * @param {ASTNode} node The AST node being checked.
    49      * @returns {Boolean} True if we are using refs, false if not.
     51     * @returns {boolean} True if we are using refs, false if not.
    5052     */
    5153    function isRefsUsage(node) {
     
    6062     * Checks if we are using a ref attribute
    6163     * @param {ASTNode} node The AST node being checked.
    62      * @returns {Boolean} True if we are using a ref attribute, false if not.
     64     * @returns {boolean} True if we are using a ref attribute, false if not.
    6365     */
    6466    function isRefAttribute(node) {
    65       return !!(
    66         node.type === 'JSXAttribute'
    67         && node.name
    68         && node.name.name === 'ref'
    69       );
     67      return node.type === 'JSXAttribute'
     68        && !!node.name
     69        && node.name.name === 'ref';
    7070    }
    7171
     
    7373     * Checks if a node contains a string value
    7474     * @param {ASTNode} node The AST node being checked.
    75      * @returns {Boolean} True if the node contains a string value, false if not.
     75     * @returns {boolean} True if the node contains a string value, false if not.
    7676     */
    7777    function containsStringLiteral(node) {
    78       return !!(
    79         node.value
     78      return !!node.value
    8079        && node.value.type === 'Literal'
    81         && typeof node.value.value === 'string'
    82       );
     80        && typeof node.value.value === 'string';
    8381    }
    8482
     
    8684     * Checks if a node contains a string value within a jsx expression
    8785     * @param {ASTNode} node The AST node being checked.
    88      * @returns {Boolean} True if the node contains a string value within a jsx expression, false if not.
     86     * @returns {boolean} True if the node contains a string value within a jsx expression, false if not.
    8987     */
    9088    function containsStringExpressionContainer(node) {
    91       return !!(
    92         node.value
     89      return !!node.value
    9390        && node.value.type === 'JSXExpressionContainer'
    9491        && node.value.expression
    9592        && ((node.value.expression.type === 'Literal' && typeof node.value.expression.value === 'string')
    96         || (node.value.expression.type === 'TemplateLiteral' && detectTemplateLiterals))
    97       );
     93        || (node.value.expression.type === 'TemplateLiteral' && detectTemplateLiterals));
    9894    }
    9995
    10096    return {
    10197      MemberExpression(node) {
    102         if (isRefsUsage(node)) {
     98        if (checkRefsUsage && isRefsUsage(node)) {
    10399          report(context, messages.thisRefsDeprecated, 'thisRefsDeprecated', {
    104100            node,
     
    106102        }
    107103      },
     104
    108105      JSXAttribute(node) {
    109106        if (
Note: See TracChangeset for help on using the changeset viewer.