Skip to content

Commit 64e837b

Browse files
Diana SuvorovaDiana Suvorova
authored andcommitted
Merge branch 'master' into noUsedProps
2 parents 430a89f + ac72383 commit 64e837b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+267
-325
lines changed

.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"guard-for-in": 2,
5050
"no-alert": 2,
5151
"no-caller": 2,
52+
"no-confusing-arrow": 2,
5253
"no-div-regex": 2,
5354
"no-else-return": 2,
5455
"no-eq-null": 2,
@@ -81,6 +82,7 @@
8182
"no-void": 0,
8283
"no-warning-comments": 2,
8384
"no-with": 2,
85+
"prefer-arrow-callback": 2,
8486
"radix": 2,
8587
"vars-on-top": 0,
8688
"wrap-iife": 2,
@@ -105,6 +107,9 @@
105107
"indent": [2, 2, {
106108
"SwitchCase": 1
107109
}],
110+
"arrow-body-style": [2, "as-needed"],
111+
"arrow-parens": [2, "as-needed"],
112+
"arrow-spacing": 2,
108113
"brace-style": 2,
109114
"camelcase": 0,
110115
"comma-spacing": 2,

docs/rules/default-props-match-prop-types.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Enforce all defaultProps have a corresponding non-required PropType (default-props-match-prop-types)
1+
# Enforce all defaultProps have a corresponding non-required PropType (react/default-props-match-prop-types)
22

33
This rule aims to ensure that any `defaultProp` has a non-required `PropType` declaration.
44

@@ -154,7 +154,7 @@ NotAComponent.propTypes = {
154154

155155
```js
156156
...
157-
"default-props-match-prop-types": [<enabled>, { "allowRequiredDefaults": <boolean> }]
157+
"react/default-props-match-prop-types": [<enabled>, { "allowRequiredDefaults": <boolean> }]
158158
...
159159
```
160160

index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,10 @@ function configureAsError(rules) {
9090
return result;
9191
}
9292

93-
const activeRules = filterRules(allRules, function(rule) {
94-
return !rule.meta.deprecated;
95-
});
93+
const activeRules = filterRules(allRules, rule => !rule.meta.deprecated);
9694
const activeRulesConfig = configureAsError(activeRules);
9795

98-
const deprecatedRules = filterRules(allRules, function(rule) {
99-
return rule.meta.deprecated;
100-
});
96+
const deprecatedRules = filterRules(allRules, rule => rule.meta.deprecated);
10197

10298
module.exports = {
10399
deprecatedRules: deprecatedRules,

lib/rules/boolean-prop-naming.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports = {
4040
}]
4141
},
4242

