Skip to content

Commit

Permalink
fix: apply style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Oct 26, 2021
1 parent d9a2a37 commit e703984
Show file tree
Hide file tree
Showing 26 changed files with 123 additions and 101 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"ajv": "^8.6.3",
"babel-plugin-add-module-exports": "^1.0.4",
"eslint": "^8.1.0",
"eslint-config-canonical": "^32.6.0",
"eslint-plugin-eslint-plugin": "^4.0.1",
"eslint-config-canonical": "^32.10.0",
"eslint-plugin-eslint-plugin": "^4.0.2",
"gitdown": "^3.1.4",
"glob": "^7.2.0",
"husky": "^7.0.4",
Expand Down
15 changes: 8 additions & 7 deletions src/bin/checkDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ const getDocIndexRules = () => {

if (match === null) {
return null;
} else {
return match[1].replace('./rules/', '').replace('.md', '');
}
}).filter((rule) => {
return rule !== null;
});

return match[1].replace('./rules/', '').replace('.md', '');
})
.filter((rule) => {
return rule !== null;
});

if (rules.length === 0) {
throw new Error('Docs checker is broken - it could not extract rules from docs index file.');
Expand All @@ -48,9 +49,9 @@ const hasCorrectAssertions = (docPath, name) => {

if (match === null) {
return false;
} else {
return match[1] === name;
}

return match[1] === name;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/bin/checkTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const getTestIndexRules = () => {
rules: [],
});

const rules = result.rules;
const {rules} = result;

if (rules.length === 0) {
throw new Error('Tests checker is broken - it could not extract rules from test index file.');
Expand Down
8 changes: 4 additions & 4 deletions src/rules/arrayStyle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const inlineType = (type) => {

if (inlined.length <= 50) {
return inlined;
} else {
return 'Type';
}

return 'Type';
};

export default (defaultConfig, simpleType) => {
Expand Down Expand Up @@ -64,9 +64,9 @@ export default (defaultConfig, simpleType) => {
fix (fixer) {
if (needWrap(elementTypeNode)) {
return fixer.replaceText(node, '(' + rawElementType + ')[]');
} else {
return fixer.replaceText(node, rawElementType + '[]');
}

return fixer.replaceText(node, rawElementType + '[]');
},
message: 'Use "{{ wrappedType }}[]", not "Array<{{ type }}>"',
node,
Expand Down
6 changes: 4 additions & 2 deletions src/rules/interfaceIdMatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ const create = (context) => {
const interfaceIdentifierName = interfaceDeclarationNode.id.name;

if (!pattern.test(interfaceIdentifierName)) {
context.report(interfaceDeclarationNode, 'Interface identifier \'{{name}}\' does not match pattern \'{{pattern}}\'.', {
context.report({data: {
name: interfaceIdentifierName,
pattern: pattern.toString(),
});
},
message: 'Interface identifier \'{{name}}\' does not match pattern \'{{pattern}}\'.',
node: interfaceDeclarationNode});
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/rules/newlineAfterFlowAnnotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ const create = (context) => {
const sourceCode = context.getSourceCode();

const potentialFlowFileAnnotation = _.find(
context.getAllComments(),
context.getSourceCode().getAllComments(),
(comment) => {
return looksLikeFlowFileAnnotation(comment.value);
},
);

if (potentialFlowFileAnnotation) {
const line = potentialFlowFileAnnotation.loc.end.line;
const {line} = potentialFlowFileAnnotation.loc.end;
const nextLineIsEmpty = sourceCode.lines[line] === '';

if (!never && !nextLineIsEmpty) {
Expand Down
5 changes: 4 additions & 1 deletion src/rules/noFlowFixMeComments.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ const create = (context) => {
const value = comment.value.trim();

if (/\$FlowFixMe/u.test(value) && !passesExtraRegex(value)) {
context.report(comment, message + extraMessage);
context.report({
message: message + extraMessage,
node: comment,
});
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/rules/noMutableArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const isEmptyArrayLiteral = (node) => {
const isEmptyArrayInstance = (node) => {
if (_.get(node, 'init.type') === 'NewExpression' || _.get(node, 'init.type') === 'CallExpression') {
return _.get(node, 'init.callee.name') === 'Array' && _.get(node, 'init.arguments.length') === 0;
} else {
return false;
}

return false;
};

const isAnnotationOfEmptyArrayInit = (node) => {
Expand All @@ -22,9 +22,9 @@ const isAnnotationOfEmptyArrayInit = (node) => {
const isVariableDeclaration = _.get(parent, 'type') === 'VariableDeclarator';

return isVariableDeclaration && (isEmptyArrayLiteral(parent) || isEmptyArrayInstance(parent));
} else {
return false;
}

return false;
};

const create = (context) => {
Expand Down
1 change: 1 addition & 0 deletions src/rules/noTypesMissingFileAnnotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const create = (context) => {
if (node.importKind === 'type') {
reporter(node, 'imports');
}

if (node.importKind === 'value' &&
node.specifiers.some((specifier) => {
return specifier.importKind === 'type';
Expand Down
3 changes: 2 additions & 1 deletion src/rules/noUnusedExpressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {

const noUnusedExpressionsRule = getBuiltinRule('no-unused-expressions');

const meta = noUnusedExpressionsRule.meta;
const {meta} = noUnusedExpressionsRule;

const create = (context) => {
const coreChecks = noUnusedExpressionsRule.create(context);
Expand All @@ -20,6 +20,7 @@ const create = (context) => {
) {
return;
}

// eslint-disable-next-line @babel/new-cap
coreChecks.ExpressionStatement(node);
},
Expand Down
4 changes: 2 additions & 2 deletions src/rules/requireCompoundTypeAlias.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ const create = (context) => {
}
},
};
} else {
return {};
}

return {};
};

export default {
Expand Down
4 changes: 2 additions & 2 deletions src/rules/requireIndexerName.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const create = (context) => {
}
},
};
} else {
return {};
}

return {};
};

export default {
Expand Down
4 changes: 3 additions & 1 deletion src/rules/requireReadonlyReactProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ const isReadOnlyObjectType = (node, {useImplicitExactTypes}) => {
// we consider `{||}` to be ReadOnly since it's exact AND has no props (when `implicitExactTypes=false`)
if (useImplicitExactTypes === true && node.exact === false) {
return true;
} else if (node.exact === true) {
}

if (node.exact === true) {
return true;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/rules/requireReturnType.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const create = (context) => {
} else {
selector = 'id.name';
}

const identifierName = _.get(functionNode, selector);

const checkRegExp = (regex) => {
Expand Down Expand Up @@ -129,14 +130,14 @@ const create = (context) => {
const returnType = functionNode.returnType || isArrow && _.get(functionNode, 'parent.id.typeAnnotation');

if (isFunctionReturnUndefined && isReturnTypeAnnotationUndefined && annotateUndefined === 'never') {
context.report(functionNode, 'Must not annotate undefined return type.');
context.report({message: 'Must not annotate undefined return type.', node: functionNode});
} else if (isFunctionReturnUndefined && !isReturnTypeAnnotationUndefined && annotateUndefined === 'always') {
context.report(functionNode, 'Must annotate undefined return type.');
context.report({message: 'Must annotate undefined return type.', node: functionNode});
} else if (
(annotateUndefined === 'always-enforce' || !isFunctionReturnUndefined && !isReturnTypeAnnotationUndefined) &&
annotateReturn && !returnType && !shouldFilterNode(functionNode)
) {
context.report(functionNode, 'Missing return type annotation.');
context.report({message: 'Missing return type annotation.', node: functionNode});
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/rules/requireTypesAtTop.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ const create = (context) => {
}
},
};
} else {
return {};
}

return {};
};

export default {
Expand Down
9 changes: 5 additions & 4 deletions src/rules/requireValidFileAnnotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ const create = (context) => {
Program (node) {
const firstToken = node.tokens[0];

const potentialFlowFileAnnotation = _.find(context.getAllComments(), (comment) => {
const potentialFlowFileAnnotation = _.find(context.getSourceCode().getAllComments(), (comment) => {
return looksLikeFlowFileAnnotation(comment.value);
});

if (potentialFlowFileAnnotation) {
if (firstToken && firstToken.range[0] < potentialFlowFileAnnotation.range[0]) {
context.report(potentialFlowFileAnnotation, 'Flow file annotation not at the top of the file.');
context.report({message: 'Flow file annotation not at the top of the file.', node: potentialFlowFileAnnotation});
}

const annotationValue = potentialFlowFileAnnotation.value.trim();

if (isFlowFileAnnotation(annotationValue)) {
Expand Down Expand Up @@ -109,9 +110,9 @@ const create = (context) => {
});
}
} else if (checkAnnotationSpelling(annotationValue)) {
context.report(potentialFlowFileAnnotation, 'Misspelled or malformed Flow file annotation.');
context.report({message: 'Misspelled or malformed Flow file annotation.', node: potentialFlowFileAnnotation});
} else {
context.report(potentialFlowFileAnnotation, 'Malformed Flow file annotation.');
context.report({message: 'Malformed Flow file annotation.', node: potentialFlowFileAnnotation});
}
} else if (always && !_.get(context, 'settings.flowtype.onlyFilesWithFlowAnnotation')) {
context.report({
Expand Down
1 change: 1 addition & 0 deletions src/rules/sortKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const generateOrderedList = (context, sort, properties) => {
return sort(first[1], second[1]);
});
}

orderedList.push(...itemGroup.map((item) => {
if (item.length === 3) {
return item[2];
Expand Down
2 changes: 2 additions & 0 deletions src/rules/sortTypeUnionIntersectionMembers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const groups = {

// eslint-disable-next-line complexity
const getGroup = (node) => {
// eslint-disable-next-line default-case
switch (node.type) {
case 'FunctionTypeAnnotation':
return groups.function;
Expand Down Expand Up @@ -61,6 +62,7 @@ const fallbackSort = (a, b) => {
if (a < b) {
return -1;
}

if (a > b) {
return 1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/rules/typeColonSpacing/evaluateTypical.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export default (context, report, typeForMessage) => {
const getColon = (node, typeAnnotation) => {
if (node.type === 'FunctionTypeParam') {
return sourceCode.getFirstToken(node, node.optional ? 2 : 1);
} else {
return sourceCode.getFirstToken(typeAnnotation);
}

return sourceCode.getFirstToken(typeAnnotation);
};

return (node) => {
Expand Down
8 changes: 4 additions & 4 deletions src/rules/typeColonSpacing/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ const hasLineBreak = (direction, colon, context) => {

if (direction === 'before') {
return colon.loc.start.line !== sourceCode.getTokenBefore(colon).loc.end.line;
} else {
return sourceCode.getTokenAfter(colon).loc.start.line !== colon.loc.end.line;
}

return sourceCode.getTokenAfter(colon).loc.start.line !== colon.loc.end.line;
};

const getSpaces = (direction, colon, context) => {
const sourceCode = context.getSourceCode();

if (direction === 'before') {
return colon.range[0] - sourceCode.getTokenBefore(colon).range[1];
} else {
return sourceCode.getTokenAfter(colon).range[0] - colon.range[1];
}

return sourceCode.getTokenAfter(colon).range[0] - colon.range[1];
};

export default (direction, context, {always, allowLineBreak}) => {
Expand Down
6 changes: 4 additions & 2 deletions src/rules/typeIdMatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ const create = (context) => {
const typeIdentifierName = typeAliasNode.id.name;

if (!pattern.test(typeIdentifierName)) {
context.report(typeAliasNode, 'Type identifier \'{{name}}\' does not match pattern \'{{pattern}}\'.', {
context.report({data: {
name: typeIdentifierName,
pattern: pattern.toString(),
});
},
message: 'Type identifier \'{{name}}\' does not match pattern \'{{pattern}}\'.',
node: typeAliasNode});
}
};

Expand Down
Loading

0 comments on commit e703984

Please sign in to comment.