Skip to content

Commit b82fca2

Browse files
committed
Codemod arrow-functions
1 parent a8cd2fe commit b82fca2

Some content is hidden

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

44 files changed

+123
-171
lines changed

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: 10 additions & 14 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 || []);
@@ -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,11 +154,9 @@ 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) {
159+
return props.map(property => {
162160
return {
163161
name: property.key.name,
164162
isRequired: isRequiredPropType(property.value),
@@ -188,7 +186,7 @@ module.exports = {
188186

189187
case 'UnionTypeAnnotation':
190188
const union = resolveUnionTypeAnnotation(node.typeAnnotation);
191-
properties = union.reduce(function(acc, curr) {
189+
properties = union.reduce((acc, curr) => {
192190
if (!curr) {
193191
return acc;
194192
}
@@ -206,11 +204,9 @@ module.exports = {
206204
break;
207205
}
208206

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

213-
return props.map(function(property) {
209+
return props.map(property => {
214210
// the `key` property is not present in ObjectTypeProperty nodes, so we need to get the key name manually.
215211
const tokens = context.getFirstTokens(property, 1);
216212
const name = tokens[0].value;
@@ -237,7 +233,7 @@ module.exports = {
237233
return 'unresolved';
238234
}
239235

240-
return objectExpression.properties.map(function(defaultProp) {
236+
return objectExpression.properties.map(defaultProp => {
241237
return {
242238
name: defaultProp.key.name,
243239
node: defaultProp
@@ -348,7 +344,7 @@ module.exports = {
348344
return;
349345
}
350346

351-
defaultProps.forEach(function(defaultProp) {
347+
defaultProps.forEach(defaultProp => {
352348
const prop = propFromName(propTypes, defaultProp.name);
353349

354350
if (prop && (allowRequiredDefaults || !prop.isRequired)) {
@@ -567,7 +563,7 @@ module.exports = {
567563
}
568564

569565
// Search for the proptypes declaration
570-
node.properties.forEach(function(property) {
566+
node.properties.forEach(property => {
571567
if (property.type === 'ExperimentalSpreadProperty') {
572568
return;
573569
}

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = {
4545
},
4646

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

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-equals-spacing.js

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

4242
return {
4343
JSXOpeningElement: function(node) {
44-
node.attributes.forEach(function(attrNode) {
44+
node.attributes.forEach(attrNode => {
4545
if (!hasEqual(attrNode)) {
4646
return;
4747
}

lib/rules/jsx-filename-extension.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module.exports = {
6464
}
6565

6666
const allowedExtensions = getExtensionsConfig();
67-
const isAllowedExtension = allowedExtensions.some(function (extension) {
67+
const isAllowedExtension = allowedExtensions.some(extension => {
6868
return filename.slice(-extension.length) === extension;
6969
});
7070

lib/rules/jsx-first-prop-new-line.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = {
3636
(configuration === 'multiline-multiprop' && isMultilineJSX(node) && node.attributes.length > 1) ||
3737
(configuration === 'always')
3838
) {
39-
node.attributes.some(function(decl) {
39+
node.attributes.some(decl => {
4040
if (decl.loc.start.line === node.loc.start.line) {
4141
context.report({
4242
node: decl,

0 commit comments

Comments
 (0)