Skip to content

Commit

Permalink
style: apply auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Oct 26, 2021
1 parent 0bf7612 commit d9a2a37
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -22,7 +22,7 @@
"ajv": "^8.6.3",
"babel-plugin-add-module-exports": "^1.0.4",
"eslint": "^8.1.0",
"eslint-config-canonical": "^32.1.1",
"eslint-config-canonical": "^32.6.0",
"eslint-plugin-eslint-plugin": "^4.0.1",
"gitdown": "^3.1.4",
"glob": "^7.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/bin/addAssertions.js
Expand Up @@ -23,9 +23,9 @@ const formatCodeSnippet = (setup) => {
paragraphs.push(setup.code);

if (setup.errors) {
setup.errors.forEach((message) => {
for (const message of setup.errors) {
paragraphs.push('// Message: ' + message.message);
});
}
}

if (setup.rules) {
Expand Down
1 change: 1 addition & 0 deletions src/bin/checkTests.js
Expand Up @@ -10,6 +10,7 @@ import {
const getTestIndexRules = () => {
const content = fs.readFileSync(path.resolve(__dirname, '../../tests/rules/index.js'), 'utf-8');

// eslint-disable-next-line unicorn/no-array-reduce
const result = content.split('\n').reduce((acc, line) => {
if (acc.inRulesArray) {
if (line === '];') {
Expand Down
4 changes: 2 additions & 2 deletions src/rules/defineFlowType.js
Expand Up @@ -68,9 +68,9 @@ const create = (context) => {
globalScope = context.getScope();
},
TypeParameterDeclaration (node) {
node.params.forEach((param) => {
for (const param of node.params) {
makeDefined(param);
});
}
},
};
};
Expand Down
4 changes: 2 additions & 2 deletions src/rules/noDupeKeys.js
Expand Up @@ -68,7 +68,7 @@ const create = (context) => {
// filter out complex object types, like ObjectTypeSpreadProperty
const identifierNodes = _.filter(node.properties, {type: 'ObjectTypeProperty'});

_.forEach(identifierNodes, (identifierNode) => {
for (const identifierNode of identifierNodes) {
const needle = {name: getParameterName(identifierNode, context)};

if (identifierNode.value.type === 'FunctionTypeAnnotation') {
Expand All @@ -86,7 +86,7 @@ const create = (context) => {
} else {
haystack.push(needle);
}
});
}
};

return {
Expand Down
13 changes: 7 additions & 6 deletions src/rules/noFlowFixMeComments.js
Expand Up @@ -25,7 +25,7 @@ const create = (context) => {
const handleComment = function (comment) {
const value = comment.value.trim();

if (value.match(/\$FlowFixMe/u) && !passesExtraRegex(value)) {
if (/\$FlowFixMe/u.test(value) && !passesExtraRegex(value)) {
context.report(comment, message + extraMessage);
}
};
Expand All @@ -41,13 +41,14 @@ const create = (context) => {
},

Program () {
context
for (const comment of context
.getSourceCode()
.getAllComments()
.filter((comment) => {
return comment.type === 'Block' || comment.type === 'Line';
})
.forEach(handleComment);
.filter((node) => {
return node.type === 'Block' || node.type === 'Line';
})) {
handleComment(comment);
}
},
};
};
Expand Down
2 changes: 1 addition & 1 deletion src/rules/requireInexactType.js
Expand Up @@ -12,7 +12,7 @@ const create = (context) => {
ObjectTypeAnnotation (node) {
const {inexact, exact} = node;

if (!node.hasOwnProperty('inexact')) {
if (!Object.prototype.hasOwnProperty.call(node, 'inexact')) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/rules/requireParameterType.js
Expand Up @@ -38,6 +38,7 @@ const create = iterateFunctionNodes((context) => {
return;
}

// eslint-disable-next-line unicorn/no-array-for-each
_.forEach(functionNode.params, (identifierNode) => {
const parameterName = getParameterName(identifierNode, context);

Expand Down
2 changes: 2 additions & 0 deletions src/rules/requireReturnType.js
Expand Up @@ -48,7 +48,9 @@ const create = (context) => {
const annotateUndefined = _.get(context, 'options[1].annotateUndefined') || 'never';
const skipArrows = _.get(context, 'options[1].excludeArrowFunctions') || false;

// eslint-disable-next-line unicorn/no-array-callback-reference
const excludeMatching = _.get(context, 'options[1].excludeMatching', []).map(makeRegExp);
// eslint-disable-next-line unicorn/no-array-callback-reference
const includeOnlyMatching = _.get(context, 'options[1].includeOnlyMatching', []).map(makeRegExp);

const targetNodes = [];
Expand Down
1 change: 1 addition & 0 deletions src/rules/requireVariableType.js
Expand Up @@ -49,6 +49,7 @@ const create = (context) => {
return;
}

// eslint-disable-next-line unicorn/no-array-for-each
_.forEach(variableDeclaration.declarations, (variableDeclarator) => {
const identifierNode = _.get(variableDeclarator, 'id');
const identifierName = _.get(identifierNode, 'name');
Expand Down
20 changes: 11 additions & 9 deletions src/rules/sortKeys.js
Expand Up @@ -101,7 +101,8 @@ const generateOrderedList = (context, sort, properties) => {

const itemGroups = [[]];
let itemGroupIndex = 0;
items.forEach((item) => {

for (const item of items) {
if (item[0].type === 'ObjectTypeSpreadProperty') {
++itemGroupIndex;
itemGroups[itemGroupIndex] = [item];
Expand All @@ -110,10 +111,10 @@ const generateOrderedList = (context, sort, properties) => {
} else {
itemGroups[itemGroupIndex].push(item);
}
});
}

const orderedList = [];
itemGroups.forEach((itemGroup) => {
for (const itemGroup of itemGroups) {
if (itemGroup[0] && itemGroup[0].type !== 'ObjectTypeSpreadProperty') {
// console.log('itemGroup', itemGroup);

Expand All @@ -129,7 +130,7 @@ const generateOrderedList = (context, sort, properties) => {

return item[2] + ':' + item[3];
}));
});
}

return orderedList;
};
Expand All @@ -146,7 +147,7 @@ const generateFix = (node, context, sort) => {

nodeText = originalSubstring;

node.properties.forEach((property, index) => {
for (const [index, property] of node.properties.entries()) {
const nextPunctuator = source.getTokenAfter(property, {
filter: (token) => {
return token.type === 'Punctuator' || token.value === '|}';
Expand All @@ -165,11 +166,11 @@ const generateFix = (node, context, sort) => {
);

nodeText = nodeText.replace(subString, '$' + index);
});
}

newTypes.forEach((item, index) => {
for (const [index, item] of newTypes.entries()) {
nodeText = nodeText.replace('$' + index, item);
});
}

return nodeText;
};
Expand All @@ -181,7 +182,8 @@ const create = (context) => {
const checkKeyOrder = (node) => {
prev = null;

_.forEach(node.properties, (identifierNode) => {
// eslint-disable-next-line unicorn/no-array-for-each
node.properties.forEach((identifierNode) => {
const current = getParameterName(identifierNode, context);
const last = prev;

Expand Down
4 changes: 2 additions & 2 deletions src/rules/spreadExactType.js
Expand Up @@ -10,7 +10,7 @@ const create = (context) => {
ObjectTypeAnnotation (node) {
const {properties} = node;

properties.forEach((property) => {
for (const property of properties) {
const {type} = property;
if (type === 'ObjectTypeSpreadProperty') {
const {argument: {type: argumentType, id: argumentId}} = property;
Expand All @@ -22,7 +22,7 @@ const create = (context) => {
});
}
}
});
}
},
};
};
Expand Down
6 changes: 4 additions & 2 deletions src/rules/typeColonSpacing/evaluateFunctions.js
@@ -1,4 +1,3 @@
import _ from 'lodash';
import {
iterateFunctionNodes,
} from '../../utilities';
Expand All @@ -10,7 +9,10 @@ export default iterateFunctionNodes((context, report) => {
const checkReturnType = evaluateReturnType(context, report);

return (functionNode) => {
_.forEach(functionNode.params, checkParam);
for (const param of functionNode.params) {
checkParam(param);
}

checkReturnType(functionNode);
};
});
4 changes: 2 additions & 2 deletions src/rules/typeColonSpacing/evaluateVariables.js
Expand Up @@ -9,7 +9,7 @@ export default (context, report) => {
return (node) => {
const declarations = _.get(node, 'declarations', []);

_.forEach(declarations, (leaf) => {
for (const leaf of declarations) {
const typeAnnotation = _.get(leaf, 'id.typeAnnotation');

if (typeAnnotation) {
Expand All @@ -20,6 +20,6 @@ export default (context, report) => {
type: node.kind + ' type annotation',
});
}
});
}
};
};
4 changes: 2 additions & 2 deletions src/rules/typeImportStyle.js
Expand Up @@ -19,14 +19,14 @@ const create = (context) => {
return {
ImportDeclaration (node) {
if (node.importKind !== 'type') {
node.specifiers.forEach((specifier) => {
for (const specifier of node.specifiers) {
if (specifier.importKind === 'type') {
context.report({
message: 'Unexpected type import',
node,
});
}
});
}
}
},
};
Expand Down
6 changes: 3 additions & 3 deletions src/rules/unionIntersectionSpacing.js
Expand Up @@ -15,9 +15,9 @@ const create = (context) => {
const always = (context.options[0] || 'always') === 'always';

const check = (node) => {
node.types.forEach((type, index) => {
for (const [index, type] of node.types.entries()) {
if (index + 1 === node.types.length) {
return;
continue;
}

const separator = getTokenAfterParens(sourceCode, type);
Expand Down Expand Up @@ -66,7 +66,7 @@ const create = (context) => {
});
}
}
});
}
};

return {
Expand Down
8 changes: 4 additions & 4 deletions src/rules/useFlowType.js
Expand Up @@ -34,19 +34,19 @@ const create = (context) => {
DeclareVariable: markTypeAsUsed,
GenericTypeAnnotation: markTypeAsUsedWithGenericType,
TypeParameterDeclaration (node) {
node.params.forEach((param) => {
for (const param of node.params) {
if (param.default && param.default.typeParameters) {
if (param.default.type === 'GenericTypeAnnotation') {
markTypeAsUsedWithGenericType(param.default);
}

param.default.typeParameters.params.forEach((typeParameterNode) => {
for (const typeParameterNode of param.default.typeParameters.params) {
if (typeParameterNode.type === 'GenericTypeAnnotation') {
markTypeAsUsedWithGenericType(typeParameterNode);
}
});
}
}
});
}
},
};
};
Expand Down
4 changes: 2 additions & 2 deletions src/rules/validSyntax.js
Expand Up @@ -9,7 +9,7 @@ const schema = [];

const create = iterateFunctionNodes((context) => {
return (functionNode) => {
_.forEach(functionNode.params, (identifierNode) => {
for (const identifierNode of functionNode.params) {
const nodeType = _.get(identifierNode, 'type');
const isAssignmentPattern = nodeType === 'AssignmentPattern';
const hasTypeAnnotation = Boolean(_.get(identifierNode, 'typeAnnotation'));
Expand All @@ -24,7 +24,7 @@ const create = iterateFunctionNodes((context) => {
node: identifierNode,
});
}
});
}
};
});

Expand Down

0 comments on commit d9a2a37

Please sign in to comment.