43-
create: Components.detect(function(context, components, utils) {
43+
create: Components.detect((context, components, utils) => {
4444
const sourceCode = context.getSourceCode();
4545
const config = context.options[0] || {};
4646
const rule = config.rule ? new RegExp(config.rule) : null;
@@ -118,7 +118,7 @@ module.exports = {
118118
const component = components.get(node) || node;
119119
const invalidProps = component.invalidProps || [];
120120

121-
proptypes.forEach(function (prop) {
121+
proptypes.forEach(prop => {
122122
const propKey = getPropKey(prop);
123123
const flowCheck = (
124124
prop.type === 'ObjectTypeProperty' &&
@@ -146,7 +146,7 @@ module.exports = {
146146
* @param {Object} component The component to process
147147
*/
148148
function reportInvalidNaming(component) {
149-
component.invalidProps.forEach(function (propNode) {
149+
component.invalidProps.forEach(propNode => {
150150
const propName = getPropName(propNode);
151151
context.report({
152152
node: propNode,
@@ -192,7 +192,7 @@ module.exports = {
192192
}
193193

194194
// Search for the proptypes declaration
195-
node.properties.forEach(function(property) {
195+
node.properties.forEach(property => {
196196
if (!isPropTypesDeclaration(property.key)) {
197197
return;
198198
}
@@ -213,7 +213,7 @@ module.exports = {
213213
}
214214

215215
const list = components.list();
216-
Object.keys(list).forEach(function (component) {
216+
Object.keys(list).forEach(component => {
217217
// If this is a functional component that uses a global type, check it
218218
if (
219219
list[component].node.type === 'FunctionDeclaration' &&

lib/rules/default-props-match-prop-types.js

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = {
3333
}]
3434
},
3535

36-
create: Components.detect(function(context, components, utils) {
36+
create: Components.detect((context, components, utils) => {
3737
const configuration = context.options[0] || {};
3838
const allowRequiredDefaults = configuration.allowRequiredDefaults || false;
3939
const propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);
@@ -91,7 +91,7 @@ module.exports = {
9191
* @returns {ASTNode|null} Return null if the variable could not be found, ASTNode otherwise.
9292
*/
9393
function findVariableByName(name) {
94-
const variable = variableUtil.variablesInScope(context).find((item) => item.name === name);
94+
const variable = variableUtil.variablesInScope(context).find(item => item.name === name);
9595

9696
if (!variable || !variable.defs[0] || !variable.defs[0].node) {
9797
return null;
@@ -139,7 +139,7 @@ module.exports = {
139139

140140
function resolveUnionTypeAnnotation(node) {
141141
// Go through all the union and resolve any generic types.
142-
return node.types.map(function(annotation) {
142+
return node.types.map(annotation => {
143143
if (annotation.type === 'GenericTypeAnnotation') {
144144
return resolveGenericTypeAnnotation(annotation);
145145
}
@@ -154,17 +154,13 @@ module.exports = {
154154
* @returns {Object[]} Array of PropType object representations, to be consumed by `addPropTypesToComponent`.
155155
*/
156156
function getPropTypesFromObjectExpression(objectExpression) {
157-
const props = objectExpression.properties.filter(function(property) {
158-
return property.type !== 'ExperimentalSpreadProperty';
159-
});
157+
const props = objectExpression.properties.filter(property => property.type !== 'ExperimentalSpreadProperty');
160158

161-
return props.map(function(property) {
162-
return {
163-
name: property.key.name,
164-
isRequired: isRequiredPropType(property.value),
165-
node: property
166-
};
167-
});
159+
return props.map(property => ({
160+
name: property.key.name,
161+
isRequired: isRequiredPropType(property.value),
162+
node: property
163+
}));
168164
}
169165

170166
/**
@@ -188,7 +184,7 @@ module.exports = {
188184

189185
case 'UnionTypeAnnotation':
190186
const union = resolveUnionTypeAnnotation(node.typeAnnotation);
191-
properties = union.reduce(function(acc, curr) {
187+
properties = union.reduce((acc, curr) => {
192188
if (!curr) {
193189
return acc;
194190
}
@@ -206,11 +202,9 @@ module.exports = {
206202
break;
207203
}
208204

209-
const props = properties.filter(function(property) {
210-
return property.type === 'ObjectTypeProperty';
211-
});
205+
const props = properties.filter(property => property.type === 'ObjectTypeProperty');
212206

213-
return props.map(function(property) {
207+
return props.map(property => {
214208
// the `key` property is not present in ObjectTypeProperty nodes, so we need to get the key name manually.
215209
const tokens = context.getFirstTokens(property, 1);
216210
const name = tokens[0].value;
@@ -237,12 +231,10 @@ module.exports = {
237231
return 'unresolved';
238232
}
239233

240-
return objectExpression.properties.map(function(defaultProp) {
241-
return {
242-
name: defaultProp.key.name,
243-
node: defaultProp
244-
};
245-
});
234+
return objectExpression.properties.map(defaultProp => ({
235+
name: defaultProp.key.name,
236+
node: defaultProp
237+
}));
246238
}
247239

248240
/**
@@ -348,7 +340,7 @@ module.exports = {
348340
return;
349341
}
350342

351-
defaultProps.forEach(function(defaultProp) {
343+
defaultProps.forEach(defaultProp => {
352344
const prop = propFromName(propTypes, defaultProp.name);
353345

354346
if (prop && (allowRequiredDefaults || !prop.isRequired)) {
@@ -567,7 +559,7 @@ module.exports = {
567559
}
568560

569561
// Search for the proptypes declaration
570-
node.properties.forEach(function(property) {
562+
node.properties.forEach(property => {
571563
if (property.type === 'ExperimentalSpreadProperty') {
572564
return;
573565
}

lib/rules/display-name.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = {
3030
}]
3131
},
3232

33-
create: Components.detect(function(context, components, utils) {
33+
create: Components.detect((context, components, utils) => {
3434
const sourceCode = context.getSourceCode();
3535
const config = context.options[0] || {};
3636
const ignoreTranspilerName = config.ignoreTranspilerName || false;
@@ -209,7 +209,7 @@ module.exports = {
209209
ObjectExpression: function(node) {
210210
if (ignoreTranspilerName || !hasTranspilerName(node)) {
211211
// Search for the displayName declaration
212-
node.properties.forEach(function(property) {
212+
node.properties.forEach(property => {
213213
if (!property.key || !isDisplayNameDeclaration(property.key)) {
214214
return;
215215
}

lib/rules/forbid-elements.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module.exports = {
5050

5151
const indexedForbidConfigs = {};
5252

53-
forbidConfiguration.forEach(function(item) {
53+
forbidConfiguration.forEach(item => {
5454
if (typeof item === 'string') {
5555
indexedForbidConfigs[item] = {element: item};
5656
} else {

lib/rules/forbid-foreign-prop-types.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ module.exports = {
4545
},
4646

4747
ObjectPattern: function(node) {
48-
const propTypesNode = node.properties.find(function(property) {
49-
return property.type === 'Property' && property.key.name === 'propTypes';
50-
});
48+
const propTypesNode = node.properties.find(property => property.type === 'Property' && property.key.name === 'propTypes');
5149

5250
if (propTypesNode) {
5351
context.report({

lib/rules/forbid-prop-types.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ module.exports = {
7474
* @returns {void}
7575
*/
7676
function checkForbidden(declarations) {
77-
declarations.forEach(function(declaration) {
77+
declarations.forEach(declaration => {
7878
if (declaration.type !== 'Property') {
7979
return;
8080
}
@@ -154,7 +154,7 @@ module.exports = {
154154
},
155155

156156
ObjectExpression: function(node) {
157-
node.properties.forEach(function(property) {
157+
node.properties.forEach(property => {
158158
if (!property.key) {
159159
return;
160160
}

lib/rules/jsx-boolean-value.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const NEVER = 'never';
2020
const errorData = new WeakMap();
2121
function getErrorData(exceptions) {
2222
if (!errorData.has(exceptions)) {
23-
const exceptionProps = Array.from(exceptions, (name) => `\`${name}\``).join(', ');
23+
const exceptionProps = Array.from(exceptions, name => `\`${name}\``).join(', ');
2424
const exceptionsMessage = exceptions.size > 0 ? ` for the following props: ${exceptionProps}` : '';
2525
errorData.set(exceptions, {exceptionsMessage: exceptionsMessage});
2626
}

0 commit comments

Comments
 (0)