eslint-plugin-react
Advanced tools
| /** | ||
| * @fileoverview Enforce no duplicate props | ||
| * @author Markus Ånöstam | ||
| */ | ||
| 'use strict'; | ||
| // ------------------------------------------------------------------------------ | ||
| // Rule Definition | ||
| // ------------------------------------------------------------------------------ | ||
| module.exports = function (context) { | ||
| var configuration = context.options[0] || {}; | ||
| var ignoreCase = configuration.ignoreCase || false; | ||
| return { | ||
| JSXOpeningElement: function (node) { | ||
| var props = {}; | ||
| node.attributes.forEach(function(decl) { | ||
| if (decl.type === 'JSXSpreadAttribute') { | ||
| return; | ||
| } | ||
| var name = decl.name.name; | ||
| if (ignoreCase) { | ||
| name = name.toLowerCase(); | ||
| } | ||
| if (props.hasOwnProperty(name)) { | ||
| context.report(decl, 'No duplicate props allowed'); | ||
| } else { | ||
| props[name] = 1; | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
| }; | ||
| module.exports.schema = [{ | ||
| type: 'object', | ||
| properties: { | ||
| ignoreCase: { | ||
| type: 'boolean' | ||
| } | ||
| }, | ||
| additionalProperties: false | ||
| }]; |
+14
-0
@@ -0,1 +1,15 @@ | ||
| 3.0.0 / 2015-07-21 | ||
| ================== | ||
| * add jsx-no-duplicate-props rule ([#161][] @hummlas) | ||
| * add allowMultiline option to the jsx-curly-spacing rule ([#156][] @mathieumg) | ||
| * breaking in jsx-curly-spacing braces spanning multiple lines are now allowed with never option ([#156][] @mathieumg) | ||
| * fix multiple var and destructuring handling in props-types ([#159][]) | ||
| * fix crash when retrieving propType name ([#163][]) | ||
| [#161]: https://github.com/yannickcr/eslint-plugin-react/pull/161 | ||
| [#156]: https://github.com/yannickcr/eslint-plugin-react/pull/156 | ||
| [#159]: https://github.com/yannickcr/eslint-plugin-react/issues/159 | ||
| [#163]: https://github.com/yannickcr/eslint-plugin-react/issues/163 | ||
| 2.7.1 / 2015-07-16 | ||
@@ -2,0 +16,0 @@ ================== |
+4
-2
@@ -24,3 +24,4 @@ 'use strict'; | ||
| 'sort-comp': require('./lib/rules/sort-comp'), | ||
| 'require-extension': require('./lib/rules/require-extension') | ||
| 'require-extension': require('./lib/rules/require-extension'), | ||
| 'jsx-no-duplicate-props': require('./lib/rules/jsx-no-duplicate-props') | ||
| }, | ||
@@ -47,4 +48,5 @@ rulesConfig: { | ||
| 'sort-comp': 0, | ||
| 'require-extension': 0 | ||
| 'require-extension': 0, | ||
| 'jsx-no-duplicate-props': 0 | ||
| } | ||
| }; |
@@ -13,2 +13,3 @@ /** | ||
| var spaced = context.options[0] === 'always'; | ||
| var multiline = context.options[1] ? context.options[1].allowMultiline : true; | ||
@@ -20,5 +21,15 @@ // -------------------------------------------------------------------------- | ||
| /** | ||
| * Determines whether two adjacent tokens are have whitespace between them. | ||
| * Determines whether two adjacent tokens have a newline between them. | ||
| * @param {Object} left - The left token object. | ||
| * @param {Object} right - The right token object. | ||
| * @returns {boolean} Whether or not there is a newline between the tokens. | ||
| */ | ||
| function isMultiline(left, right) { | ||
| return left.loc.start.line !== right.loc.start.line; | ||
| } | ||
| /** | ||
| * Determines whether two adjacent tokens have whitespace between them. | ||
| * @param {Object} left - The left token object. | ||
| * @param {Object} right - The right token object. | ||
| * @returns {boolean} Whether or not there is space between the tokens. | ||
@@ -31,2 +42,24 @@ */ | ||
| /** | ||
| * Reports that there shouldn't be a newline after the first token | ||
| * @param {ASTNode} node - The node to report in the event of an error. | ||
| * @param {Token} token - The token to use for the report. | ||
| * @returns {void} | ||
| */ | ||
| function reportNoBeginningNewline(node, token) { | ||
| context.report(node, token.loc.start, | ||
| 'There should be no newline after \'' + token.value + '\''); | ||
| } | ||
| /** | ||
| * Reports that there shouldn't be a newline before the last token | ||
| * @param {ASTNode} node - The node to report in the event of an error. | ||
| * @param {Token} token - The token to use for the report. | ||
| * @returns {void} | ||
| */ | ||
| function reportNoEndingNewline(node, token) { | ||
| context.report(node, token.loc.start, | ||
| 'There should be no newline before \'' + token.value + '\''); | ||
| } | ||
| /** | ||
| * Reports that there shouldn't be a space after the first token | ||
@@ -85,12 +118,24 @@ * @param {ASTNode} node - The node to report in the event of an error. | ||
| function validateBraceSpacing(node, first, second, penultimate, last) { | ||
| if (spaced && !isSpaced(first, second)) { | ||
| reportRequiredBeginningSpace(node, first); | ||
| if (spaced) { | ||
| if (!isSpaced(first, second)) { | ||
| reportRequiredBeginningSpace(node, first); | ||
| } else if (!multiline && isMultiline(first, second)) { | ||
| reportNoBeginningNewline(node, first); | ||
| } | ||
| if (!isSpaced(penultimate, last)) { | ||
| reportRequiredEndingSpace(node, last); | ||
| } else if (!multiline && isMultiline(penultimate, last)) { | ||
| reportNoEndingNewline(node, last); | ||
| } | ||
| return; | ||
| } | ||
| if (!spaced && isSpaced(first, second)) { | ||
| // "never" setting if we get here. | ||
| if (isSpaced(first, second) && !(multiline && isMultiline(first, second))) { | ||
| reportNoBeginningSpace(node, first); | ||
| } | ||
| if (spaced && !isSpaced(penultimate, last)) { | ||
| reportRequiredEndingSpace(node, last); | ||
| } | ||
| if (!spaced && isSpaced(penultimate, last)) { | ||
| if (isSpaced(penultimate, last) && !(multiline && isMultiline(penultimate, last))) { | ||
| reportNoEndingSpace(node, last); | ||
@@ -118,2 +163,10 @@ } | ||
| enum: ['always', 'never'] | ||
| }, { | ||
| type: 'object', | ||
| properties: { | ||
| allowMultiline: { | ||
| type: 'boolean' | ||
| } | ||
| }, | ||
| additionalProperties: false | ||
| }]; |
@@ -355,8 +355,8 @@ /** | ||
| } else if ( | ||
| node.parent.parent.declarations && | ||
| node.parent.parent.declarations[0].id.properties && | ||
| getKeyValue(node.parent.parent.declarations[0].id.properties[0]) | ||
| node.parent.id && | ||
| node.parent.id.properties && | ||
| getKeyValue(node.parent.id.properties[0]) | ||
| ) { | ||
| type = 'destructuring'; | ||
| properties = node.parent.parent.declarations[0].id.properties; | ||
| properties = node.parent.id.properties; | ||
| } | ||
@@ -465,3 +465,3 @@ break; | ||
| } | ||
| if (propTypes) { | ||
| if (propTypes && propTypes.property) { | ||
| curDeclaredPropTypes[propTypes.property.name] = | ||
@@ -468,0 +468,0 @@ buildReactDeclarationTypes(propTypes.parent.right); |
+1
-1
| { | ||
| "name": "eslint-plugin-react", | ||
| "version": "2.7.1", | ||
| "version": "3.0.0", | ||
| "author": "Yannick Croissant <yannick.croissant+npm@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "React specific linting rules for ESLint", |
+2
-0
@@ -47,2 +47,3 @@ ESLint-plugin-React | ||
| "react/jsx-boolean-value": 1, | ||
| "react/jsx-no-duplicate-props": 1, | ||
| "react/jsx-no-undef": 1, | ||
@@ -74,2 +75,3 @@ "react/jsx-quotes": 1, | ||
| * [jsx-curly-spacing](docs/rules/jsx-curly-spacing.md): Enforce or disallow spaces inside of curly braces in JSX attributes | ||
| * [jsx-no-duplicate-props](docs/rules/jsx-no-duplicate-props.md): Prevent duplicate props in JSX | ||
| * [jsx-no-undef](docs/rules/jsx-no-undef.md): Disallow undeclared variables in JSX | ||
@@ -76,0 +78,0 @@ * [jsx-quotes](docs/rules/jsx-quotes.md): Enforce quote style for JSX attributes |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
97060
3.91%28
3.7%2384
3.83%125
1.63%