Skip to content

Commit 09246b5

Browse files
committed
style: fix code style issues
1 parent 6f70f61 commit 09246b5

24 files changed

+119
-85
lines changed

src/bin/addAssertions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* @file This script is used to inline assertions into the README.md documents.
55
*/
66

7-
import path from 'path';
87
import fs from 'fs';
8+
import path from 'path';
99
import glob from 'glob';
1010
import _ from 'lodash';
1111

@@ -43,7 +43,7 @@ const getAssertions = () => {
4343
});
4444

4545
const assertionCodes = _.map(assertionFiles, (filePath) => {
46-
// eslint-disable-next-line global-require, import/no-dynamic-require
46+
// eslint-disable-next-line import/no-dynamic-require
4747
const codes = require(filePath);
4848

4949
return {

src/bin/checkTests.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
const getTestIndexRules = () => {
1111
const content = fs.readFileSync(path.resolve(__dirname, '../../tests/rules/index.js'), 'utf-8');
1212

13-
// eslint-disable-next-line unicorn/no-reduce
1413
const result = content.split('\n').reduce((acc, line) => {
1514
if (acc.inRulesArray) {
1615
if (line === '];') {

src/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/* eslint-disable import/max-dependencies */
21
import _ from 'lodash';
32
import recommended from './configs/recommended.json';
43
import arrayStyleComplexType from './rules/arrayStyleComplexType';
54
import arrayStyleSimpleType from './rules/arrayStyleSimpleType';
5+
import arrowParens from './rules/arrowParens';
66
import booleanStyle from './rules/booleanStyle';
77
import defineFlowType from './rules/defineFlowType';
88
import delimiterDangle from './rules/delimiterDangle';
@@ -13,20 +13,20 @@ import newlineAfterFlowAnnotation from './rules/newlineAfterFlowAnnotation';
1313
import noDupeKeys from './rules/noDupeKeys';
1414
import noExistentialType from './rules/noExistentialType';
1515
import noFlowFixMeComments from './rules/noFlowFixMeComments';
16+
import noInternalFlowType from './rules/noInternalFlowType';
17+
import noMixed from './rules/noMixed';
1618
import noMutableArray from './rules/noMutableArray';
1719
import noPrimitiveConstructorTypes from './rules/noPrimitiveConstructorTypes';
1820
import noTypesMissingFileAnnotation from './rules/noTypesMissingFileAnnotation';
1921
import noUnusedExpressions from './rules/noUnusedExpressions';
2022
import noWeakTypes from './rules/noWeakTypes';
21-
import noInternalFlowType from './rules/noInternalFlowType';
22-
import noMixed from './rules/noMixed';
2323
import objectTypeCurlySpacing from './rules/objectTypeCurlySpacing';
2424
import objectTypeDelimiter from './rules/objectTypeDelimiter';
2525
import quotes from './rules/quotes';
26-
import requireIndexerName from './rules/requireIndexerName';
2726
import requireCompoundTypeAlias from './rules/requireCompoundTypeAlias';
28-
import requireInexactType from './rules/requireInexactType';
2927
import requireExactType from './rules/requireExactType';
28+
import requireIndexerName from './rules/requireIndexerName';
29+
import requireInexactType from './rules/requireInexactType';
3030
import requireParameterType from './rules/requireParameterType';
3131
import requireReadonlyReactProps from './rules/requireReadonlyReactProps';
3232
import requireReturnType from './rules/requireReturnType';
@@ -39,15 +39,16 @@ import sortTypeUnionIntersectionMembers from './rules/sortTypeUnionIntersectionM
3939
import spaceAfterTypeColon from './rules/spaceAfterTypeColon';
4040
import spaceBeforeGenericBracket from './rules/spaceBeforeGenericBracket';
4141
import spaceBeforeTypeColon from './rules/spaceBeforeTypeColon';
42+
import spreadExactType from './rules/spreadExactType';
4243
import typeIdMatch from './rules/typeIdMatch';
4344
import typeImportStyle from './rules/typeImportStyle';
4445
import unionIntersectionSpacing from './rules/unionIntersectionSpacing';
4546
import useFlowType from './rules/useFlowType';
4647
import useReadOnlySpread from './rules/useReadOnlySpread';
4748
import validSyntax from './rules/validSyntax';
48-
import spreadExactType from './rules/spreadExactType';
49-
import arrowParens from './rules/arrowParens';
50-
import {checkFlowFileAnnotation} from './utilities';
49+
import {
50+
checkFlowFileAnnotation,
51+
} from './utilities';
5152

5253
const rules = {
5354
'array-style-complex-type': arrayStyleComplexType,

src/rules/arrayStyle/index.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,31 @@ export default (defaultConfig, simpleType) => {
4646

4747
// verbose
4848
GenericTypeAnnotation (node) {
49-
if (node.id.name === 'Array') {
50-
// Don't report on un-parameterized Array annotations. There are valid cases for this,
51-
// but regardless, we must NOT crash when encountering them.
52-
if (node.typeParameters && node.typeParameters.params.length === 1) {
53-
const elementTypeNode = node.typeParameters.params[0];
54-
const rawElementType = context.getSourceCode().getText(elementTypeNode);
55-
const inlinedType = inlineType(rawElementType);
56-
const wrappedInlinedType = needWrap(elementTypeNode) ? '(' + inlinedType + ')' : inlinedType;
49+
// Don't report on un-parameterized Array annotations. There are valid cases for this,
50+
// but regardless, we must NOT crash when encountering them.
51+
if (node.id.name === 'Array' &&
52+
node.typeParameters && node.typeParameters.params.length === 1) {
53+
const elementTypeNode = node.typeParameters.params[0];
54+
const rawElementType = context.getSourceCode().getText(elementTypeNode);
55+
const inlinedType = inlineType(rawElementType);
56+
const wrappedInlinedType = needWrap(elementTypeNode) ? '(' + inlinedType + ')' : inlinedType;
5757

58-
if (isSimpleType(elementTypeNode) === simpleType && !verbose) {
59-
context.report({
60-
data: {
61-
type: inlinedType,
62-
wrappedType: wrappedInlinedType,
63-
},
64-
fix (fixer) {
65-
if (needWrap(elementTypeNode)) {
66-
return fixer.replaceText(node, '(' + rawElementType + ')[]');
67-
} else {
68-
return fixer.replaceText(node, rawElementType + '[]');
69-
}
70-
},
71-
message: 'Use "{{ wrappedType }}[]", not "Array<{{ type }}>"',
72-
node,
73-
});
74-
}
58+
if (isSimpleType(elementTypeNode) === simpleType && !verbose) {
59+
context.report({
60+
data: {
61+
type: inlinedType,
62+
wrappedType: wrappedInlinedType,
63+
},
64+
fix (fixer) {
65+
if (needWrap(elementTypeNode)) {
66+
return fixer.replaceText(node, '(' + rawElementType + ')[]');
67+
} else {
68+
return fixer.replaceText(node, rawElementType + '[]');
69+
}
70+
},
71+
message: 'Use "{{ wrappedType }}[]", not "Array<{{ type }}>"',
72+
node,
73+
});
7574
}
7675
}
7776
},

src/rules/defineFlowType.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const create = (context) => {
1414

1515
if (ref.identifier.name === ident.name) {
1616
// use "__defineGeneric" since we don't have a reference to "escope.Variable"
17-
// eslint-disable-next-line no-underscore-dangle
17+
1818
globalScope.__defineGeneric(
1919
ident.name,
2020
globalScope.set,

src/rules/genericSpacing.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {spacingFixers} from '../utilities';
1+
import {
2+
spacingFixers,
3+
} from '../utilities';
24

35
const schema = [
46
{

src/rules/noTypesMissingFileAnnotation.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {isFlowFile} from '../utilities';
1+
import {
2+
isFlowFile,
3+
} from '../utilities';
24

35
/**
46
* Disallows the use for flow types without a valid file annotation.

src/rules/objectTypeCurlySpacing.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {spacingFixers} from '../utilities';
1+
import {
2+
spacingFixers,
3+
} from '../utilities';
24

35
const schema = [
46
{

src/rules/objectTypeDelimiter.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ const create = (context) => {
3737
lastToken = parentTokens[parentTokens.indexOf(lastToken) + 1];
3838
}
3939

40-
if (lastToken.type === 'Punctuator') {
41-
if (lastToken.value === BAD.char) {
42-
context.report({
43-
fix (fixer) {
44-
return fixer.replaceText(lastToken, GOOD.char);
45-
},
46-
message: 'Prefer ' + GOOD.name + 's to ' + BAD.name + 's in object and class types',
47-
node: lastToken,
48-
});
49-
}
40+
if (lastToken.type === 'Punctuator' && lastToken.value === BAD.char) {
41+
context.report({
42+
fix (fixer) {
43+
return fixer.replaceText(lastToken, GOOD.char);
44+
},
45+
message: 'Prefer ' + GOOD.name + 's to ' + BAD.name + 's in object and class types',
46+
node: lastToken,
47+
});
5048
}
5149
};
5250

src/rules/requireIndexerName.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {getParameterName} from '../utilities';
1+
import {
2+
getParameterName,
3+
} from '../utilities';
24

35
const schema = [
46
{

src/rules/spaceBeforeGenericBracket.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {spacingFixers} from '../utilities';
1+
import {
2+
spacingFixers,
3+
} from '../utilities';
24

35
const schema = [
46
{

src/rules/typeColonSpacing/evaluateFunctions.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import _ from 'lodash';
2-
import {iterateFunctionNodes} from '../../utilities';
3-
import evaluateTypical from './evaluateTypical';
2+
import {
3+
iterateFunctionNodes,
4+
} from '../../utilities';
45
import evaluateReturnType from './evaluateReturnType';
6+
import evaluateTypical from './evaluateTypical';
57

68
export default iterateFunctionNodes((context, report) => {
79
const checkParam = evaluateTypical(context, report, 'parameter');

src/rules/typeColonSpacing/evaluateObjectTypeIndexer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {getTokenAfterParens, getTokenBeforeParens} from '../../utilities';
1+
import {
2+
getTokenAfterParens, getTokenBeforeParens,
3+
} from '../../utilities';
24

35
export default (context, report) => {
46
const sourceCode = context.getSourceCode();

src/rules/typeColonSpacing/evaluateObjectTypeProperty.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import {getParameterName, quoteName} from '../../utilities';
1+
import {
2+
getParameterName, quoteName,
3+
} from '../../utilities';
24

35
const getColon = (context, objectTypeProperty) => {
4-
// eslint-disable-next-line init-declarations
56
let tokenIndex = 1;
67

78
if (objectTypeProperty.optional) {

src/rules/typeColonSpacing/evaluateTypical.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import _ from 'lodash';
2-
import {getParameterName, quoteName} from '../../utilities';
2+
import {
3+
getParameterName, quoteName,
4+
} from '../../utilities';
35

46
export default (context, report, typeForMessage) => {
57
const sourceCode = context.getSourceCode();

src/rules/typeColonSpacing/evaluateVariables.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import _ from 'lodash';
2-
import {getParameterName, quoteName} from '../../utilities';
2+
import {
3+
getParameterName, quoteName,
4+
} from '../../utilities';
35

46
export default (context, report) => {
57
const sourceCode = context.getSourceCode();

src/rules/typeColonSpacing/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import reporter from './reporter';
1+
import evaluateFunctions from './evaluateFunctions';
22
import evaluateObjectTypeIndexer from './evaluateObjectTypeIndexer';
33
import evaluateObjectTypeProperty from './evaluateObjectTypeProperty';
44
import evaluateTypeCastExpression from './evaluateTypeCastExpression';
55
import evaluateTypical from './evaluateTypical';
6-
import evaluateFunctions from './evaluateFunctions';
76
import evaluateVariables from './evaluateVariables';
7+
import reporter from './reporter';
88

99
export default (direction, context, options) => {
1010
const report = reporter(direction, context, options);

src/rules/typeColonSpacing/reporter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {spacingFixers} from '../../utilities';
1+
import {
2+
spacingFixers,
3+
} from '../../utilities';
24

35
const hasLineBreak = (direction, colon, context) => {
46
const sourceCode = context.getSourceCode();

src/rules/unionIntersectionSpacing.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {spacingFixers, getTokenAfterParens} from '../utilities';
1+
import {
2+
spacingFixers, getTokenAfterParens,
3+
} from '../utilities';
24

35
const schema = [
46
{

src/utilities/index.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,36 @@
33
// eslint-disable-next-line import/no-namespace
44
import * as spacingFixers from './spacingFixers';
55

6-
export {default as checkFlowFileAnnotation} from './checkFlowFileAnnotation';
7-
export {default as fuzzyStringMatch} from './fuzzyStringMatch';
8-
export {default as getParameterName} from './getParameterName';
9-
export {default as getTokenAfterParens} from './getTokenAfterParens';
10-
export {default as getTokenBeforeParens} from './getTokenBeforeParens';
11-
export {default as isFlowFile} from './isFlowFile';
12-
export {default as isNoFlowFile} from './isNoFlowFile';
13-
export {default as isFlowFileAnnotation} from './isFlowFileAnnotation';
14-
export {default as iterateFunctionNodes} from './iterateFunctionNodes';
15-
export {default as quoteName} from './quoteName';
6+
export {
7+
default as checkFlowFileAnnotation,
8+
} from './checkFlowFileAnnotation';
9+
export {
10+
default as fuzzyStringMatch,
11+
} from './fuzzyStringMatch';
12+
export {
13+
default as getParameterName,
14+
} from './getParameterName';
15+
export {
16+
default as getTokenAfterParens,
17+
} from './getTokenAfterParens';
18+
export {
19+
default as getTokenBeforeParens,
20+
} from './getTokenBeforeParens';
21+
export {
22+
default as isFlowFile,
23+
} from './isFlowFile';
24+
export {
25+
default as isNoFlowFile,
26+
} from './isNoFlowFile';
27+
export {
28+
default as isFlowFileAnnotation,
29+
} from './isFlowFileAnnotation';
30+
export {
31+
default as iterateFunctionNodes,
32+
} from './iterateFunctionNodes';
33+
export {
34+
default as quoteName,
35+
} from './quoteName';
1636

1737
export {
1838
spacingFixers,

tests/rules/assertions/arrowParens.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable sort-keys */
21
const type = 'ArrowFunctionExpression';
32

43
export default {
@@ -285,11 +284,9 @@ export default {
285284
options: ['as-needed'],
286285
parserOptions: {ecmaVersion: 8}},
287286
{code: '(a: T) => a',
288-
options: ['as-needed'],
289-
},
287+
options: ['as-needed']},
290288
{code: '(a): T => a',
291-
options: ['as-needed'],
292-
},
289+
options: ['as-needed']},
293290

294291
// "as-needed", { "requireForBlockBody": true }
295292
{code: '() => {}',

tests/rules/assertions/defineFlowType.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ const VALID_WITH_DEFINE_FLOW_TYPE = [
131131

132132
// This tests to ensure we have a robust handling of @flow comments
133133
{
134-
// eslint-disable-next-line no-restricted-syntax
135134
code: `
136135
/**
137136
* Copyright 2019 no corp

tests/rules/assertions/sortKeys.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export default {
4040
errors: [{message: 'Expected type annotations to be in ascending order. "b" must be before "c".'}],
4141
output: 'type FooType = { a: number, b: string, c: number }',
4242
},
43-
/* eslint-disable no-restricted-syntax */
4443
{
4544
code: `
4645
type FooType = {
@@ -438,7 +437,6 @@ export default {
438437
|}
439438
`,
440439
},
441-
/* eslint-enable no-restricted-syntax */
442440

443441
// https://github.com/gajus/eslint-plugin-flowtype/issues/455
444442
{

0 commit comments

Comments
 (0)