Skip to content

Commit

Permalink
Merge branch 'SimeonC-fix-interface-delimiters'
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jul 28, 2019
2 parents 2981c01 + f627743 commit b0477b2
Show file tree
Hide file tree
Showing 93 changed files with 2,577 additions and 2,546 deletions.
4 changes: 3 additions & 1 deletion .README/rules/delimiter-dangle.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ _The `--fix` option on the command line automatically fixes problems reported by

Enforces consistent use of trailing commas in Object and Tuple annotations.

This rule takes one argument which mirrors ESLint's default `comma-dangle` rule.
This rule takes two arguments which both mirror ESLint's default `comma-dangle` rule.
The first argument is for Object and Tuple annotations.
The second argument is used for Interface annotations as ESLint's default `comma-dangle` doesn't apply to interfaces - this defaults to whatever the first argument is.

If it is `'never'` then a problem is raised when there is a trailing comma.

Expand Down
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,9 @@ _The `--fix` option on the command line automatically fixes problems reported by
Enforces consistent use of trailing commas in Object and Tuple annotations.
This rule takes one argument which mirrors ESLint's default `comma-dangle` rule.
This rule takes two arguments which both mirror ESLint's default `comma-dangle` rule.
The first argument is for Object and Tuple annotations.
The second argument is used for Interface annotations as ESLint's default `comma-dangle` doesn't apply to interfaces - this defaults to whatever the first argument is.
If it is `'never'` then a problem is raised when there is a trailing comma.
Expand Down Expand Up @@ -660,6 +662,10 @@ foo: string
type X = { foo: string; }
// Message: Unexpected trailing delimiter

// Options: ["always","never"]
interface X { foo: string; }
// Message: Unexpected trailing delimiter

// Options: ["never"]
type X = { [key: string]: number, }
// Message: Unexpected trailing delimiter
Expand Down Expand Up @@ -862,6 +868,9 @@ type X = {
foo: string;
}

// Options: ["never","always"]
interface X { foo: string; }

// Options: ["never"]
type X = {}

Expand Down Expand Up @@ -1152,7 +1161,7 @@ import Foo from './foo';
// Message: Expected newline after flow annotation

// Options: ["always-windows"]
// @flow
// @flow
import Foo from './foo';
// Message: Expected newline after flow annotation

Expand All @@ -1172,8 +1181,8 @@ The following patterns are not considered problems:
import Foo from './foo';

// Options: ["always-windows"]
// @flow

// @flow

import Foo from './foo';

// Options: ["never"]
Expand Down Expand Up @@ -4028,7 +4037,7 @@ The following patterns are not considered problems:
{ a: string, b: number }) => {}
// Options: ["always",{"allowLineBreak":true}]
(foo:
(foo:
{ a: string, b: number }) => {}
// Options: ["never"]
Expand Down
2 changes: 1 addition & 1 deletion src/bin/addAssertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const getAssertions = () => {

return {
invalid: _.map(codes.invalid, formatCodeSnippet),
valid: _.map(codes.valid, formatCodeSnippet),
valid: _.map(codes.valid, formatCodeSnippet)
};
});

Expand Down
2 changes: 1 addition & 1 deletion src/bin/checkDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fs from 'fs';
import path from 'path';
import {
getRules,
isFile,
isFile
} from './utilities';

const windows = (array, size) => {
Expand Down
4 changes: 2 additions & 2 deletions src/bin/checkTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'fs';
import path from 'path';
import {
getRules,
isFile,
isFile
} from './utilities';

const getTestIndexRules = () => {
Expand All @@ -24,7 +24,7 @@ const getTestIndexRules = () => {
return acc;
}, {
inRulesArray: false,
rules: [],
rules: []
});

const rules = result.rules;
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ const rules = {
'type-import-style': typeImportStyle,
'union-intersection-spacing': unionIntersectionSpacing,
'use-flow-type': useFlowType,
'valid-syntax': validSyntax,
'valid-syntax': validSyntax
};

export default {
configs: {
recommended,
recommended
},
rules: _.mapValues(rules, (rule, key) => {
if (key === 'no-types-missing-file-annotation') {
Expand All @@ -92,7 +92,7 @@ export default {

return {
...rule,
create: _.partial(checkFlowFileAnnotation, rule.create),
create: _.partial(checkFlowFileAnnotation, rule.create)
};
}),
rulesConfig: {
Expand Down Expand Up @@ -123,6 +123,6 @@ export default {
'type-import-style': 0,
'union-intersection-spacing': 0,
'use-flow-type': 0,
'valid-syntax': 0,
},
'valid-syntax': 0
}
};
16 changes: 8 additions & 8 deletions src/rules/arrayStyle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import needWrap from './needWrap';
const schema = [
{
enum: ['verbose', 'shorthand'],
type: 'string',
},
type: 'string'
}
];

const inlineType = (type) => {
Expand Down Expand Up @@ -33,13 +33,13 @@ export default (defaultConfig, simpleType) => {
context.report({
data: {
type: inlinedType,
wrappedType: wrappedInlinedType,
wrappedType: wrappedInlinedType
},
fix (fixer) {
return fixer.replaceText(node, 'Array<' + rawElementType + '>');
},
message: 'Use "Array<{{ type }}>", not "{{ wrappedType }}[]"',
node,
node
});
}
},
Expand All @@ -59,7 +59,7 @@ export default (defaultConfig, simpleType) => {
context.report({
data: {
type: inlinedType,
wrappedType: wrappedInlinedType,
wrappedType: wrappedInlinedType
},
fix (fixer) {
if (needWrap(elementTypeNode)) {
Expand All @@ -69,17 +69,17 @@ export default (defaultConfig, simpleType) => {
}
},
message: 'Use "{{ wrappedType }}[]", not "Array<{{ type }}>"',
node,
node
});
}
}
}
},
}
};
};

