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

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[d565449]1/**
2 * @fileoverview Enforce no duplicate props
3 * @author Markus Ånöstam
4 */
5
6'use strict';
7
8const has = require('hasown');
9const docsUrl = require('../util/docsUrl');
10const report = require('../util/report');
11
12// ------------------------------------------------------------------------------
13// Rule Definition
14// ------------------------------------------------------------------------------
15
16const messages = {
17 noDuplicateProps: 'No duplicate props allowed',
18};
19
20/** @type {import('eslint').Rule.RuleModule} */
21module.exports = {
22 meta: {
23 docs: {
24 description: 'Disallow duplicate properties in JSX',
25 category: 'Possible Errors',
26 recommended: true,
27 url: docsUrl('jsx-no-duplicate-props'),
28 },
29
30 messages,
31
32 schema: [{
33 type: 'object',
34 properties: {
35 ignoreCase: {
36 type: 'boolean',
37 },
38 },
39 additionalProperties: false,
40 }],
41 },
42
43 create(context) {
44 const configuration = context.options[0] || {};
45 const ignoreCase = configuration.ignoreCase || false;
46
47 return {
48 JSXOpeningElement(node) {
49 const props = {};
50
51 node.attributes.forEach((decl) => {
52 if (decl.type === 'JSXSpreadAttribute') {
53 return;
54 }
55
56 let name = decl.name.name;
57
58 if (typeof name !== 'string') {
59 return;
60 }
61
62 if (ignoreCase) {
63 name = name.toLowerCase();
64 }
65
66 if (has(props, name)) {
67 report(context, messages.noDuplicateProps, 'noDuplicateProps', {
68 node: decl,
69 });
70 } else {
71 props[name] = 1;
72 }
73 });
74 },
75 };
76 },
77};
Note: See TracBrowser for help on using the repository browser.