source: frontend/node_modules/eslint-plugin-react/lib/rules/jsx-props-no-spread-multi.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/**
2 * @fileoverview Prevent JSX prop spreading the same expression multiple times
3 * @author Simon Schick
4 */
5
6'use strict';
7
8const docsUrl = require('../util/docsUrl');
9const report = require('../util/report');
10
11// ------------------------------------------------------------------------------
12// Rule Definition
13// ------------------------------------------------------------------------------
14
15const messages = {
16 noMultiSpreading: 'Spreading the same expression multiple times is forbidden',
17};
18
19/** @type {import('eslint').Rule.RuleModule} */
20module.exports = {
21 meta: {
22 docs: {
23 description: 'Disallow JSX prop spreading the same identifier multiple times',
24 category: 'Best Practices',
25 recommended: false,
26 url: docsUrl('jsx-props-no-spread-multi'),
27 },
28 messages,
29 },
30
31 create(context) {
32 return {
33 JSXOpeningElement(node) {
34 const spreads = node.attributes.filter(
35 (attr) => attr.type === 'JSXSpreadAttribute'
36 && attr.argument.type === 'Identifier'
37 );
38 if (spreads.length < 2) {
39 return;
40 }
41 // We detect duplicate expressions by their identifier
42 const identifierNames = new Set();
43 spreads.forEach((spread) => {
44 if (identifierNames.has(spread.argument.name)) {
45 report(context, messages.noMultiSpreading, 'noMultiSpreading', {
46 node: spread,
47 });
48 }
49 identifierNames.add(spread.argument.name);
50 });
51 },
52 };
53 },
54};
Note: See TracBrowser for help on using the repository browser.