return {
create,
schema,
schema
};
};
2 changes: 1 addition & 1 deletion src/rules/arrayStyle/isSimpleType.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

const simpleTypePatterns = [
/^(?:Any|Array|Boolean|Generic|Mixed|Number|String|Void)TypeAnnotation$/,
/.+LiteralTypeAnnotation$/,
/.+LiteralTypeAnnotation$/
];

export default (node) => {
Expand Down
32 changes: 16 additions & 16 deletions src/rules/arrowParens.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const getLocation = (node) => {
return {
end: node.params[node.params.length - 1].loc.end,
start: node.params[0].loc.start,
start: node.params[0].loc.start
};
};

Expand Down Expand Up @@ -40,7 +40,7 @@ export default {

return fixer.replaceTextRange([
firstTokenOfParam.range[0],
closingParenToken.range[1],
closingParenToken.range[1]
], `${shouldAddSpaceForAsync ? ' ' : ''}${paramToken.value}`);
};

Expand Down Expand Up @@ -70,7 +70,7 @@ export default {
fix: fixParamsWithParenthesis,
loc: getLocation(node),
messageId: 'unexpectedParensInline',
node,
node
});
}

Expand All @@ -88,7 +88,7 @@ export default {
},
loc: getLocation(node),
messageId: 'expectedParensBlock',
node,
node
});
}

Expand All @@ -107,7 +107,7 @@ export default {
fix: fixParamsWithParenthesis,
loc: getLocation(node),
messageId: 'unexpectedParens',
node,
node
});
}

Expand All @@ -125,14 +125,14 @@ export default {
},
loc: getLocation(node),
messageId: 'expectedParens',
node,
node
});
}
}
};

return {
ArrowFunctionExpression: parens,
ArrowFunctionExpression: parens
};
},

Expand All @@ -141,7 +141,7 @@ export default {
category: 'ECMAScript 6',
description: 'require parentheses around arrow function arguments',
recommended: false,
url: 'https://eslint.org/docs/rules/arrow-parens',
url: 'https://eslint.org/docs/rules/arrow-parens'
},

fixable: 'code',
Expand All @@ -151,25 +151,25 @@ export default {
expectedParensBlock: 'Expected parentheses around arrow function argument having a body with curly braces.',

unexpectedParens: 'Unexpected parentheses around single function argument.',
unexpectedParensInline: 'Unexpected parentheses around single function argument having a body with no curly braces.',
unexpectedParensInline: 'Unexpected parentheses around single function argument having a body with no curly braces.'
},

type: 'layout',
type: 'layout'
},

schema: [
{
enum: ['always', 'as-needed'],
enum: ['always', 'as-needed']
},
{
additionalProperties: false,
properties: {
requireForBlockBody: {
default: false,
type: 'boolean',
},
type: 'boolean'
}
},
type: 'object',
},
],
type: 'object'
}
]
};
12 changes: 6 additions & 6 deletions src/rules/booleanStyle.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const schema = [
{
enum: ['bool', 'boolean'],
type: 'string',
},
type: 'string'
}
];

const create = (context) => {
Expand All @@ -18,7 +18,7 @@ const create = (context) => {
return fixer.replaceText(node, 'boolean');
},
message: 'Use "boolean", not "bool"',
node,
node
});
}

Expand All @@ -28,14 +28,14 @@ const create = (context) => {
return fixer.replaceText(node, 'bool');
},
message: 'Use "bool", not "boolean"',
node,
node
});
}
},
}
};
};

export default {
create,
schema,
schema
};
4 changes: 2 additions & 2 deletions src/rules/defineFlowType.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ const create = (context) => {
node.params.forEach((param) => {
makeDefined(param);
});
},
}
};
};

export default {
create,
schema,
schema
};

0 comments on commit b0477b2

Please sign in to comment.