diff --git a/src/bin/addAssertions.js b/src/bin/addAssertions.js index 8a08486b..58114653 100644 --- a/src/bin/addAssertions.js +++ b/src/bin/addAssertions.js @@ -48,7 +48,7 @@ const getAssertions = () => { return { invalid: _.map(codes.invalid, formatCodeSnippet), - valid: _.map(codes.valid, formatCodeSnippet) + valid: _.map(codes.valid, formatCodeSnippet), }; }); diff --git a/src/bin/checkDocs.js b/src/bin/checkDocs.js index b6acd865..933edb91 100644 --- a/src/bin/checkDocs.js +++ b/src/bin/checkDocs.js @@ -6,7 +6,7 @@ import fs from 'fs'; import path from 'path'; import { getRules, - isFile + isFile, } from './utilities'; const windows = (array, size) => { diff --git a/src/bin/checkTests.js b/src/bin/checkTests.js index 22e4a9ec..8acef78c 100644 --- a/src/bin/checkTests.js +++ b/src/bin/checkTests.js @@ -4,7 +4,7 @@ import fs from 'fs'; import path from 'path'; import { getRules, - isFile + isFile, } from './utilities'; const getTestIndexRules = () => { @@ -24,7 +24,7 @@ const getTestIndexRules = () => { return acc; }, { inRulesArray: false, - rules: [] + rules: [], }); const rules = result.rules; diff --git a/src/index.js b/src/index.js index 58ea1e15..87f59cb5 100644 --- a/src/index.js +++ b/src/index.js @@ -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') { @@ -92,7 +92,7 @@ export default { return { ...rule, - create: _.partial(checkFlowFileAnnotation, rule.create) + create: _.partial(checkFlowFileAnnotation, rule.create), }; }), rulesConfig: { @@ -123,6 +123,6 @@ export default { 'type-import-style': 0, 'union-intersection-spacing': 0, 'use-flow-type': 0, - 'valid-syntax': 0 - } + 'valid-syntax': 0, + }, }; diff --git a/src/rules/arrayStyle/index.js b/src/rules/arrayStyle/index.js index 4ee744b6..8f1b3b36 100644 --- a/src/rules/arrayStyle/index.js +++ b/src/rules/arrayStyle/index.js @@ -4,8 +4,8 @@ import needWrap from './needWrap'; const schema = [ { enum: ['verbose', 'shorthand'], - type: 'string' - } + type: 'string', + }, ]; const inlineType = (type) => { @@ -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, }); } }, @@ -59,7 +59,7 @@ export default (defaultConfig, simpleType) => { context.report({ data: { type: inlinedType, - wrappedType: wrappedInlinedType + wrappedType: wrappedInlinedType, }, fix (fixer) { if (needWrap(elementTypeNode)) { @@ -69,17 +69,17 @@ export default (defaultConfig, simpleType) => { } }, message: 'Use "{{ wrappedType }}[]", not "Array<{{ type }}>"', - node + node, }); } } } - } + }, }; }; return { create, - schema + schema, }; }; diff --git a/src/rules/arrayStyle/isSimpleType.js b/src/rules/arrayStyle/isSimpleType.js index 1cbdf2f6..0b987e5b 100644 --- a/src/rules/arrayStyle/isSimpleType.js +++ b/src/rules/arrayStyle/isSimpleType.js @@ -20,7 +20,7 @@ const simpleTypePatterns = [ /^(?:Any|Array|Boolean|Generic|Mixed|Number|String|Void)TypeAnnotation$/, - /.+LiteralTypeAnnotation$/ + /.+LiteralTypeAnnotation$/, ]; export default (node) => { diff --git a/src/rules/arrowParens.js b/src/rules/arrowParens.js index 449b00a0..2606fc25 100644 --- a/src/rules/arrowParens.js +++ b/src/rules/arrowParens.js @@ -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, }; }; @@ -40,7 +40,7 @@ export default { return fixer.replaceTextRange([ firstTokenOfParam.range[0], - closingParenToken.range[1] + closingParenToken.range[1], ], `${shouldAddSpaceForAsync ? ' ' : ''}${paramToken.value}`); }; @@ -70,7 +70,7 @@ export default { fix: fixParamsWithParenthesis, loc: getLocation(node), messageId: 'unexpectedParensInline', - node + node, }); } @@ -88,7 +88,7 @@ export default { }, loc: getLocation(node), messageId: 'expectedParensBlock', - node + node, }); } @@ -107,7 +107,7 @@ export default { fix: fixParamsWithParenthesis, loc: getLocation(node), messageId: 'unexpectedParens', - node + node, }); } @@ -125,14 +125,14 @@ export default { }, loc: getLocation(node), messageId: 'expectedParens', - node + node, }); } } }; return { - ArrowFunctionExpression: parens + ArrowFunctionExpression: parens, }; }, @@ -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', @@ -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', + }, + ], }; diff --git a/src/rules/booleanStyle.js b/src/rules/booleanStyle.js index e484a06a..68388d9d 100644 --- a/src/rules/booleanStyle.js +++ b/src/rules/booleanStyle.js @@ -1,8 +1,8 @@ const schema = [ { enum: ['bool', 'boolean'], - type: 'string' - } + type: 'string', + }, ]; const create = (context) => { @@ -18,7 +18,7 @@ const create = (context) => { return fixer.replaceText(node, 'boolean'); }, message: 'Use "boolean", not "bool"', - node + node, }); } @@ -28,14 +28,14 @@ const create = (context) => { return fixer.replaceText(node, 'bool'); }, message: 'Use "bool", not "boolean"', - node + node, }); } - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/defineFlowType.js b/src/rules/defineFlowType.js index 764641c8..1e065bfd 100644 --- a/src/rules/defineFlowType.js +++ b/src/rules/defineFlowType.js @@ -71,11 +71,11 @@ const create = (context) => { node.params.forEach((param) => { makeDefined(param); }); - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/delimiterDangle.js b/src/rules/delimiterDangle.js index ec683d23..ed57d012 100644 --- a/src/rules/delimiterDangle.js +++ b/src/rules/delimiterDangle.js @@ -3,8 +3,8 @@ import _ from 'lodash'; const schema = [ { enum: ['always', 'always-multiline', 'only-multiline', 'never'], - type: 'string' - } + type: 'string', + }, ]; const create = (context) => { @@ -16,7 +16,7 @@ const create = (context) => { context.report({ fix, message, - node + node, }); }; }; @@ -28,7 +28,7 @@ const create = (context) => { }), noDangle: reporter(node, 'Missing trailing delimiter', (fixer) => { return fixer.insertTextAfter(tokenToFix, ','); - }) + }), }; }; @@ -105,11 +105,11 @@ const create = (context) => { TupleTypeAnnotation (node) { evaluate(node, _.last(node.types)); - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/genericSpacing.js b/src/rules/genericSpacing.js index c0a6e483..dcc270d4 100644 --- a/src/rules/genericSpacing.js +++ b/src/rules/genericSpacing.js @@ -3,8 +3,8 @@ import {spacingFixers} from '../utilities'; const schema = [ { enum: ['always', 'never'], - type: 'string' - } + type: 'string', + }, ]; const create = (context) => { @@ -35,7 +35,7 @@ const create = (context) => { data: {name: node.id.name}, fix: spacingFixers.stripSpacesAfter(opener, spacesBefore), message: 'There must be no space at start of "{{name}}" generic type annotation', - node: types + node: types, }); } @@ -44,7 +44,7 @@ const create = (context) => { data: {name: node.id.name}, fix: spacingFixers.stripSpacesAfter(lastInnerToken, spacesAfter), message: 'There must be no space at end of "{{name}}" generic type annotation', - node: types + node: types, }); } } else { @@ -53,14 +53,14 @@ const create = (context) => { data: {name: node.id.name}, fix: spacingFixers.stripSpacesAfter(opener, spacesBefore - 1), message: 'There must be one space at start of "{{name}}" generic type annotation', - node: types + node: types, }); } else if (spacesBefore === 0) { context.report({ data: {name: node.id.name}, fix: spacingFixers.addSpaceAfter(opener), message: 'There must be a space at start of "{{name}}" generic type annotation', - node: types + node: types, }); } @@ -69,22 +69,22 @@ const create = (context) => { data: {name: node.id.name}, fix: spacingFixers.stripSpacesAfter(lastInnerToken, spacesAfter - 1), message: 'There must be one space at end of "{{name}}" generic type annotation', - node: types + node: types, }); } else if (spacesAfter === 0) { context.report({ data: {name: node.id.name}, fix: spacingFixers.addSpaceAfter(lastInnerToken), message: 'There must be a space at end of "{{name}}" generic type annotation', - node: types + node: types, }); } } - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/newlineAfterFlowAnnotation.js b/src/rules/newlineAfterFlowAnnotation.js index a67ea725..6a86fc83 100644 --- a/src/rules/newlineAfterFlowAnnotation.js +++ b/src/rules/newlineAfterFlowAnnotation.js @@ -7,8 +7,8 @@ const looksLikeFlowFileAnnotation = (comment) => { const schema = [ { enum: ['always', 'always-windows', 'never'], - type: 'string' - } + type: 'string', + }, ]; const create = (context) => { @@ -41,7 +41,7 @@ const create = (context) => { ); }, message: 'Expected newline after flow annotation', - node + node, }); } @@ -55,22 +55,22 @@ const create = (context) => { potentialFlowFileAnnotation.end, potentialFlowFileAnnotation.end + ( lineBreak === '\r' ? 2 : 1 - ) + ), ], '' ); }, message: 'Expected no newline after flow annotation', - node + node, }); } } - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/noDupeKeys.js b/src/rules/noDupeKeys.js index 8b68dba5..6fe87dc1 100644 --- a/src/rules/noDupeKeys.js +++ b/src/rules/noDupeKeys.js @@ -1,6 +1,6 @@ import _ from 'lodash/'; import { - getParameterName + getParameterName, } from '../utilities'; const schema = []; @@ -10,7 +10,7 @@ const create = (context) => { context.report({ loc: node.loc, message: 'Duplicate property.', - node + node, }); }; @@ -37,7 +37,7 @@ const create = (context) => { return { type, - value + value, }; }; @@ -57,7 +57,7 @@ const create = (context) => { return { ...element, - name: getParameterName(property, context) + name: getParameterName(property, context), }; }); }; @@ -90,11 +90,11 @@ const create = (context) => { }; return { - ObjectTypeAnnotation: checkForDuplicates + ObjectTypeAnnotation: checkForDuplicates, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/noExistentialType.js b/src/rules/noExistentialType.js index f2f126a8..455ec01f 100644 --- a/src/rules/noExistentialType.js +++ b/src/rules/noExistentialType.js @@ -4,7 +4,7 @@ const reporter = (context) => { return (node) => { context.report({ message: 'Unexpected use of existential type (*).', - node + node, }); }; }; @@ -12,11 +12,11 @@ const reporter = (context) => { const create = (context) => { return { ExistentialTypeParam: reporter(context), - ExistsTypeAnnotation: reporter(context) + ExistsTypeAnnotation: reporter(context), }; }; export default { - create + create, }; diff --git a/src/rules/noFlowFixMeComments.js b/src/rules/noFlowFixMeComments.js index 72cb6b80..55920712 100644 --- a/src/rules/noFlowFixMeComments.js +++ b/src/rules/noFlowFixMeComments.js @@ -1,7 +1,7 @@ const schema = [ { - type: 'string' - } + type: 'string', + }, ]; const message = '$FlowFixMe is treated as `any` and should be fixed.'; @@ -35,7 +35,7 @@ const create = (context) => { if (isIdentifier(node.id, /\$FlowFixMe/)) { context.report({ message, - node: node.id + node: node.id, }); } }, @@ -48,11 +48,11 @@ const create = (context) => { return comment.type === 'Block' || comment.type === 'Line'; }) .forEach(handleComment); - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/noMixed.js b/src/rules/noMixed.js index f8bebf73..eccc73c1 100644 --- a/src/rules/noMixed.js +++ b/src/rules/noMixed.js @@ -5,13 +5,13 @@ const create = (context) => { MixedTypeAnnotation (node) { context.report({ message: 'Unexpected use of mixed type', - node + node, }); - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/noMutableArray.js b/src/rules/noMutableArray.js index 5dd7c653..f0426173 100644 --- a/src/rules/noMutableArray.js +++ b/src/rules/noMutableArray.js @@ -38,7 +38,7 @@ const create = (context) => { return fixer.replaceText(node, '$ReadOnlyArray<' + rawElementType + '>'); }, message: 'Use "$ReadOnlyArray" instead of array shorthand notation', - node + node, }); } }, @@ -49,14 +49,14 @@ const create = (context) => { return fixer.replaceText(node.id, '$ReadOnlyArray'); }, message: 'Use "$ReadOnlyArray" instead of "Array"', - node + node, }); } - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/noPrimitiveConstructorTypes.js b/src/rules/noPrimitiveConstructorTypes.js index 10dfbf1f..9a50108b 100644 --- a/src/rules/noPrimitiveConstructorTypes.js +++ b/src/rules/noPrimitiveConstructorTypes.js @@ -12,18 +12,18 @@ const create = (context) => { if (regex.test(name)) { context.report({ data: { - name + name, }, loc: node.loc, message: 'Unexpected use of {{name}} constructor type.', - node + node, }); } - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/noTypesMissingFileAnnotation.js b/src/rules/noTypesMissingFileAnnotation.js index 5efddd82..a1cf2dd9 100644 --- a/src/rules/noTypesMissingFileAnnotation.js +++ b/src/rules/noTypesMissingFileAnnotation.js @@ -17,7 +17,7 @@ const create = (context) => { context.report({ data: {type}, message: 'Type {{type}} require valid Flow declaration.', - node + node, }); }; @@ -43,11 +43,11 @@ const create = (context) => { }, TypeAnnotation (node) { reporter(node, 'annotations'); - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/noUnusedExpressions.js b/src/rules/noUnusedExpressions.js index 9d2bdb32..2fd292b7 100644 --- a/src/rules/noUnusedExpressions.js +++ b/src/rules/noUnusedExpressions.js @@ -13,11 +13,11 @@ const create = (context) => { if (node.expression.type !== 'TypeCastExpression') { coreChecks.ExpressionStatement(node); } - } + }, }; }; export default { create, - meta + meta, }; diff --git a/src/rules/noWeakTypes.js b/src/rules/noWeakTypes.js index 33941872..ef6bf818 100644 --- a/src/rules/noWeakTypes.js +++ b/src/rules/noWeakTypes.js @@ -5,17 +5,17 @@ const schema = [ additionalProperties: false, properties: { any: { - type: 'boolean' + type: 'boolean', }, Function: { - type: 'boolean' + type: 'boolean', }, Object: { - type: 'boolean' - } + type: 'boolean', + }, }, - type: 'object' - } + type: 'object', + }, ]; const reportWeakType = (context, weakType) => { @@ -23,7 +23,7 @@ const reportWeakType = (context, weakType) => { context.report({ data: {weakType}, message: 'Unexpected use of weak type "{{weakType}}"', - node + node, }); }; }; @@ -52,7 +52,7 @@ const create = (context) => { if (checkFunction || checkObject) { checks.GenericTypeAnnotation = genericTypeEvaluator(context, { checkFunction, - checkObject + checkObject, }); } @@ -61,5 +61,5 @@ const create = (context) => { export default { create, - schema + schema, }; diff --git a/src/rules/objectTypeDelimiter.js b/src/rules/objectTypeDelimiter.js index d82fe93c..fe15a2d0 100644 --- a/src/rules/objectTypeDelimiter.js +++ b/src/rules/objectTypeDelimiter.js @@ -3,12 +3,12 @@ const SEMICOLON = { char: ';', - name: 'semicolon' + name: 'semicolon', }; const COMMA = { char: ',', - name: 'comma' + name: 'comma', }; const create = (context) => { @@ -44,7 +44,7 @@ const create = (context) => { return fixer.replaceText(lastToken, GOOD.char); }, message: 'Prefer ' + GOOD.name + 's to ' + BAD.name + 's in object and class types', - node: lastToken + node: lastToken, }); } } @@ -53,18 +53,18 @@ const create = (context) => { return { ObjectTypeCallProperty: requireProperPunctuation, ObjectTypeIndexer: requireProperPunctuation, - ObjectTypeProperty: requireProperPunctuation + ObjectTypeProperty: requireProperPunctuation, }; }; const schema = [ { enum: ['semicolon', 'comma'], - type: 'string' - } + type: 'string', + }, ]; export default { create, - schema + schema, }; diff --git a/src/rules/requireCompoundTypeAlias.js b/src/rules/requireCompoundTypeAlias.js index 54598c5b..f056c39b 100644 --- a/src/rules/requireCompoundTypeAlias.js +++ b/src/rules/requireCompoundTypeAlias.js @@ -1,8 +1,8 @@ const schema = [ { enum: ['always', 'never'], - type: 'string' - } + type: 'string', + }, ]; const create = (context) => { @@ -14,7 +14,7 @@ const create = (context) => { if (node.parent.type !== 'TypeAlias') { context.report({ message: 'All intersection types must be declared with named type alias.', - node + node, }); } }, @@ -22,10 +22,10 @@ const create = (context) => { if (node.parent.type !== 'TypeAlias') { context.report({ message: 'All union types must be declared with named type alias.', - node + node, }); } - } + }, }; } else { return {}; @@ -34,5 +34,5 @@ const create = (context) => { export default { create, - schema + schema, }; diff --git a/src/rules/requireExactType.js b/src/rules/requireExactType.js index e24d5193..885439ef 100644 --- a/src/rules/requireExactType.js +++ b/src/rules/requireExactType.js @@ -1,8 +1,8 @@ const schema = [ { enum: ['always', 'never'], - type: 'string' - } + type: 'string', + }, ]; const create = (context) => { @@ -17,7 +17,7 @@ const create = (context) => { context.report({ data: {name}, message: 'Type identifier \'{{name}}\' must be exact.', - node + node, }); } @@ -25,15 +25,15 @@ const create = (context) => { context.report({ data: {name}, message: 'Type identifier \'{{name}}\' must not be exact.', - node + node, }); } } - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/requireInexactType.js b/src/rules/requireInexactType.js index d048afe0..872cf9a8 100644 --- a/src/rules/requireInexactType.js +++ b/src/rules/requireInexactType.js @@ -1,8 +1,8 @@ const schema = [ { enum: ['always', 'never'], - type: 'string' - } + type: 'string', + }, ]; const create = (context) => { @@ -19,21 +19,21 @@ const create = (context) => { if (always && !inexact && !exact) { context.report({ message: 'Type must be explicit inexact.', - node + node, }); } if (!always && inexact) { context.report({ message: 'Type must not be explicit inexact.', - node + node, }); } - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/requireParameterType.js b/src/rules/requireParameterType.js index a5ad0709..a527eeb6 100644 --- a/src/rules/requireParameterType.js +++ b/src/rules/requireParameterType.js @@ -2,7 +2,7 @@ import _ from 'lodash'; import { getParameterName, iterateFunctionNodes, - quoteName + quoteName, } from '../utilities'; const schema = [ @@ -10,14 +10,14 @@ const schema = [ additionalProperties: false, properties: { excludeArrowFunctions: { - enum: [false, true, 'expressionsOnly'] + enum: [false, true, 'expressionsOnly'], }, excludeParameterMatch: { - type: 'string' - } + type: 'string', + }, }, - type: 'object' - } + type: 'object', + }, ]; const create = iterateFunctionNodes((context) => { @@ -56,10 +56,10 @@ const create = iterateFunctionNodes((context) => { if (!typeAnnotation) { context.report({ data: { - name: quoteName(parameterName) + name: quoteName(parameterName), }, message: 'Missing {{name}}parameter type annotation.', - node: identifierNode + node: identifierNode, }); } }); @@ -68,5 +68,5 @@ const create = iterateFunctionNodes((context) => { export default { create, - schema + schema, }; diff --git a/src/rules/requireReadonlyReactProps.js b/src/rules/requireReadonlyReactProps.js index f52ff92c..2351daae 100644 --- a/src/rules/requireReadonlyReactProps.js +++ b/src/rules/requireReadonlyReactProps.js @@ -71,14 +71,14 @@ const create = (context) => { if (isReactComponent(node) && isReadOnlyClassProp(node)) { context.report({ message: node.superTypeParameters.params[0].id.name + ' must be $ReadOnly', - node + node, }); } else if (node.superTypeParameters && node.superTypeParameters.params[0].type === 'ObjectTypeAnnotation' && !isReadOnlyObjectType(node.superTypeParameters.params[0])) { context.report({ message: node.id.name + ' class props must be $ReadOnly', - node + node, }); } }, @@ -109,7 +109,7 @@ const create = (context) => { context.report({ message: identifier.name + ' must be $ReadOnly', - node + node, }); reportedFunctionalComponents.push(identifier); @@ -121,15 +121,15 @@ const create = (context) => { !isReadOnlyObjectType(typeAnnotation.typeAnnotation)) { context.report({ message: currentNode.id.name + ' component props must be $ReadOnly', - node + node, }); } } - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/requireReturnType.js b/src/rules/requireReturnType.js index 9352ec5b..b1c55706 100644 --- a/src/rules/requireReturnType.js +++ b/src/rules/requireReturnType.js @@ -3,33 +3,33 @@ import _ from 'lodash'; const schema = [ { enum: ['always'], - type: 'string' + type: 'string', }, { additionalProperties: false, properties: { annotateUndefined: { enum: ['always', 'never', 'ignore'], - type: 'string' + type: 'string', }, excludeArrowFunctions: { - enum: [false, true, 'expressionsOnly'] + enum: [false, true, 'expressionsOnly'], }, excludeMatching: { items: { - type: 'string' + type: 'string', }, - type: 'array' + type: 'array', }, includeOnlyMatching: { items: { - type: 'string' + type: 'string', }, - type: 'array' - } + type: 'array', + }, }, - type: 'object' - } + type: 'object', + }, ]; const create = (context) => { @@ -48,7 +48,7 @@ const create = (context) => { const registerFunction = (functionNode) => { targetNodes.push({ - functionNode + functionNode, }); }; @@ -147,11 +147,11 @@ const create = (context) => { if (targetNodes.length) { targetNodes[targetNodes.length - 1].returnStatementNode = node; } - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/requireTypesAtTop.js b/src/rules/requireTypesAtTop.js index 2a9cf98b..7ac87606 100644 --- a/src/rules/requireTypesAtTop.js +++ b/src/rules/requireTypesAtTop.js @@ -3,8 +3,8 @@ import _ from 'lodash'; const schema = [ { enum: ['always', 'never'], - type: 'string' - } + type: 'string', + }, ]; const create = (context) => { @@ -36,7 +36,7 @@ const create = (context) => { // opaque type Foo = ... (node) => { return node.type === 'OpaqueType'; - } + }, ]; const isIgnoredNode = (node) => { @@ -68,10 +68,10 @@ const create = (context) => { if (node.range[0] > regularCodeStartRange[0]) { context.report({ message: 'All type declaration should be at the top of the file, after any import declarations.', - node + node, }); } - } + }, }; } else { return {}; @@ -80,5 +80,5 @@ const create = (context) => { export default { create, - schema + schema, }; diff --git a/src/rules/requireValidFileAnnotation.js b/src/rules/requireValidFileAnnotation.js index e12f10be..86421e8b 100644 --- a/src/rules/requireValidFileAnnotation.js +++ b/src/rules/requireValidFileAnnotation.js @@ -1,12 +1,12 @@ import _ from 'lodash'; import { isFlowFileAnnotation, - fuzzyStringMatch + fuzzyStringMatch, } from '../utilities'; const defaults = { annotationStyle: 'none', - strict: false + strict: false, }; const looksLikeFlowFileAnnotation = (comment) => { @@ -36,22 +36,22 @@ const noFlowAnnotation = (comment) => { const schema = [ { enum: ['always', 'never'], - type: 'string' + type: 'string', }, { additionalProperties: false, properties: { annotationStyle: { enum: ['none', 'line', 'block'], - type: 'string' + type: 'string', }, strict: { enum: [true, false], - type: 'boolean' - } + type: 'boolean', + }, }, - type: 'object' - } + type: 'object', + }, ]; const create = (context) => { @@ -104,7 +104,7 @@ const create = (context) => { context.report({ fix: addStrictAnnotation(), message: 'Strict Flow file annotation is required, should be ' + str, - node + node, }); } } @@ -117,14 +117,14 @@ const create = (context) => { context.report({ fix: addAnnotation(), message: 'Flow file annotation is missing.', - node + node, }); } - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/requireVariableType.js b/src/rules/requireVariableType.js index 600ae519..3ad30477 100644 --- a/src/rules/requireVariableType.js +++ b/src/rules/requireVariableType.js @@ -1,7 +1,7 @@ import _ from 'lodash'; import { isFlowFile, - quoteName + quoteName, } from '../utilities'; const schema = [ @@ -9,26 +9,26 @@ const schema = [ additionalProperties: false, properties: { excludeVariableMatch: { - type: 'string' + type: 'string', }, excludeVariableTypes: { additionalProperties: false, properties: { const: { - type: 'boolean' + type: 'boolean', }, let: { - type: 'boolean' + type: 'boolean', }, var: { - type: 'boolean' - } + type: 'boolean', + }, }, - type: 'object' - } + type: 'object', + }, }, - type: 'object' - } + type: 'object', + }, ]; const create = (context) => { @@ -62,18 +62,18 @@ const create = (context) => { if (!typeAnnotation) { context.report({ data: { - name: quoteName(identifierName) + name: quoteName(identifierName), }, message: 'Missing {{name}}variable type annotation.', - node: identifierNode + node: identifierNode, }); } }); - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/semi.js b/src/rules/semi.js index 09f807f7..0f4b031c 100644 --- a/src/rules/semi.js +++ b/src/rules/semi.js @@ -1,8 +1,8 @@ const schema = [ { enum: ['always', 'never'], - type: 'string' - } + type: 'string', + }, ]; const create = (context) => { @@ -33,7 +33,7 @@ const create = (context) => { fix, loc, message, - node + node, }); }; @@ -56,11 +56,11 @@ const create = (context) => { return { OpaqueType: checkForSemicolon, - TypeAlias: checkForSemicolon + TypeAlias: checkForSemicolon, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/sortKeys.js b/src/rules/sortKeys.js index b17dbac5..45e1d956 100644 --- a/src/rules/sortKeys.js +++ b/src/rules/sortKeys.js @@ -1,30 +1,30 @@ import _ from 'lodash'; import { - getParameterName + getParameterName, } from '../utilities'; const defaults = { caseSensitive: true, - natural: false + natural: false, }; const schema = [ { enum: ['asc', 'desc'], - type: 'string' + type: 'string', }, { additionalProperties: false, properties: { caseSensitive: { - type: 'boolean' + type: 'boolean', }, natural: { - type: 'boolean' - } + type: 'boolean', + }, }, - type: 'object' - } + type: 'object', + }, ]; /** @@ -62,12 +62,12 @@ const isValidOrders = { }, naturalCompare (str1, str2) { return str1.localeCompare(str2, 'en-US', {numeric: true}); - } + }, }; const variances = { minus: '-', - plus: '+' + plus: '+', }; const getVariance = (node) => { @@ -163,7 +163,7 @@ const create = (context) => { insensitive: insensitive ? 'insensitive ' : '', last, natural: natural ? 'natural ' : '', - order + order, }, fix (fixer) { const nodeText = generateFix(node, context, isValidOrder); @@ -172,18 +172,18 @@ const create = (context) => { }, loc: identifierNode.loc, message: 'Expected type annotations to be in {{natural}}{{insensitive}}{{order}}ending order. "{{current}}" should be before "{{last}}".', - node: identifierNode + node: identifierNode, }); } }); }; return { - ObjectTypeAnnotation: checkKeyOrder + ObjectTypeAnnotation: checkKeyOrder, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/spaceAfterTypeColon.js b/src/rules/spaceAfterTypeColon.js index 25085d94..0c202422 100644 --- a/src/rules/spaceAfterTypeColon.js +++ b/src/rules/spaceAfterTypeColon.js @@ -4,27 +4,27 @@ import makeSpacing from './typeColonSpacing'; const schema = [ { enum: ['always', 'never'], - type: 'string' + type: 'string', }, { additionalProperties: false, properties: { allowLineBreak: { - type: 'boolean' - } + type: 'boolean', + }, }, - type: 'object' - } + type: 'object', + }, ]; const create = (context) => { return makeSpacing('after', context, { allowLineBreak: _.get(context, ['options', '1', 'allowLineBreak'], false), - always: _.get(context, ['options', '0'], 'always') === 'always' + always: _.get(context, ['options', '0'], 'always') === 'always', }); }; export default { create, - schema + schema, }; diff --git a/src/rules/spaceBeforeGenericBracket.js b/src/rules/spaceBeforeGenericBracket.js index e1592f65..31afd73b 100644 --- a/src/rules/spaceBeforeGenericBracket.js +++ b/src/rules/spaceBeforeGenericBracket.js @@ -3,8 +3,8 @@ import {spacingFixers} from '../utilities'; const schema = [ { enum: ['always', 'never'], - type: 'string' - } + type: 'string', + }, ]; const create = (context) => { @@ -28,7 +28,7 @@ const create = (context) => { data: {name: node.id.name}, fix: spacingFixers.stripSpacesAfter(node.id, spaceBefore), message: 'There must be no space before "{{name}}" generic type annotation bracket', - node + node, }); } @@ -37,7 +37,7 @@ const create = (context) => { data: {name: node.id.name}, fix: spacingFixers.addSpaceAfter(node.id), message: 'There must be a space before "{{name}}" generic type annotation bracket', - node + node, }); } @@ -46,14 +46,14 @@ const create = (context) => { data: {name: node.id.name}, fix: spacingFixers.stripSpacesAfter(node.id, spaceBefore - 1), message: 'There must be one space before "{{name}}" generic type annotation bracket', - node + node, }); } - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/spaceBeforeTypeColon.js b/src/rules/spaceBeforeTypeColon.js index 4515bb60..20c2610d 100644 --- a/src/rules/spaceBeforeTypeColon.js +++ b/src/rules/spaceBeforeTypeColon.js @@ -3,17 +3,17 @@ import makeSpacing from './typeColonSpacing'; const schema = [ { enum: ['always', 'never'], - type: 'string' - } + type: 'string', + }, ]; const create = (context) => { return makeSpacing('before', context, { - always: context.options[0] === 'always' + always: context.options[0] === 'always', }); }; export default { create, - schema + schema, }; diff --git a/src/rules/spreadExactType.js b/src/rules/spreadExactType.js index a7807b0d..03873f11 100644 --- a/src/rules/spreadExactType.js +++ b/src/rules/spreadExactType.js @@ -1,8 +1,8 @@ const schema = [ { enum: ['always', 'never'], - type: 'string' - } + type: 'string', + }, ]; const create = (context) => { @@ -18,16 +18,16 @@ const create = (context) => { argumentType !== 'GenericTypeAnnotation' || argumentId.name !== '$Exact') { context.report({ message: 'Use $Exact to make type spreading safe.', - node + node, }); } } }); - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/typeColonSpacing/evaluateObjectTypeIndexer.js b/src/rules/typeColonSpacing/evaluateObjectTypeIndexer.js index 914be1ee..31baf346 100644 --- a/src/rules/typeColonSpacing/evaluateObjectTypeIndexer.js +++ b/src/rules/typeColonSpacing/evaluateObjectTypeIndexer.js @@ -8,14 +8,14 @@ export default (context, report) => { // ^ report({ colon: getTokenBeforeParens(sourceCode, objectTypeIndexer.key), - node: objectTypeIndexer + node: objectTypeIndexer, }); // type X = { [a: b]: c } // ^ report({ colon: sourceCode.getTokenAfter(getTokenAfterParens(sourceCode, objectTypeIndexer.key)), - node: objectTypeIndexer + node: objectTypeIndexer, }); }; }; diff --git a/src/rules/typeColonSpacing/evaluateObjectTypeProperty.js b/src/rules/typeColonSpacing/evaluateObjectTypeProperty.js index 71abbaa8..11a94ae0 100644 --- a/src/rules/typeColonSpacing/evaluateObjectTypeProperty.js +++ b/src/rules/typeColonSpacing/evaluateObjectTypeProperty.js @@ -37,7 +37,7 @@ export default (context, report) => { report({ colon: getColon(context, objectTypeProperty), name: quoteName(getParameterName(objectTypeProperty, context)), - node: objectTypeProperty + node: objectTypeProperty, }); }; }; diff --git a/src/rules/typeColonSpacing/evaluateReturnType.js b/src/rules/typeColonSpacing/evaluateReturnType.js index d1815fbf..a4ba1eee 100644 --- a/src/rules/typeColonSpacing/evaluateReturnType.js +++ b/src/rules/typeColonSpacing/evaluateReturnType.js @@ -9,7 +9,7 @@ export default (context, report) => { report({ colon: sourceCode.getFirstToken(functionNode.returnType), node: functionNode, - type: 'return type' + type: 'return type', }); } }; diff --git a/src/rules/typeColonSpacing/evaluateTypeCastExpression.js b/src/rules/typeColonSpacing/evaluateTypeCastExpression.js index bf77f9f6..a8a7dabb 100644 --- a/src/rules/typeColonSpacing/evaluateTypeCastExpression.js +++ b/src/rules/typeColonSpacing/evaluateTypeCastExpression.js @@ -5,7 +5,7 @@ export default (context, report) => { report({ colon: sourceCode.getFirstToken(typeCastExpression.typeAnnotation), node: typeCastExpression, - type: 'type cast' + type: 'type cast', }); }; }; diff --git a/src/rules/typeColonSpacing/evaluateTypical.js b/src/rules/typeColonSpacing/evaluateTypical.js index c2228d24..5d3c3f02 100644 --- a/src/rules/typeColonSpacing/evaluateTypical.js +++ b/src/rules/typeColonSpacing/evaluateTypical.js @@ -20,7 +20,7 @@ export default (context, report, typeForMessage) => { colon: getColon(node, typeAnnotation), name: quoteName(getParameterName(node, context)), node, - type: typeForMessage + ' type annotation' + type: typeForMessage + ' type annotation', }); } }; diff --git a/src/rules/typeColonSpacing/evaluateVariables.js b/src/rules/typeColonSpacing/evaluateVariables.js index 2ed99ec0..ac437eac 100644 --- a/src/rules/typeColonSpacing/evaluateVariables.js +++ b/src/rules/typeColonSpacing/evaluateVariables.js @@ -15,7 +15,7 @@ export default (context, report) => { colon: sourceCode.getFirstToken(typeAnnotation), name: quoteName(getParameterName(leaf, context)), node: leaf, - type: node.kind + ' type annotation' + type: node.kind + ' type annotation', }); } }); diff --git a/src/rules/typeColonSpacing/index.js b/src/rules/typeColonSpacing/index.js index 53d0d556..e64cb757 100644 --- a/src/rules/typeColonSpacing/index.js +++ b/src/rules/typeColonSpacing/index.js @@ -15,6 +15,6 @@ export default (direction, context, options) => { ObjectTypeIndexer: evaluateObjectTypeIndexer(context, report), ObjectTypeProperty: evaluateObjectTypeProperty(context, report), TypeCastExpression: evaluateTypeCastExpression(context, report), - VariableDeclaration: evaluateVariables(context, report) + VariableDeclaration: evaluateVariables(context, report), }; }; diff --git a/src/rules/typeColonSpacing/reporter.js b/src/rules/typeColonSpacing/reporter.js index 93619d82..8527fb2a 100644 --- a/src/rules/typeColonSpacing/reporter.js +++ b/src/rules/typeColonSpacing/reporter.js @@ -35,7 +35,7 @@ export default (direction, context, {always, allowLineBreak}) => { const data = { direction, name, - type + type, }; if (hasLineBreak(direction, colon, context)) { @@ -54,28 +54,28 @@ export default (direction, context, {always, allowLineBreak}) => { data, fix: spacingFixers.replaceWithSpace(direction, colon, spaces), message: 'There must not be a line break {{direction}} {{name}}{{type}} colon.', - node + node, }); } else if (always && spaces > 1) { context.report({ data, fix: spacingFixers.stripSpaces(direction, colon, spaces - 1), message: 'There must be 1 space {{direction}} {{name}}{{type}} colon.', - node + node, }); } else if (always && spaces === 0) { context.report({ data, fix: spacingFixers.addSpace(direction, colon), message: 'There must be a space {{direction}} {{name}}{{type}} colon.', - node + node, }); } else if (!always && spaces > 0) { context.report({ data, fix: spacingFixers.stripSpaces(direction, colon, spaces), message: 'There must be no space {{direction}} {{name}}{{type}} colon.', - node + node, }); } }; diff --git a/src/rules/typeIdMatch.js b/src/rules/typeIdMatch.js index c9ac83d7..916860eb 100644 --- a/src/rules/typeIdMatch.js +++ b/src/rules/typeIdMatch.js @@ -1,7 +1,7 @@ const schema = [ { - type: 'string' - } + type: 'string', + }, ]; const create = (context) => { @@ -14,14 +14,14 @@ const create = (context) => { if (!pattern.test(typeIdentifierName)) { context.report(typeAliasNode, 'Type identifier \'{{name}}\' does not match pattern \'{{pattern}}\'.', { name: typeIdentifierName, - pattern: pattern.toString() + pattern: pattern.toString(), }); } - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/typeImportStyle.js b/src/rules/typeImportStyle.js index 6ee50690..b96a3d97 100644 --- a/src/rules/typeImportStyle.js +++ b/src/rules/typeImportStyle.js @@ -1,17 +1,17 @@ const schema = [ { enum: ['declaration', 'identifier'], - type: 'string' + type: 'string', }, { additionalProperties: false, properties: { ignoreTypeDefault: { - type: 'boolean' - } + type: 'boolean', + }, }, - type: 'object' - } + type: 'object', + }, ]; const create = (context) => { @@ -23,12 +23,12 @@ const create = (context) => { if (specifier.importKind === 'type') { context.report({ message: 'Unexpected type import', - node + node, }); } }); } - } + }, }; } else { // Default to 'identifier' @@ -78,14 +78,14 @@ const create = (context) => { return fixer.replaceText(node, 'import {' + imports.join(', ') + '} from \'' + source + '\';'); }, message: 'Unexpected "import type"', - node + node, }); - } + }, }; } }; export default { create, - schema + schema, }; diff --git a/src/rules/unionIntersectionSpacing.js b/src/rules/unionIntersectionSpacing.js index 76b9d28f..00759c1d 100644 --- a/src/rules/unionIntersectionSpacing.js +++ b/src/rules/unionIntersectionSpacing.js @@ -3,8 +3,8 @@ import {spacingFixers, getTokenAfterParens} from '../utilities'; const schema = [ { enum: ['always', 'never'], - type: 'string' - } + type: 'string', + }, ]; const create = (context) => { @@ -33,7 +33,7 @@ const create = (context) => { data, fix: spacingFixers.addSpaceAfter(endOfType), message: 'There must be a space before {{type}} type annotation separator', - node + node, }); } @@ -42,7 +42,7 @@ const create = (context) => { data, fix: spacingFixers.addSpaceAfter(separator), message: 'There must be a space after {{type}} type annotation separator', - node + node, }); } } else { @@ -51,7 +51,7 @@ const create = (context) => { data, fix: spacingFixers.stripSpacesAfter(endOfType, spaceBefore), message: 'There must be no space before {{type}} type annotation separator', - node + node, }); } @@ -60,7 +60,7 @@ const create = (context) => { data, fix: spacingFixers.stripSpacesAfter(separator, spaceAfter), message: 'There must be no space after {{type}} type annotation separator', - node + node, }); } } @@ -69,11 +69,11 @@ const create = (context) => { return { IntersectionTypeAnnotation: check, - UnionTypeAnnotation: check + UnionTypeAnnotation: check, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/useFlowType.js b/src/rules/useFlowType.js index cb612f58..ce08c072 100644 --- a/src/rules/useFlowType.js +++ b/src/rules/useFlowType.js @@ -47,11 +47,11 @@ const create = (context) => { }); } }); - } + }, }; }; export default { create, - schema + schema, }; diff --git a/src/rules/validSyntax.js b/src/rules/validSyntax.js index fd69cd9b..3163dec1 100644 --- a/src/rules/validSyntax.js +++ b/src/rules/validSyntax.js @@ -2,7 +2,7 @@ import _ from 'lodash'; import { getParameterName, iterateFunctionNodes, - quoteName + quoteName, } from '../utilities'; const schema = []; @@ -18,10 +18,10 @@ const create = iterateFunctionNodes((context) => { if (isAssignmentPattern && hasTypeAnnotation && !leftAnnotated) { context.report({ data: { - name: quoteName(getParameterName(identifierNode, context)) + name: quoteName(getParameterName(identifierNode, context)), }, message: '{{name}}parameter type annotation must be placed on left-hand side of assignment.', - node: identifierNode + node: identifierNode, }); } }); @@ -31,8 +31,8 @@ const create = iterateFunctionNodes((context) => { export default { create, meta: { - deprecated: true + deprecated: true, }, - schema + schema, }; diff --git a/src/utilities/index.js b/src/utilities/index.js index d120e737..23c7b2ec 100644 --- a/src/utilities/index.js +++ b/src/utilities/index.js @@ -14,5 +14,5 @@ export {default as iterateFunctionNodes} from './iterateFunctionNodes'; export {default as quoteName} from './quoteName'; export { - spacingFixers + spacingFixers, }; diff --git a/src/utilities/iterateFunctionNodes.js b/src/utilities/iterateFunctionNodes.js index c8e09880..a5e28805 100644 --- a/src/utilities/iterateFunctionNodes.js +++ b/src/utilities/iterateFunctionNodes.js @@ -6,7 +6,7 @@ export default (iterator) => { ArrowFunctionExpression: nodeIterator, FunctionDeclaration: nodeIterator, FunctionExpression: nodeIterator, - FunctionTypeAnnotation: nodeIterator + FunctionTypeAnnotation: nodeIterator, }; }; }; diff --git a/tests/rules/assertions/arrayStyleComplexType.js b/tests/rules/assertions/arrayStyleComplexType.js index 7e2f4617..992a794a 100644 --- a/tests/rules/assertions/arrayStyleComplexType.js +++ b/tests/rules/assertions/arrayStyleComplexType.js @@ -3,61 +3,61 @@ export default { { code: 'type X = (?string)[]', errors: [{message: 'Use "Array", not "(?string)[]"'}], - output: 'type X = Array' + output: 'type X = Array', }, { code: 'type X = (?string)[]', errors: [{message: 'Use "Array", not "(?string)[]"'}], options: ['verbose'], - output: 'type X = Array' + output: 'type X = Array', }, { code: 'type X = Array', errors: [{message: 'Use "(?string)[]", not "Array"'}], options: ['shorthand'], - output: 'type X = (?string)[]' + output: 'type X = (?string)[]', }, { code: 'type X = Array<{foo: string}>', errors: [{message: 'Use "{foo: string}[]", not "Array<{foo: string}>"'}], options: ['shorthand'], - output: 'type X = {foo: string}[]' + output: 'type X = {foo: string}[]', }, { code: 'type X = (string | number)[]', errors: [{message: 'Use "Array", not "(string | number)[]"'}], - output: 'type X = Array' + output: 'type X = Array', }, { code: 'type X = (string & number)[]', errors: [{message: 'Use "Array", not "(string & number)[]"'}], - output: 'type X = Array' + output: 'type X = Array', }, { code: 'type X = [string, number][]', errors: [{message: 'Use "Array<[string, number]>", not "[string, number][]"'}], - output: 'type X = Array<[string, number]>' + output: 'type X = Array<[string, number]>', }, { code: 'type X = {foo: string}[]', errors: [{message: 'Use "Array<{foo: string}>", not "{foo: string}[]"'}], - output: 'type X = Array<{foo: string}>' + output: 'type X = Array<{foo: string}>', }, { code: 'type X = (string => number)[]', errors: [{message: 'Use "Array number>", not "(string => number)[]"'}], - output: 'type X = Array number>' + output: 'type X = Array number>', }, { code: 'type X = {\n foo: string,\n bar: number\n}[]', errors: [{message: 'Use "Array<{ foo: string, bar: number }>", not "{ foo: string, bar: number }[]"'}], - output: 'type X = Array<{\n foo: string,\n bar: number\n}>' + output: 'type X = Array<{\n foo: string,\n bar: number\n}>', }, { code: 'type X = {\n foo: string,\n bar: number,\n quo: boolean,\n hey: Date\n}[]', errors: [{message: 'Use "Array", not "Type[]"'}], - output: 'type X = Array<{\n foo: string,\n bar: number,\n quo: boolean,\n hey: Date\n}>' - } + output: 'type X = Array<{\n foo: string,\n bar: number,\n quo: boolean,\n hey: Date\n}>', + }, ], misconfigured: [ { @@ -70,50 +70,50 @@ export default { params: { allowedValues: [ 'verbose', - 'shorthand' - ] + 'shorthand', + ], }, parentSchema: { enum: [ 'verbose', - 'shorthand' + 'shorthand', ], - type: 'string' + type: 'string', }, schema: [ 'verbose', - 'shorthand' + 'shorthand', ], - schemaPath: '#/items/0/enum' - } + schemaPath: '#/items/0/enum', + }, ], - options: ['normal'] - } + options: ['normal'], + }, ], valid: [ { - code: 'type X = Array' + code: 'type X = Array', }, { code: 'type X = Array', - options: ['verbose'] + options: ['verbose'], }, { code: 'type X = (?string)[]', - options: ['shorthand'] + options: ['shorthand'], }, { code: 'type X = Array', - options: ['shorthand'] + options: ['shorthand'], }, { code: 'type X = Array', options: ['shorthand'], settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } - } - ] + onlyFilesWithFlowAnnotation: true, + }, + }, + }, + ], }; diff --git a/tests/rules/assertions/arrayStyleSimpleType.js b/tests/rules/assertions/arrayStyleSimpleType.js index 710b8b4e..d12bed23 100644 --- a/tests/rules/assertions/arrayStyleSimpleType.js +++ b/tests/rules/assertions/arrayStyleSimpleType.js @@ -3,72 +3,72 @@ export default { { code: 'type X = string[]', errors: [{message: 'Use "Array", not "string[]"'}], - output: 'type X = Array' + output: 'type X = Array', }, { code: 'type X = string[]', errors: [{message: 'Use "Array", not "string[]"'}], options: ['verbose'], - output: 'type X = Array' + output: 'type X = Array', }, { code: 'type X = Array', errors: [{message: 'Use "string[]", not "Array"'}], options: ['shorthand'], - output: 'type X = string[]' + output: 'type X = string[]', }, { code: 'type X = Date[]', errors: [{message: 'Use "Array", not "Date[]"'}], - output: 'type X = Array' + output: 'type X = Array', }, { code: 'type X = Promise[]', errors: [{message: 'Use "Array>", not "Promise[]"'}], - output: 'type X = Array>' + output: 'type X = Array>', }, { code: 'type X = $Keys<{foo: string}>[]', errors: [{message: 'Use "Array<$Keys<{foo: string}>>", not "$Keys<{foo: string}>[]"'}], - output: 'type X = Array<$Keys<{foo: string}>>' + output: 'type X = Array<$Keys<{foo: string}>>', }, { code: 'type X = any[]', errors: [{message: 'Use "Array", not "any[]"'}], - output: 'type X = Array' + output: 'type X = Array', }, { code: 'type X = mixed[]', errors: [{message: 'Use "Array", not "mixed[]"'}], - output: 'type X = Array' + output: 'type X = Array', }, { code: 'type X = void[]', errors: [{message: 'Use "Array", not "void[]"'}], - output: 'type X = Array' + output: 'type X = Array', }, { code: 'type X = null[]', errors: [{message: 'Use "Array", not "null[]"'}], - output: 'type X = Array' + output: 'type X = Array', }, { code: 'type X = string[][]', errors: [ {message: 'Use "Array", not "string[][]"'}, - {message: 'Use "Array", not "string[]"'} - ] + {message: 'Use "Array", not "string[]"'}, + ], }, { code: 'type X = Promise<{\n foo: string,\n bar: number\n}>[]', errors: [{message: 'Use "Array>", not "Promise<{ foo: string, bar: number }>[]"'}], - output: 'type X = Array>' + output: 'type X = Array>', }, { code: 'type X = Promise<{\n foo: string,\n bar: number,\n quo: boolean\n}>[]', errors: [{message: 'Use "Array", not "Type[]"'}], - output: 'type X = Array>' - } + output: 'type X = Array>', + }, ], misconfigured: [ { @@ -81,63 +81,63 @@ export default { params: { allowedValues: [ 'verbose', - 'shorthand' - ] + 'shorthand', + ], }, parentSchema: { enum: [ 'verbose', - 'shorthand' + 'shorthand', ], - type: 'string' + type: 'string', }, schema: [ 'verbose', - 'shorthand' + 'shorthand', ], - schemaPath: '#/items/0/enum' - } + schemaPath: '#/items/0/enum', + }, ], - options: ['normal'] - } + options: ['normal'], + }, ], valid: [ { - code: 'type X = Array' + code: 'type X = Array', }, { code: 'type X = Array', - options: ['verbose'] + options: ['verbose'], }, { code: 'type X = string[]', - options: ['shorthand'] + options: ['shorthand'], }, { - code: 'type X = Array>' + code: 'type X = Array>', }, { code: 'type X = (?string)[]', - options: ['verbose'] + options: ['verbose'], }, { code: 'type X = string[]', options: ['verbose'], settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } + onlyFilesWithFlowAnnotation: true, + }, + }, }, // While this isn't valid flow, we shouldn't disallow it. { - code: 'type X = Array' + code: 'type X = Array', }, // Valid flow. { - code: 'type X = typeof Array' - } - ] + code: 'type X = typeof Array', + }, + ], }; diff --git a/tests/rules/assertions/arrowParens.js b/tests/rules/assertions/arrowParens.js index 338c4644..5893137b 100644 --- a/tests/rules/assertions/arrowParens.js +++ b/tests/rules/assertions/arrowParens.js @@ -13,8 +13,8 @@ export default { column: 1, endColumn: 2, messageId: 'expectedParens', - type - }] + type, + }], }, { code: 'a => a', @@ -24,8 +24,8 @@ export default { column: 1, endColumn: 2, messageId: 'expectedParens', - type - }] + type, + }], }, { code: 'a => {\n}', @@ -35,8 +35,8 @@ export default { column: 1, endColumn: 2, messageId: 'expectedParens', - type - }] + type, + }], }, { code: 'a.then(foo => {});', @@ -46,8 +46,8 @@ export default { column: 8, endColumn: 11, messageId: 'expectedParens', - type - }] + type, + }], }, { code: 'a.then(foo => a);', @@ -57,8 +57,8 @@ export default { column: 8, endColumn: 11, messageId: 'expectedParens', - type - }] + type, + }], }, { code: 'a(foo => { if (true) {}; });', @@ -68,8 +68,8 @@ export default { column: 3, endColumn: 6, messageId: 'expectedParens', - type - }] + type, + }], }, { code: 'a(async foo => { if (true) {}; });', @@ -80,8 +80,8 @@ export default { column: 9, endColumn: 12, messageId: 'expectedParens', - type - }] + type, + }], }, // "as-needed" @@ -94,8 +94,8 @@ export default { column: 2, endColumn: 3, messageId: 'unexpectedParens', - type - }] + type, + }], }, { code: '(a,) => a', @@ -107,8 +107,8 @@ export default { column: 2, endColumn: 3, messageId: 'unexpectedParens', - type - }] + type, + }], }, { code: 'async (a) => a', @@ -120,8 +120,8 @@ export default { column: 8, endColumn: 9, messageId: 'unexpectedParens', - type - }] + type, + }], }, { code: 'async(a) => a', @@ -133,8 +133,8 @@ export default { column: 7, endColumn: 8, messageId: 'unexpectedParens', - type - }] + type, + }], }, // "as-needed", { "requireForBlockBody": true } @@ -147,8 +147,8 @@ export default { column: 1, endColumn: 2, messageId: 'expectedParensBlock', - type - }] + type, + }], }, { code: '(a) => a', @@ -159,8 +159,8 @@ export default { column: 2, endColumn: 3, messageId: 'unexpectedParensInline', - type - }] + type, + }], }, { code: 'async a => {}', @@ -172,8 +172,8 @@ export default { column: 7, endColumn: 8, messageId: 'expectedParensBlock', - type - }] + type, + }], }, { code: 'async (a) => a', @@ -185,8 +185,8 @@ export default { column: 8, endColumn: 9, messageId: 'unexpectedParensInline', - type - }] + type, + }], }, { code: 'async(a) => a', @@ -198,9 +198,9 @@ export default { column: 7, endColumn: 8, messageId: 'unexpectedParensInline', - type - }] - } + type, + }], + }, ], // can't figure out how to get this working @@ -285,10 +285,10 @@ export default { options: ['as-needed'], parserOptions: {ecmaVersion: 8}}, {code: '(a: T) => a', - options: ['as-needed'] + options: ['as-needed'], }, {code: '(a): T => a', - options: ['as-needed'] + options: ['as-needed'], }, // "as-needed", { "requireForBlockBody": true } @@ -333,7 +333,7 @@ export default { {code: '(a: T) => { return a; }', options: ['as-needed', {requireForBlockBody: true}]}, {code: '(a): %checks => typeof a === "number"', - options: ['as-needed', {requireForBlockBody: true}]} + options: ['as-needed', {requireForBlockBody: true}]}, - ] + ], }; diff --git a/tests/rules/assertions/booleanStyle.js b/tests/rules/assertions/booleanStyle.js index 2a9202fd..a10a5789 100644 --- a/tests/rules/assertions/booleanStyle.js +++ b/tests/rules/assertions/booleanStyle.js @@ -3,20 +3,20 @@ export default { { code: 'type X = bool', errors: [{message: 'Use "boolean", not "bool"'}], - output: 'type X = boolean' + output: 'type X = boolean', }, { code: 'type X = bool', errors: [{message: 'Use "boolean", not "bool"'}], options: ['boolean'], - output: 'type X = boolean' + output: 'type X = boolean', }, { code: 'type X = boolean', errors: [{message: 'Use "bool", not "boolean"'}], options: ['bool'], - output: 'type X = bool' - } + output: 'type X = bool', + }, ], misconfigured: [ { @@ -29,46 +29,46 @@ export default { params: { allowedValues: [ 'bool', - 'boolean' - ] + 'boolean', + ], }, parentSchema: { enum: [ 'bool', - 'boolean' + 'boolean', ], - type: 'string' + type: 'string', }, schema: [ 'bool', - 'boolean' + 'boolean', ], - schemaPath: '#/items/0/enum' - } + schemaPath: '#/items/0/enum', + }, ], - options: ['integer'] - } + options: ['integer'], + }, ], valid: [ { - code: 'type X = boolean' + code: 'type X = boolean', }, { code: 'type X = boolean', - options: ['boolean'] + options: ['boolean'], }, { code: 'type X = bool', - options: ['bool'] + options: ['bool'], }, { code: 'type X = bool', options: ['boolean'], settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } - } - ] + onlyFilesWithFlowAnnotation: true, + }, + }, + }, + ], }; diff --git a/tests/rules/assertions/defineFlowType.js b/tests/rules/assertions/defineFlowType.js index 8ffe8082..80acc64b 100644 --- a/tests/rules/assertions/defineFlowType.js +++ b/tests/rules/assertions/defineFlowType.js @@ -1,5 +1,5 @@ import { - RuleTester + RuleTester, } from 'eslint'; import noUndefRule from 'eslint/lib/rules/no-undef'; @@ -7,109 +7,109 @@ const VALID_WITH_DEFINE_FLOW_TYPE = [ { code: 'var a: AType', errors: [ - '\'AType\' is not defined.' - ] + '\'AType\' is not defined.', + ], }, { code: 'var a: AType; var b: AType', errors: [ '\'AType\' is not defined.', - '\'AType\' is not defined.' - ] + '\'AType\' is not defined.', + ], }, { code: 'var a; (a: AType)', errors: [ - '\'AType\' is not defined.' - ] + '\'AType\' is not defined.', + ], }, { code: 'var a: AType', errors: [ '\'AType\' is not defined.', - '\'BType\' is not defined.' - ] + '\'BType\' is not defined.', + ], }, { code: 'type A = AType', errors: [ - '\'AType\' is not defined.' - ] + '\'AType\' is not defined.', + ], }, { code: 'declare type A = number', errors: [ - '\'A\' is not defined.' - ] + '\'A\' is not defined.', + ], }, { code: 'opaque type A = AType', errors: [ // Complaining about 'A' is fixed in https://github.com/babel/babel-eslint/pull/696 '\'A\' is not defined.', - '\'AType\' is not defined.' - ] + '\'AType\' is not defined.', + ], }, { code: 'function f(a: AType) {}', errors: [ - '\'AType\' is not defined.' - ] + '\'AType\' is not defined.', + ], }, { code: 'function f(a: AType.a) {}', errors: [ - '\'AType\' is not defined.' - ] + '\'AType\' is not defined.', + ], }, { code: 'function f(a: AType.a.b) {}', errors: [ - '\'AType\' is not defined.' - ] + '\'AType\' is not defined.', + ], }, { code: 'function f(a): AType {}; var a: AType', errors: [ '\'AType\' is not defined.', - '\'AType\' is not defined.' - ] + '\'AType\' is not defined.', + ], }, { code: 'function f(a): AType {}', errors: [ - '\'AType\' is not defined.' - ] + '\'AType\' is not defined.', + ], }, { code: 'class C { a: AType }', errors: [ - '\'AType\' is not defined.' - ] + '\'AType\' is not defined.', + ], }, { code: 'class C { a: AType.a }', errors: [ - '\'AType\' is not defined.' - ] + '\'AType\' is not defined.', + ], }, { code: 'class C { a: AType.a.b }', errors: [ - '\'AType\' is not defined.' - ] + '\'AType\' is not defined.', + ], }, { code: 'class C implements AType {}', errors: [ - '\'AType\' is not defined.' - ] + '\'AType\' is not defined.', + ], }, { code: 'declare interface A {}', errors: [ - '\'A\' is not defined.' - ] + '\'A\' is not defined.', + ], }, { code: '({ a: ({b() {}}: AType) })', @@ -118,15 +118,15 @@ const VALID_WITH_DEFINE_FLOW_TYPE = [ // references, this may be a babel-eslint bug. errors: [ '\'AType\' is not defined.', - '\'AType\' is not defined.' - ] + '\'AType\' is not defined.', + ], }, { code: 'type X = {Y(): BType}', errors: [ '\'AType\' is not defined.', - '\'BType\' is not defined.' - ] + '\'BType\' is not defined.', + ], }, // This tests to ensure we have a robust handling of @flow comments @@ -139,41 +139,41 @@ const VALID_WITH_DEFINE_FLOW_TYPE = [ */ type Foo = $ReadOnly<{}>`, errors: [ - '\'$ReadOnly\' is not defined.' + '\'$ReadOnly\' is not defined.', ], settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } - } + onlyFilesWithFlowAnnotation: true, + }, + }, + }, ]; const ALWAYS_INVALID = [ { code: 'var a = b', errors: [ - '\'b\' is not defined.' - ] + '\'b\' is not defined.', + ], }, { code: 'function f(a = b) {}', errors: [ - '\'b\' is not defined.' - ] + '\'b\' is not defined.', + ], }, { code: 'class C extends b {}', errors: [ - '\'b\' is not defined.' - ] + '\'b\' is not defined.', + ], }, { code: 'class C { static S = b }', errors: [ - '\'b\' is not defined.' - ] - } + '\'b\' is not defined.', + ], + }, ]; const ALWAYS_VALID = [ @@ -188,7 +188,7 @@ const ALWAYS_VALID = [ 'function f(a): string {}', 'class C { a: string }', 'var AType = {}; class C { a: AType.a }', - 'declare module A { declare var a: AType }' + 'declare module A { declare var a: AType }', ]; /** @@ -199,26 +199,26 @@ const ALWAYS_VALID = [ */ { const ruleTester = new RuleTester({ - parser: 'babel-eslint' + parser: 'babel-eslint', }); ruleTester.run('no-undef must not trigger an error in these cases', noUndefRule, { invalid: [], - valid: ALWAYS_VALID + valid: ALWAYS_VALID, }); } { const ruleTester = new RuleTester({ - parser: 'babel-eslint' + parser: 'babel-eslint', }); ruleTester.run('no-undef must trigger an error when define-flow-type is not used in these cases', noUndefRule, { invalid: [ ...ALWAYS_INVALID, - ...VALID_WITH_DEFINE_FLOW_TYPE + ...VALID_WITH_DEFINE_FLOW_TYPE, ], - valid: [] + valid: [], }); } @@ -229,9 +229,9 @@ export default { return { code: subject.code, rules: { - 'no-undef': 2 + 'no-undef': 2, }, - settings: subject.settings + settings: subject.settings, }; }), ...VALID_WITH_DEFINE_FLOW_TYPE.map((subject) => { @@ -241,11 +241,11 @@ export default { 'no-undef': 2, 'no-use-before-define': [ 2, - 'nofunc' - ] + 'nofunc', + ], }, - settings: subject.settings + settings: subject.settings, }; - }) - ] + }), + ], }; diff --git a/tests/rules/assertions/delimiterDangle.js b/tests/rules/assertions/delimiterDangle.js index dd590ea9..1a178307 100644 --- a/tests/rules/assertions/delimiterDangle.js +++ b/tests/rules/assertions/delimiterDangle.js @@ -3,55 +3,55 @@ const OBJECT_TYPE_ANNOTATION = { { code: 'type X = { foo: string, }', errors: [{message: 'Unexpected trailing delimiter'}], - output: 'type X = { foo: string }' + output: 'type X = { foo: string }', }, { code: 'type X = { foo: string, }', errors: [{message: 'Unexpected trailing delimiter'}], options: ['never'], - output: 'type X = { foo: string }' + output: 'type X = { foo: string }', }, { code: 'type X = { foo: string; }', errors: [{message: 'Unexpected trailing delimiter'}], options: ['never'], - output: 'type X = { foo: string }' + output: 'type X = { foo: string }', }, { code: 'type X = {\nfoo: string,\n}', errors: [{message: 'Unexpected trailing delimiter'}], options: ['never'], - output: 'type X = {\nfoo: string\n}' + output: 'type X = {\nfoo: string\n}', }, { code: 'type X = { foo: string }', errors: [{message: 'Missing trailing delimiter'}], options: ['always'], - output: 'type X = { foo: string, }' + output: 'type X = { foo: string, }', }, { code: 'type X = {\nfoo: string\n}', errors: [{message: 'Missing trailing delimiter'}], options: ['always'], - output: 'type X = {\nfoo: string,\n}' + output: 'type X = {\nfoo: string,\n}', }, { code: 'type X = { foo: string, }', errors: [{message: 'Unexpected trailing delimiter'}], options: ['always-multiline'], - output: 'type X = { foo: string }' + output: 'type X = { foo: string }', }, { code: 'type X = {\nfoo: string\n}', errors: [{message: 'Missing trailing delimiter'}], options: ['always-multiline'], - output: 'type X = {\nfoo: string,\n}' + output: 'type X = {\nfoo: string,\n}', }, { code: 'type X = { foo: string; }', errors: [{message: 'Unexpected trailing delimiter'}], options: ['only-multiline'], - output: 'type X = { foo: string }' + output: 'type X = { foo: string }', }, // Only indexers... @@ -59,31 +59,31 @@ const OBJECT_TYPE_ANNOTATION = { code: 'type X = { [key: string]: number, }', errors: [{message: 'Unexpected trailing delimiter'}], options: ['never'], - output: 'type X = { [key: string]: number }' + output: 'type X = { [key: string]: number }', }, { code: 'type X = { [key: string]: number }', errors: [{message: 'Missing trailing delimiter'}], options: ['always'], - output: 'type X = { [key: string]: number, }' + output: 'type X = { [key: string]: number, }', }, { code: 'type X = { [key: string]: number, }', errors: [{message: 'Unexpected trailing delimiter'}], options: ['always-multiline'], - output: 'type X = { [key: string]: number }' + output: 'type X = { [key: string]: number }', }, { code: 'type X = {\n[key: string]: number\n}', errors: [{message: 'Missing trailing delimiter'}], options: ['always-multiline'], - output: 'type X = {\n[key: string]: number,\n}' + output: 'type X = {\n[key: string]: number,\n}', }, { code: 'type X = { [key: string]: number; }', errors: [{message: 'Unexpected trailing delimiter'}], options: ['only-multiline'], - output: 'type X = { [key: string]: number }' + output: 'type X = { [key: string]: number }', }, // Indexer, Prop... @@ -93,10 +93,10 @@ const OBJECT_TYPE_ANNOTATION = { // be sure it's reporting the prop, not the indexer column: 35, line: 1, - message: 'Unexpected trailing delimiter' + message: 'Unexpected trailing delimiter', }], options: ['never'], - output: 'type X = { [key: string]: number, foo: string }' + output: 'type X = { [key: string]: number, foo: string }', }, { code: 'type X = {\n[key: string]: number,\nfoo: string,\n}', @@ -104,10 +104,10 @@ const OBJECT_TYPE_ANNOTATION = { // be sure it's reporting the prop, not the indexer column: 1, line: 3, - message: 'Unexpected trailing delimiter' + message: 'Unexpected trailing delimiter', }], options: ['never'], - output: 'type X = {\n[key: string]: number,\nfoo: string\n}' + output: 'type X = {\n[key: string]: number,\nfoo: string\n}', }, { code: 'type X = {\n[key: string]: number,\naReallyLongPropertyNameHere: string,\n}', @@ -115,40 +115,40 @@ const OBJECT_TYPE_ANNOTATION = { // be sure it's reporting the prop, not the indexer column: 1, line: 3, - message: 'Unexpected trailing delimiter' + message: 'Unexpected trailing delimiter', }], options: ['never'], - output: 'type X = {\n[key: string]: number,\naReallyLongPropertyNameHere: string\n}' + output: 'type X = {\n[key: string]: number,\naReallyLongPropertyNameHere: string\n}', }, { code: 'type X = { [key: string]: number, foo: string }', errors: [{message: 'Missing trailing delimiter'}], options: ['always'], - output: 'type X = { [key: string]: number, foo: string, }' + output: 'type X = { [key: string]: number, foo: string, }', }, { code: 'type X = {\n[key: string]: number;\nfoo: string\n}', errors: [{message: 'Missing trailing delimiter'}], options: ['always'], - output: 'type X = {\n[key: string]: number;\nfoo: string,\n}' + output: 'type X = {\n[key: string]: number;\nfoo: string,\n}', }, { code: 'type X = { [key: string]: number, foo: string, }', errors: [{message: 'Unexpected trailing delimiter'}], options: ['always-multiline'], - output: 'type X = { [key: string]: number, foo: string }' + output: 'type X = { [key: string]: number, foo: string }', }, { code: 'type X = {\n[key: string]: number,\nfoo: string\n}', errors: [{message: 'Missing trailing delimiter'}], options: ['always-multiline'], - output: 'type X = {\n[key: string]: number,\nfoo: string,\n}' + output: 'type X = {\n[key: string]: number,\nfoo: string,\n}', }, { code: 'type X = { [key: string]: number, foo: string, }', errors: [{message: 'Unexpected trailing delimiter'}], options: ['only-multiline'], - output: 'type X = { [key: string]: number, foo: string }' + output: 'type X = { [key: string]: number, foo: string }', }, // Prop, Indexer... @@ -158,10 +158,10 @@ const OBJECT_TYPE_ANNOTATION = { // be sure it's reporting the indexer, not the prop column: 25, line: 1, - message: 'Unexpected trailing delimiter' + message: 'Unexpected trailing delimiter', }], options: ['never'], - output: 'type X = { foo: string, [key: string]: number }' + output: 'type X = { foo: string, [key: string]: number }', }, { code: 'type X = {\nfoo: string,\n[key: string]: number,\n}', @@ -169,10 +169,10 @@ const OBJECT_TYPE_ANNOTATION = { // be sure it's reporting the prop, not the indexer column: 1, line: 3, - message: 'Unexpected trailing delimiter' + message: 'Unexpected trailing delimiter', }], options: ['never'], - output: 'type X = {\nfoo: string,\n[key: string]: number\n}' + output: 'type X = {\nfoo: string,\n[key: string]: number\n}', }, { code: 'type X = {\naReallyLongPropertyNameHere: string,\n[key: string]: number,\n}', @@ -180,215 +180,215 @@ const OBJECT_TYPE_ANNOTATION = { // be sure it's reporting the prop, not the indexer column: 1, line: 3, - message: 'Unexpected trailing delimiter' + message: 'Unexpected trailing delimiter', }], options: ['never'], - output: 'type X = {\naReallyLongPropertyNameHere: string,\n[key: string]: number\n}' + output: 'type X = {\naReallyLongPropertyNameHere: string,\n[key: string]: number\n}', }, { code: 'type X = { foo: string, [key: string]: number }', errors: [{message: 'Missing trailing delimiter'}], options: ['always'], - output: 'type X = { foo: string, [key: string]: number, }' + output: 'type X = { foo: string, [key: string]: number, }', }, { code: 'type X = { foo: string; [key: string]: number }', errors: [{message: 'Missing trailing delimiter'}], options: ['always'], - output: 'type X = { foo: string; [key: string]: number, }' + output: 'type X = { foo: string; [key: string]: number, }', }, { code: 'type X = { foo: string, [key: string]: number; }', errors: [{message: 'Unexpected trailing delimiter'}], options: ['always-multiline'], - output: 'type X = { foo: string, [key: string]: number }' + output: 'type X = { foo: string, [key: string]: number }', }, { code: 'type X = {\nfoo: string,\n[key: string]: number\n}', errors: [{message: 'Missing trailing delimiter'}], options: ['always-multiline'], - output: 'type X = {\nfoo: string,\n[key: string]: number,\n}' + output: 'type X = {\nfoo: string,\n[key: string]: number,\n}', }, { code: 'type X = { foo: string, [key: string]: number; }', errors: [{message: 'Unexpected trailing delimiter'}], options: ['only-multiline'], - output: 'type X = { foo: string, [key: string]: number }' - } + output: 'type X = { foo: string, [key: string]: number }', + }, ], valid: [ { - code: 'type X = { foo: string }' + code: 'type X = { foo: string }', }, { code: 'type X = { foo: string }', - options: ['never'] + options: ['never'], }, { code: 'type X = { foo: string, }', - options: ['always'] + options: ['always'], }, { code: 'type X = { foo: string; }', - options: ['always'] + options: ['always'], }, { code: 'type X = {\nfoo: string\n}', - options: ['never'] + options: ['never'], }, { code: 'type X = {\nfoo: string,\n}', - options: ['always'] + options: ['always'], }, { code: 'type X = { foo: string }', - options: ['always-multiline'] + options: ['always-multiline'], }, { code: 'type X = {\nfoo: string,\n}', - options: ['always-multiline'] + options: ['always-multiline'], }, { code: 'type X = {\nfoo: string;\n}', - options: ['always-multiline'] + options: ['always-multiline'], }, { code: 'type X = { foo: string }', - options: ['only-multiline'] + options: ['only-multiline'], }, { code: 'type X = {\nfoo: string\n}', - options: ['only-multiline'] + options: ['only-multiline'], }, { code: 'type X = {\nfoo: string,\n}', - options: ['only-multiline'] + options: ['only-multiline'], }, { code: 'type X = {\nfoo: string;\n}', - options: ['only-multiline'] + options: ['only-multiline'], }, // Empty... { code: 'type X = {}', - options: ['never'] + options: ['never'], }, { code: 'type X = {}', - options: ['always'] + options: ['always'], }, { code: 'type X = {}', - options: ['always-multiline'] + options: ['always-multiline'], }, { code: 'type X = {}', - options: ['only-multiline'] + options: ['only-multiline'], }, // Only indexers... { code: 'type X = { [key: string]: number }', - options: ['never'] + options: ['never'], }, { code: 'type X = { [key: string]: number, }', - options: ['always'] + options: ['always'], }, { code: 'type X = { [key: string]: number; }', - options: ['always'] + options: ['always'], }, { code: 'type X = { [key: string]: number }', - options: ['always-multiline'] + options: ['always-multiline'], }, { code: 'type X = {\n[key: string]: number,\n}', - options: ['always-multiline'] + options: ['always-multiline'], }, { code: 'type X = {\n[key: string]: number,\n}', - options: ['only-multiline'] + options: ['only-multiline'], }, { code: 'type X = {\n[key: string]: number\n}', - options: ['only-multiline'] + options: ['only-multiline'], }, { code: 'type X = { [key: string]: number }', - options: ['only-multiline'] + options: ['only-multiline'], }, // Indexer, Prop... { code: 'type X = { [key: string]: number, foo: string }', - options: ['never'] + options: ['never'], }, { code: 'type X = { [key: string]: number, foo: string, }', - options: ['always'] + options: ['always'], }, { code: 'type X = { [key: string]: number; foo: string; }', - options: ['always'] + options: ['always'], }, { code: 'type X = { [key: string]: number, foo: string }', - options: ['always-multiline'] + options: ['always-multiline'], }, { code: 'type X = {\n[key: string]: number,\nfoo: string,\n}', - options: ['always-multiline'] + options: ['always-multiline'], }, { code: 'type X = {\n[key: string]: number,\nfoo: string,\n}', - options: ['only-multiline'] + options: ['only-multiline'], }, { code: 'type X = {\n[key: string]: number;\nfoo: string\n}', - options: ['only-multiline'] + options: ['only-multiline'], }, { code: 'type X = { [key: string]: number, foo: string }', - options: ['only-multiline'] + options: ['only-multiline'], }, // Prop, Indexer... { code: 'type X = { foo: string, [key: string]: number }', - options: ['never'] + options: ['never'], }, { code: 'type X = { foo: string, [key: string]: number, }', - options: ['always'] + options: ['always'], }, { code: 'type X = { foo: string; [key: string]: number; }', - options: ['always'] + options: ['always'], }, { code: 'type X = { foo: string, [key: string]: number }', - options: ['always-multiline'] + options: ['always-multiline'], }, { code: 'type X = {\nfoo: string,\n[key: string]: number,\n}', - options: ['always-multiline'] + options: ['always-multiline'], }, { code: 'type X = {\nfoo: string,\n[key: string]: number,\n}', - options: ['only-multiline'] + options: ['only-multiline'], }, { code: 'type X = {\nfoo: string;\n[key: string]: number\n}', - options: ['only-multiline'] + options: ['only-multiline'], }, { code: 'type X = { foo: string, [key: string]: number }', - options: ['only-multiline'] - } - ] + options: ['only-multiline'], + }, + ], }; const TUPLE_TYPE_ANNOTATION = { @@ -396,108 +396,108 @@ const TUPLE_TYPE_ANNOTATION = { { code: 'type X = [string, number,]', errors: [{message: 'Unexpected trailing delimiter'}], - output: 'type X = [string, number]' + output: 'type X = [string, number]', }, { code: 'type X = [string, number,]', errors: [{message: 'Unexpected trailing delimiter'}], options: ['never'], - output: 'type X = [string, number]' + output: 'type X = [string, number]', }, { code: 'type X = [\nstring,\nnumber,\n]', errors: [{message: 'Unexpected trailing delimiter'}], options: ['never'], - output: 'type X = [\nstring,\nnumber\n]' + output: 'type X = [\nstring,\nnumber\n]', }, { code: 'type X = [string, number]', errors: [{message: 'Missing trailing delimiter'}], options: ['always'], - output: 'type X = [string, number,]' + output: 'type X = [string, number,]', }, { code: 'type X = [\nstring,\nnumber\n]', errors: [{message: 'Missing trailing delimiter'}], options: ['always'], - output: 'type X = [\nstring,\nnumber,\n]' + output: 'type X = [\nstring,\nnumber,\n]', }, { code: 'type X = [string, number,]', errors: [{message: 'Unexpected trailing delimiter'}], options: ['always-multiline'], - output: 'type X = [string, number]' + output: 'type X = [string, number]', }, { code: 'type X = [\nfoo, string\n]', errors: [{message: 'Missing trailing delimiter'}], options: ['always-multiline'], - output: 'type X = [\nfoo, string,\n]' + output: 'type X = [\nfoo, string,\n]', }, { code: 'type X = [ number, string, ]', errors: [{message: 'Unexpected trailing delimiter'}], options: ['only-multiline'], - output: 'type X = [ number, string ]' - } + output: 'type X = [ number, string ]', + }, ], valid: [ { - code: 'type X = [string, number]' + code: 'type X = [string, number]', }, { code: 'type X = [string, number]', - options: ['never'] + options: ['never'], }, { code: 'type X = [\nstring,\nnumber\n]', - options: ['never'] + options: ['never'], }, { code: 'type X = [string, number,]', - options: ['always'] + options: ['always'], }, { code: 'type X = [\nstring,\nnumber,\n]', - options: ['always'] + options: ['always'], }, { code: 'type X = [ foo, string ]', - options: ['always-multiline'] + options: ['always-multiline'], }, { code: 'type X = [\nfoo, string,\n]', - options: ['always-multiline'] + options: ['always-multiline'], }, { code: 'type X = [ number, string ]', - options: ['only-multiline'] + options: ['only-multiline'], }, { code: 'type X = [\nnumber,\nstring\n]', - options: ['only-multiline'] + options: ['only-multiline'], }, { code: 'type X = [\nnumber,\nstring,\n]', - options: ['only-multiline'] + options: ['only-multiline'], }, { code: 'type X = []', - options: ['never'] + options: ['never'], }, { code: 'type X = []', - options: ['always'] + options: ['always'], }, { code: 'type X = []', - options: ['always-multiline'] + options: ['always-multiline'], }, { code: 'type X = []', - options: ['only-multiline'] - } - ] + options: ['only-multiline'], + }, + ], }; const MISCONFIGURED = [ @@ -513,40 +513,40 @@ const MISCONFIGURED = [ 'always', 'always-multiline', 'only-multiline', - 'never' - ] + 'never', + ], }, parentSchema: { enum: [ 'always', 'always-multiline', 'only-multiline', - 'never' + 'never', ], - type: 'string' + type: 'string', }, schema: [ 'always', 'always-multiline', 'only-multiline', - 'never' + 'never', ], - schemaPath: '#/items/0/enum' + schemaPath: '#/items/0/enum', - } + }, ], - options: ['occasionally'] - } + options: ['occasionally'], + }, ]; export default { invalid: [ ...OBJECT_TYPE_ANNOTATION.invalid, - ...TUPLE_TYPE_ANNOTATION.invalid + ...TUPLE_TYPE_ANNOTATION.invalid, ], misconfigured: MISCONFIGURED, valid: [ ...OBJECT_TYPE_ANNOTATION.valid, - ...TUPLE_TYPE_ANNOTATION.valid - ] + ...TUPLE_TYPE_ANNOTATION.valid, + ], }; diff --git a/tests/rules/assertions/genericSpacing.js b/tests/rules/assertions/genericSpacing.js index 3d01887d..12f97c12 100644 --- a/tests/rules/assertions/genericSpacing.js +++ b/tests/rules/assertions/genericSpacing.js @@ -5,34 +5,34 @@ export default { { code: 'type X = Promise< string>', errors: [{message: 'There must be no space at start of "Promise" generic type annotation'}], - output: 'type X = Promise' + output: 'type X = Promise', }, { code: 'type X = Promise< string>', errors: [{message: 'There must be no space at start of "Promise" generic type annotation'}], options: ['never'], - output: 'type X = Promise' + output: 'type X = Promise', }, { code: 'type X = FooBar', errors: [{message: 'There must be no space at end of "FooBar" generic type annotation'}], - output: 'type X = FooBar' + output: 'type X = FooBar', }, { code: 'type X = Promise< string >', errors: [ {message: 'There must be no space at start of "Promise" generic type annotation'}, - {message: 'There must be no space at end of "Promise" generic type annotation'} + {message: 'There must be no space at end of "Promise" generic type annotation'}, ], - output: 'type X = Promise' + output: 'type X = Promise', }, { code: 'type X = Promise< (foo), bar, (((baz))) >', errors: [ {message: 'There must be no space at start of "Promise" generic type annotation'}, - {message: 'There must be no space at end of "Promise" generic type annotation'} + {message: 'There must be no space at end of "Promise" generic type annotation'}, ], - output: 'type X = Promise<(foo), bar, (((baz)))>' + output: 'type X = Promise<(foo), bar, (((baz)))>', }, // Always (given no space) @@ -41,31 +41,31 @@ export default { code: 'type X = Promise', errors: [{message: 'There must be a space at start of "Promise" generic type annotation'}], options: ['always'], - output: 'type X = Promise< string >' + output: 'type X = Promise< string >', }, { code: 'type X = FooBar< string>', errors: [{message: 'There must be a space at end of "FooBar" generic type annotation'}], options: ['always'], - output: 'type X = FooBar< string >' + output: 'type X = FooBar< string >', }, { code: 'type X = Promise', errors: [ {message: 'There must be a space at start of "Promise" generic type annotation'}, - {message: 'There must be a space at end of "Promise" generic type annotation'} + {message: 'There must be a space at end of "Promise" generic type annotation'}, ], options: ['always'], - output: 'type X = Promise< string >' + output: 'type X = Promise< string >', }, { code: 'type X = Promise<(foo), bar, (((baz)))>', errors: [ {message: 'There must be a space at start of "Promise" generic type annotation'}, - {message: 'There must be a space at end of "Promise" generic type annotation'} + {message: 'There must be a space at end of "Promise" generic type annotation'}, ], options: ['always'], - output: 'type X = Promise< (foo), bar, (((baz))) >' + output: 'type X = Promise< (foo), bar, (((baz))) >', }, // Always (given too many spaces) @@ -74,23 +74,23 @@ export default { code: 'type X = FooBar< string >', errors: [{message: 'There must be one space at start of "FooBar" generic type annotation'}], options: ['always'], - output: 'type X = FooBar< string >' + output: 'type X = FooBar< string >', }, { code: 'type X = FooBar< string >', errors: [{message: 'There must be one space at end of "FooBar" generic type annotation'}], options: ['always'], - output: 'type X = FooBar< string >' + output: 'type X = FooBar< string >', }, { code: 'type X = Promise< (foo), bar, (((baz))) >', errors: [ {message: 'There must be one space at start of "Promise" generic type annotation'}, - {message: 'There must be one space at end of "Promise" generic type annotation'} + {message: 'There must be one space at end of "Promise" generic type annotation'}, ], options: ['always'], - output: 'type X = Promise< (foo), bar, (((baz))) >' - } + output: 'type X = Promise< (foo), bar, (((baz))) >', + }, ], misconfigured: [ { @@ -103,25 +103,25 @@ export default { params: { allowedValues: [ 'always', - 'never' - ] + 'never', + ], }, parentSchema: { enum: [ 'always', - 'never' + 'never', ], - type: 'string' + type: 'string', }, schema: [ 'always', - 'never' + 'never', ], - schemaPath: '#/items/0/enum' - } + schemaPath: '#/items/0/enum', + }, ], - options: ['frequently'] - } + options: ['frequently'], + }, ], valid: [ // Never @@ -134,15 +134,15 @@ export default { { code: 'type X = Promise< string >', - options: ['always'] + options: ['always'], }, { code: 'type X = Promise< (string) >', - options: ['always'] + options: ['always'], }, { code: 'type X = Promise< (foo), bar, (((baz))) >', - options: ['always'] - } - ] + options: ['always'], + }, + ], }; diff --git a/tests/rules/assertions/newlineAfterFlowAnnotation.js b/tests/rules/assertions/newlineAfterFlowAnnotation.js index a563d753..fddc227a 100644 --- a/tests/rules/assertions/newlineAfterFlowAnnotation.js +++ b/tests/rules/assertions/newlineAfterFlowAnnotation.js @@ -3,40 +3,40 @@ export default { { code: '// @flow\nimport Foo from \'./foo\';', errors: [{message: 'Expected newline after flow annotation'}], - output: '// @flow\n\nimport Foo from \'./foo\';' + output: '// @flow\n\nimport Foo from \'./foo\';', }, { code: '// @flow\nimport Foo from \'./foo\';', errors: [{message: 'Expected newline after flow annotation'}], options: ['always'], - output: '// @flow\n\nimport Foo from \'./foo\';' + output: '// @flow\n\nimport Foo from \'./foo\';', }, { code: '// @flow\r\nimport Foo from \'./foo\';', errors: [{message: 'Expected newline after flow annotation'}], options: ['always-windows'], - output: '// @flow\r\n\r\nimport Foo from \'./foo\';' + output: '// @flow\r\n\r\nimport Foo from \'./foo\';', }, { code: '// @flow\n\n', errors: [{message: 'Expected no newline after flow annotation'}], options: ['never'], - output: '// @flow\n' - } + output: '// @flow\n', + }, ], valid: [ { code: '// @flow\n\nimport Foo from \'./foo\';', - options: ['always'] + options: ['always'], }, { code: '// @flow\r\n\r\nimport Foo from \'./foo\';', - options: ['always-windows'] + options: ['always-windows'], }, { code: '// @flow\nimport Foo from \'./foo\';', - options: ['never'] - } - ] + options: ['never'], + }, + ], }; diff --git a/tests/rules/assertions/noDupeKeys.js b/tests/rules/assertions/noDupeKeys.js index af7607df..7521d53c 100644 --- a/tests/rules/assertions/noDupeKeys.js +++ b/tests/rules/assertions/noDupeKeys.js @@ -2,114 +2,114 @@ export default { invalid: [ { code: 'type f = { a: number, b: string, a: number }', - errors: [{message: 'Duplicate property.'}] + errors: [{message: 'Duplicate property.'}], }, { code: 'type f = { a: number, b: string, a: string }', - errors: [{message: 'Duplicate property.'}] + errors: [{message: 'Duplicate property.'}], }, { code: 'type f = { get(key: "a"): string, get(key: "a"): string }', - errors: [{message: 'Duplicate property.'}] + errors: [{message: 'Duplicate property.'}], }, { code: 'type f = { get(key: 1): string, get(key: 1): string }', - errors: [{message: 'Duplicate property.'}] + errors: [{message: 'Duplicate property.'}], }, { code: 'type f = { get(key: 1.1): string, get(key: 1.1): string }', - errors: [{message: 'Duplicate property.'}] + errors: [{message: 'Duplicate property.'}], }, { code: 'type f = { get(key: true): string, get(key: true): string }', - errors: [{message: 'Duplicate property.'}] + errors: [{message: 'Duplicate property.'}], }, { code: 'type f = { get(key: {a: 1}): string, get(key: {a: 1}):string }', - errors: [{message: 'Duplicate property.'}] + errors: [{message: 'Duplicate property.'}], }, { code: 'var a = "a"; type f = { get(key: a): string, get(key: a): string }', - errors: [{message: 'Duplicate property.'}] + errors: [{message: 'Duplicate property.'}], }, { code: 'var b = 1; type f = { get(key: b): string, get(key: b): string }', - errors: [{message: 'Duplicate property.'}] + errors: [{message: 'Duplicate property.'}], }, { code: 'var c = true; type f = { get(key: c): string, get(key: c): string }', - errors: [{message: 'Duplicate property.'}] + errors: [{message: 'Duplicate property.'}], }, { code: 'var d = {}; type f = { get(key: d): string, get(key: d): string }', - errors: [{message: 'Duplicate property.'}] + errors: [{message: 'Duplicate property.'}], }, { code: 'var e = []; type f = { get(key: e): string, get(key: e): string }', - errors: [{message: 'Duplicate property.'}] + errors: [{message: 'Duplicate property.'}], }, { code: 'var e = [1, "a"]; type f = { get(key: e): string, get(key: e): string }', - errors: [{message: 'Duplicate property.'}] + errors: [{message: 'Duplicate property.'}], }, { code: 'function fn() {}; type f = { get(key: fn): string, get(key: fn): string }', - errors: [{message: 'Duplicate property.'}] - } + errors: [{message: 'Duplicate property.'}], + }, ], valid: [ { - code: 'type FooType = { a: number, b: string, c: number }' + code: 'type FooType = { a: number, b: string, c: number }', }, { code: 'type FooType = { a: number, b: string, a: number }', settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } + onlyFilesWithFlowAnnotation: true, + }, + }, }, { - code: 'type f = { get(key: "a"): string, get(key: "b"): string }' + code: 'type f = { get(key: "a"): string, get(key: "b"): string }', }, { - code: 'type f = { get(key: 1): string, get(key: 2): string }' + code: 'type f = { get(key: 1): string, get(key: 2): string }', }, { - code: 'type f = { get(key: 1.1): string, get(key: 1.2): string }' + code: 'type f = { get(key: 1.1): string, get(key: 1.2): string }', }, { - code: 'type f = { get(key: true): string, get(key: false): string }' + code: 'type f = { get(key: true): string, get(key: false): string }', }, { - code: 'type f = { get(key: ["a", 1]): string, get(key: ["a", 2]): string }' + code: 'type f = { get(key: ["a", 1]): string, get(key: ["a", 2]): string }', }, { - code: 'type f = { get(key: ["a", ["b", 1]]): string, get(key: ["a", ["b", 2]]): string }' + code: 'type f = { get(key: ["a", ["b", 1]]): string, get(key: ["a", ["b", 2]]): string }', }, { - code: 'type f = { a: number, b: string, c: number }' + code: 'type f = { a: number, b: string, c: number }', }, { - code: 'type f = { get(key: "a"): string, get(key: "b"): string }' + code: 'type f = { get(key: "a"): string, get(key: "b"): string }', }, { - code: 'type f = { get(key: "a"): string, get(key: "a", key2: "b"): string }' + code: 'type f = { get(key: "a"): string, get(key: "a", key2: "b"): string }', }, { - code: 'type f = { get(key: "a"): string, get(key: 1): string }' + code: 'type f = { get(key: "a"): string, get(key: 1): string }', }, { - code: 'type f = { get(key: { a: 1 }): string, get(key: { a: 2 }): string}' + code: 'type f = { get(key: { a: 1 }): string, get(key: { a: 2 }): string}', }, { - code: 'var a = {}; var b = {}; type f = { get(key: a): string, get(key: b): string }' + code: 'var a = {}; var b = {}; type f = { get(key: a): string, get(key: b): string }', }, { - code: 'var a = 1; var b = 1; type f = { get(key: a): string, get(key: b): string }' + code: 'var a = 1; var b = 1; type f = { get(key: a): string, get(key: b): string }', }, { - code: 'type a = { b: (config: { ...C, key: string}) => C }' - } - ] + code: 'type a = { b: (config: { ...C, key: string}) => C }', + }, + ], }; diff --git a/tests/rules/assertions/noExistentialType.js b/tests/rules/assertions/noExistentialType.js index bf915140..fd50fbd0 100644 --- a/tests/rules/assertions/noExistentialType.js +++ b/tests/rules/assertions/noExistentialType.js @@ -2,7 +2,7 @@ export default { invalid: [ { code: 'type T = *;', - errors: [{message: 'Unexpected use of existential type (*).'}] + errors: [{message: 'Unexpected use of existential type (*).'}], }, { code: 'type T = U<*, *>;', @@ -10,18 +10,18 @@ export default { {column: 12, message: 'Unexpected use of existential type (*).'}, {column: 15, - message: 'Unexpected use of existential type (*).'} - ] + message: 'Unexpected use of existential type (*).'}, + ], }, { code: 'const f: (*) => null = () => null;', - errors: [{message: 'Unexpected use of existential type (*).'}] - } + errors: [{message: 'Unexpected use of existential type (*).'}], + }, ], valid: [ { - code: 'type T = string | null' - } - ] + code: 'type T = string | null', + }, + ], }; diff --git a/tests/rules/assertions/noFlowFixMeComments.js b/tests/rules/assertions/noFlowFixMeComments.js index dad3b708..c858e5b7 100644 --- a/tests/rules/assertions/noFlowFixMeComments.js +++ b/tests/rules/assertions/noFlowFixMeComments.js @@ -4,51 +4,51 @@ export default { code: '// $FlowFixMe I am doing something evil here\nconst text = \'HELLO\';', errors: [ { - message: '$FlowFixMe is treated as `any` and should be fixed.' - } - ] + message: '$FlowFixMe is treated as `any` and should be fixed.', + }, + ], }, { code: '// $FlowFixMe I am doing something evil here\nconst text = \'HELLO\';', errors: [ { - message: '$FlowFixMe is treated as `any` and should be fixed. Fix it or match `/TODO [0-9]+/`.' - } + message: '$FlowFixMe is treated as `any` and should be fixed. Fix it or match `/TODO [0-9]+/`.', + }, ], options: [ - 'TODO [0-9]+' - ] + 'TODO [0-9]+', + ], }, { code: '// $FlowFixMe TODO abc 47 I am doing something evil here\nconst text = \'HELLO\';', errors: [ { - message: '$FlowFixMe is treated as `any` and should be fixed. Fix it or match `/TODO [0-9]+/`.' - } + message: '$FlowFixMe is treated as `any` and should be fixed. Fix it or match `/TODO [0-9]+/`.', + }, ], options: [ - 'TODO [0-9]+' - ] + 'TODO [0-9]+', + ], }, { code: '// $$FlowFixMeProps I am doing something evil here\nconst text = \'HELLO\';', errors: [ { - message: '$FlowFixMe is treated as `any` and should be fixed.' - } - ] + message: '$FlowFixMe is treated as `any` and should be fixed.', + }, + ], }, { code: '// $FlowFixMeProps I am doing something evil here\nconst text = \'HELLO\';', errors: [ { - message: '$FlowFixMe is treated as `any` and should be fixed. Fix it or match `/TODO [0-9]+/`.' - } + message: '$FlowFixMe is treated as `any` and should be fixed. Fix it or match `/TODO [0-9]+/`.', + }, ], options: [ - 'TODO [0-9]+' - ] - } + 'TODO [0-9]+', + ], + }, ], misconfigured: [ { @@ -59,27 +59,27 @@ export default { keyword: 'type', message: 'should be string', params: { - type: 'string' + type: 'string', }, parentSchema: { - type: 'string' + type: 'string', }, schema: 'string', - schemaPath: '#/items/0/type' - } + schemaPath: '#/items/0/type', + }, ], - options: [7] - } + options: [7], + }, ], valid: [ { - code: 'const text = \'HELLO\';' + code: 'const text = \'HELLO\';', }, { code: '// $FlowFixMe TODO 48\nconst text = \'HELLO\';', options: [ - 'TODO [0-9]+' - ] - } - ] + 'TODO [0-9]+', + ], + }, + ], }; diff --git a/tests/rules/assertions/noMixed.js b/tests/rules/assertions/noMixed.js index 5983266b..44417b00 100644 --- a/tests/rules/assertions/noMixed.js +++ b/tests/rules/assertions/noMixed.js @@ -3,64 +3,64 @@ export default { { code: 'function foo(thing): mixed {}', errors: [{ - message: 'Unexpected use of mixed type' - }] + message: 'Unexpected use of mixed type', + }], }, { code: 'function foo(thing): Promise {}', errors: [{ - message: 'Unexpected use of mixed type' - }] + message: 'Unexpected use of mixed type', + }], }, { code: 'function foo(thing): Promise> {}', errors: [{ - message: 'Unexpected use of mixed type' - }] - } + message: 'Unexpected use of mixed type', + }], + }, ], valid: [ { - code: 'function foo(thing): string {}' + code: 'function foo(thing): string {}', }, { - code: 'function foo(thing): Promise {}' + code: 'function foo(thing): Promise {}', }, { - code: 'function foo(thing): Promise> {}' + code: 'function foo(thing): Promise> {}', }, { - code: '(foo?: string) => {}' + code: '(foo?: string) => {}', }, { - code: '(foo: ?string) => {}' + code: '(foo: ?string) => {}', }, { - code: '(foo: { a: string }) => {}' + code: '(foo: { a: string }) => {}', }, { - code: '(foo: { a: ?string }) => {}' + code: '(foo: { a: ?string }) => {}', }, { - code: '(foo: string[]) => {}' + code: '(foo: string[]) => {}', }, { - code: 'type Foo = string' + code: 'type Foo = string', }, { - code: 'type Foo = { a: string }' + code: 'type Foo = { a: string }', }, { - code: 'type Foo = { (a: string): string }' + code: 'type Foo = { (a: string): string }', }, { - code: 'function foo(thing: string) {}' + code: 'function foo(thing: string) {}', }, { - code: 'var foo: string' + code: 'var foo: string', }, { - code: 'class Foo { props: string }' - } - ] + code: 'class Foo { props: string }', + }, + ], }; diff --git a/tests/rules/assertions/noMutableArray.js b/tests/rules/assertions/noMutableArray.js index b7a429d6..54d1c317 100644 --- a/tests/rules/assertions/noMutableArray.js +++ b/tests/rules/assertions/noMutableArray.js @@ -3,42 +3,42 @@ export default { { code: 'type X = Array', errors: [{message: 'Use "$ReadOnlyArray" instead of "Array"'}], - output: 'type X = $ReadOnlyArray' + output: 'type X = $ReadOnlyArray', }, { code: 'type X = string[]', errors: [{message: 'Use "$ReadOnlyArray" instead of array shorthand notation'}], - output: 'type X = $ReadOnlyArray' + output: 'type X = $ReadOnlyArray', }, { code: 'const values: Array> = [];', errors: [{message: 'Use "$ReadOnlyArray" instead of "Array"'}], - output: 'const values: Array<$ReadOnlyArray> = [];' + output: 'const values: Array<$ReadOnlyArray> = [];', }, { code: 'let values: Array>;', errors: [ {message: 'Use "$ReadOnlyArray" instead of "Array"'}, - {message: 'Use "$ReadOnlyArray" instead of "Array"'} + {message: 'Use "$ReadOnlyArray" instead of "Array"'}, ], - output: 'let values: $ReadOnlyArray<$ReadOnlyArray>;' - } + output: 'let values: $ReadOnlyArray<$ReadOnlyArray>;', + }, ], valid: [ { - code: 'type X = $ReadOnlyArray' + code: 'type X = $ReadOnlyArray', }, { - code: 'const values: Array<$ReadOnlyArray> = [];' + code: 'const values: Array<$ReadOnlyArray> = [];', }, { - code: 'const values: $ReadOnlyArray[] = [];' + code: 'const values: $ReadOnlyArray[] = [];', }, { - code: 'const values: Array<$ReadOnlyArray> = new Array();' + code: 'const values: Array<$ReadOnlyArray> = new Array();', }, { - code: 'const values: Array<$ReadOnlyArray> = Array();' - } - ] + code: 'const values: Array<$ReadOnlyArray> = Array();', + }, + ], }; diff --git a/tests/rules/assertions/noPrimitiveConstructorTypes.js b/tests/rules/assertions/noPrimitiveConstructorTypes.js index 4af2e30d..946009e0 100644 --- a/tests/rules/assertions/noPrimitiveConstructorTypes.js +++ b/tests/rules/assertions/noPrimitiveConstructorTypes.js @@ -2,77 +2,77 @@ export default { invalid: [ { code: 'type x = Number', - errors: [{message: 'Unexpected use of Number constructor type.'}] + errors: [{message: 'Unexpected use of Number constructor type.'}], }, { code: 'type x = String', - errors: [{message: 'Unexpected use of String constructor type.'}] + errors: [{message: 'Unexpected use of String constructor type.'}], }, { code: 'type x = Boolean', - errors: [{message: 'Unexpected use of Boolean constructor type.'}] + errors: [{message: 'Unexpected use of Boolean constructor type.'}], }, { code: 'type x = { a: Number }', - errors: [{message: 'Unexpected use of Number constructor type.'}] + errors: [{message: 'Unexpected use of Number constructor type.'}], }, { code: 'type x = { a: String }', - errors: [{message: 'Unexpected use of String constructor type.'}] + errors: [{message: 'Unexpected use of String constructor type.'}], }, { code: 'type x = { a: Boolean }', - errors: [{message: 'Unexpected use of Boolean constructor type.'}] + errors: [{message: 'Unexpected use of Boolean constructor type.'}], }, { code: '(x: Number) => {}', - errors: [{message: 'Unexpected use of Number constructor type.'}] + errors: [{message: 'Unexpected use of Number constructor type.'}], }, { code: '(x: String) => {}', - errors: [{message: 'Unexpected use of String constructor type.'}] + errors: [{message: 'Unexpected use of String constructor type.'}], }, { code: '(x: Boolean) => {}', - errors: [{message: 'Unexpected use of Boolean constructor type.'}] - } + errors: [{message: 'Unexpected use of Boolean constructor type.'}], + }, ], valid: [ { - code: 'type x = number' + code: 'type x = number', }, { - code: 'type x = string' + code: 'type x = string', }, { - code: 'type x = boolean' + code: 'type x = boolean', }, { - code: 'type x = { a: number }' + code: 'type x = { a: number }', }, { - code: 'type x = { a: string }' + code: 'type x = { a: string }', }, { - code: 'type x = { a: boolean }' + code: 'type x = { a: boolean }', }, { - code: '(x: number) => {}' + code: '(x: number) => {}', }, { - code: '(x: string) => {}' + code: '(x: string) => {}', }, { - code: '(x: boolean) => {}' + code: '(x: boolean) => {}', }, { - code: 'type x = MyNumber' + code: 'type x = MyNumber', }, { - code: 'type x = MyString' + code: 'type x = MyString', }, { - code: 'type x = MyBoolean' - } - ] + code: 'type x = MyBoolean', + }, + ], }; diff --git a/tests/rules/assertions/noTypesMissingFileAnnotation.js b/tests/rules/assertions/noTypesMissingFileAnnotation.js index a8aec639..ee4fe182 100644 --- a/tests/rules/assertions/noTypesMissingFileAnnotation.js +++ b/tests/rules/assertions/noTypesMissingFileAnnotation.js @@ -3,78 +3,78 @@ export default { { code: 'const x: number = 42;', errors: [{ - message: 'Type annotations require valid Flow declaration.' - }] + message: 'Type annotations require valid Flow declaration.', + }], }, { code: 'type FooType = number;', errors: [{ - message: 'Type aliases require valid Flow declaration.' - }] + message: 'Type aliases require valid Flow declaration.', + }], }, { code: 'import type A from "a"', errors: [{ - message: 'Type imports require valid Flow declaration.' - }] + message: 'Type imports require valid Flow declaration.', + }], }, { code: 'import type {A} from "a"', errors: [{ - message: 'Type imports require valid Flow declaration.' - }] + message: 'Type imports require valid Flow declaration.', + }], }, { code: 'import {type A} from "a"', errors: [{ - message: 'Type imports require valid Flow declaration.' - }] + message: 'Type imports require valid Flow declaration.', + }], }, { code: 'export type {A} from "a"', errors: [{ - message: 'Type exports require valid Flow declaration.' - }] + message: 'Type exports require valid Flow declaration.', + }], }, { code: 'function t(): T{}', errors: [{ - message: 'Type annotations require valid Flow declaration.' - }] + message: 'Type annotations require valid Flow declaration.', + }], }, { code: 'const x: number = 42;', errors: [{ - message: 'Type annotations require valid Flow declaration.' + message: 'Type annotations require valid Flow declaration.', }], settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } - } + onlyFilesWithFlowAnnotation: true, + }, + }, + }, ], valid: [ { - code: '// @flow\nconst x: number = 42;' + code: '// @flow\nconst x: number = 42;', }, { - code: '/* @flow weak */\ntype FooType = number;' + code: '/* @flow weak */\ntype FooType = number;', }, { - code: '/* @noflow */\ntype FooType = number;' + code: '/* @noflow */\ntype FooType = number;', }, { - code: '/* @noflow */\nimport type A from "a"' + code: '/* @noflow */\nimport type A from "a"', }, { - code: '/* @noflow */\nimport {type A} from "a"' + code: '/* @noflow */\nimport {type A} from "a"', }, { - code: '/* @noflow */\nexport type {A} from "a"' + code: '/* @noflow */\nexport type {A} from "a"', }, { - code: '// an unrelated comment\n// @flow\nexport type {A} from "a"' - } - ] + code: '// an unrelated comment\n// @flow\nexport type {A} from "a"', + }, + ], }; diff --git a/tests/rules/assertions/noUnusedExpressions.js b/tests/rules/assertions/noUnusedExpressions.js index 83aa55e6..1d113005 100644 --- a/tests/rules/assertions/noUnusedExpressions.js +++ b/tests/rules/assertions/noUnusedExpressions.js @@ -3,13 +3,13 @@ export default { { code: 'foo + 1', errors: [{ - message: 'Expected an assignment or function call and instead saw an expression.' - }] - } + message: 'Expected an assignment or function call and instead saw an expression.', + }], + }, ], valid: [ { - code: '(foo: number)' - } - ] + code: '(foo: number)', + }, + ], }; diff --git a/tests/rules/assertions/noWeakTypes.js b/tests/rules/assertions/noWeakTypes.js index 9339399b..8f15ca52 100644 --- a/tests/rules/assertions/noWeakTypes.js +++ b/tests/rules/assertions/noWeakTypes.js @@ -3,229 +3,229 @@ export default { { code: 'function foo(thing): any {}', errors: [{ - message: 'Unexpected use of weak type "any"' - }] + message: 'Unexpected use of weak type "any"', + }], }, { code: 'function foo(thing): Promise {}', errors: [{ - message: 'Unexpected use of weak type "any"' - }] + message: 'Unexpected use of weak type "any"', + }], }, { code: 'function foo(thing): Promise> {}', errors: [{ - message: 'Unexpected use of weak type "any"' - }] + message: 'Unexpected use of weak type "any"', + }], }, { code: 'function foo(thing): Object {}', errors: [{ - message: 'Unexpected use of weak type "Object"' - }] + message: 'Unexpected use of weak type "Object"', + }], }, { code: 'function foo(thing): Promise {}', errors: [{ - message: 'Unexpected use of weak type "Object"' - }] + message: 'Unexpected use of weak type "Object"', + }], }, { code: 'function foo(thing): Promise> {}', errors: [{ - message: 'Unexpected use of weak type "Object"' - }] + message: 'Unexpected use of weak type "Object"', + }], }, { code: 'function foo(thing): Function {}', errors: [{ - message: 'Unexpected use of weak type "Function"' - }] + message: 'Unexpected use of weak type "Function"', + }], }, { code: 'function foo(thing): Promise {}', errors: [{ - message: 'Unexpected use of weak type "Function"' - }] + message: 'Unexpected use of weak type "Function"', + }], }, { code: 'function foo(thing): Promise> {}', errors: [{ - message: 'Unexpected use of weak type "Function"' - }] + message: 'Unexpected use of weak type "Function"', + }], }, { code: '(foo: any) => {}', errors: [{ - message: 'Unexpected use of weak type "any"' - }] + message: 'Unexpected use of weak type "any"', + }], }, { code: '(foo: Function) => {}', errors: [{ - message: 'Unexpected use of weak type "Function"' - }] + message: 'Unexpected use of weak type "Function"', + }], }, { code: '(foo?: any) => {}', errors: [{ - message: 'Unexpected use of weak type "any"' - }] + message: 'Unexpected use of weak type "any"', + }], }, { code: '(foo?: Function) => {}', errors: [{ - message: 'Unexpected use of weak type "Function"' - }] + message: 'Unexpected use of weak type "Function"', + }], }, { code: '(foo: { a: any }) => {}', errors: [{ - message: 'Unexpected use of weak type "any"' - }] + message: 'Unexpected use of weak type "any"', + }], }, { code: '(foo: { a: Object }) => {}', errors: [{ - message: 'Unexpected use of weak type "Object"' - }] + message: 'Unexpected use of weak type "Object"', + }], }, { code: '(foo: any[]) => {}', errors: [{ - message: 'Unexpected use of weak type "any"' - }] + message: 'Unexpected use of weak type "any"', + }], }, { code: 'type Foo = any', errors: [{ - message: 'Unexpected use of weak type "any"' - }] + message: 'Unexpected use of weak type "any"', + }], }, { code: 'type Foo = Function', errors: [{ - message: 'Unexpected use of weak type "Function"' - }] + message: 'Unexpected use of weak type "Function"', + }], }, { code: 'type Foo = { a: any }', errors: [{ - message: 'Unexpected use of weak type "any"' - }] + message: 'Unexpected use of weak type "any"', + }], }, { code: 'type Foo = { a: Object }', errors: [{ - message: 'Unexpected use of weak type "Object"' - }] + message: 'Unexpected use of weak type "Object"', + }], }, { code: 'type Foo = { (a: Object): string }', errors: [{ - message: 'Unexpected use of weak type "Object"' - }] + message: 'Unexpected use of weak type "Object"', + }], }, { code: 'type Foo = { (a: string): Function }', errors: [{ - message: 'Unexpected use of weak type "Function"' - }] + message: 'Unexpected use of weak type "Function"', + }], }, { code: 'function foo(thing: any) {}', errors: [{ - message: 'Unexpected use of weak type "any"' - }] + message: 'Unexpected use of weak type "any"', + }], }, { code: 'function foo(thing: Object) {}', errors: [{ - message: 'Unexpected use of weak type "Object"' - }] + message: 'Unexpected use of weak type "Object"', + }], }, { code: 'var foo: Function', errors: [{ - message: 'Unexpected use of weak type "Function"' - }] + message: 'Unexpected use of weak type "Function"', + }], }, { code: 'var foo: Object', errors: [{ - message: 'Unexpected use of weak type "Object"' - }] + message: 'Unexpected use of weak type "Object"', + }], }, { code: 'class Foo { props: any }', errors: [{ - message: 'Unexpected use of weak type "any"' - }] + message: 'Unexpected use of weak type "any"', + }], }, { code: 'class Foo { props: Object }', errors: [{ - message: 'Unexpected use of weak type "Object"' - }] + message: 'Unexpected use of weak type "Object"', + }], }, { code: 'var foo: any', errors: [{ - message: 'Unexpected use of weak type "any"' - }] + message: 'Unexpected use of weak type "any"', + }], }, { code: 'type X = any; type Y = Function; type Z = Object', errors: [ {message: 'Unexpected use of weak type "any"'}, - {message: 'Unexpected use of weak type "Object"'} + {message: 'Unexpected use of weak type "Object"'}, ], options: [{ - Function: false - }] + Function: false, + }], }, { code: 'type X = any; type Y = Function; type Z = Object', errors: [{message: 'Unexpected use of weak type "Function"'}], options: [{ any: false, - Object: false - }] - } + Object: false, + }], + }, ], misconfigured: [ { errors: [ { data: { - nonExistentWeakType: false + nonExistentWeakType: false, }, dataPath: '[0]', keyword: 'additionalProperties', message: 'should NOT have additional properties', params: { - additionalProperty: 'nonExistentWeakType' + additionalProperty: 'nonExistentWeakType', }, parentSchema: { additionalProperties: false, properties: { any: { - type: 'boolean' + type: 'boolean', }, Function: { - type: 'boolean' + type: 'boolean', }, Object: { - type: 'boolean' - } + type: 'boolean', + }, }, - type: 'object' + type: 'object', }, schema: false, - schemaPath: '#/items/0/additionalProperties' - } + schemaPath: '#/items/0/additionalProperties', + }, ], - options: [{nonExistentWeakType: false}] + options: [{nonExistentWeakType: false}], }, { errors: [ @@ -235,79 +235,79 @@ export default { keyword: 'type', message: 'should be boolean', params: { - type: 'boolean' + type: 'boolean', }, parentSchema: { - type: 'boolean' + type: 'boolean', }, schema: 'boolean', - schemaPath: '#/items/0/properties/Object/type' - } + schemaPath: '#/items/0/properties/Object/type', + }, ], - options: [{Object: 'irrelevant'}] - } + options: [{Object: 'irrelevant'}], + }, ], valid: [ { - code: 'function foo(thing): string {}' + code: 'function foo(thing): string {}', }, { - code: 'function foo(thing): Promise {}' + code: 'function foo(thing): Promise {}', }, { - code: 'function foo(thing): Promise> {}' + code: 'function foo(thing): Promise> {}', }, { - code: '(foo?: string) => {}' + code: '(foo?: string) => {}', }, { - code: '(foo: ?string) => {}' + code: '(foo: ?string) => {}', }, { - code: '(foo: { a: string }) => {}' + code: '(foo: { a: string }) => {}', }, { - code: '(foo: { a: ?string }) => {}' + code: '(foo: { a: ?string }) => {}', }, { - code: '(foo: string[]) => {}' + code: '(foo: string[]) => {}', }, { - code: 'type Foo = string' + code: 'type Foo = string', }, { - code: 'type Foo = { a: string }' + code: 'type Foo = { a: string }', }, { - code: 'type Foo = { (a: string): string }' + code: 'type Foo = { (a: string): string }', }, { - code: 'function foo(thing: string) {}' + code: 'function foo(thing: string) {}', }, { - code: 'var foo: string' + code: 'var foo: string', }, { - code: 'class Foo { props: string }' + code: 'class Foo { props: string }', }, { code: 'type X = any; type Y = Object', options: [{ any: false, - Object: false - }] + Object: false, + }], }, { code: 'type X = Function', - options: [{Function: false}] + options: [{Function: false}], }, { code: 'function foo(thing): Function {}', settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } - } - ] + onlyFilesWithFlowAnnotation: true, + }, + }, + }, + ], }; diff --git a/tests/rules/assertions/objectTypeDelimiter.js b/tests/rules/assertions/objectTypeDelimiter.js index 21a403dd..229163eb 100644 --- a/tests/rules/assertions/objectTypeDelimiter.js +++ b/tests/rules/assertions/objectTypeDelimiter.js @@ -4,86 +4,86 @@ export default { code: 'type Foo = { a: Foo, b: Bar }', errors: [{message: 'Prefer semicolons to commas in object and class types'}], options: ['semicolon'], - output: 'type Foo = { a: Foo; b: Bar }' + output: 'type Foo = { a: Foo; b: Bar }', }, { code: 'type Foo = { a: Foo; b: Bar }', errors: [{message: 'Prefer commas to semicolons in object and class types'}], options: ['comma'], - output: 'type Foo = { a: Foo, b: Bar }' + output: 'type Foo = { a: Foo, b: Bar }', }, { code: 'type Foo = { [a: string]: Foo, [b: string]: Bar }', errors: [{message: 'Prefer semicolons to commas in object and class types'}], options: ['semicolon'], - output: 'type Foo = { [a: string]: Foo; [b: string]: Bar }' + output: 'type Foo = { [a: string]: Foo; [b: string]: Bar }', }, { code: 'type Foo = { [a: string]: Foo; [b: string]: Bar }', errors: [{message: 'Prefer commas to semicolons in object and class types'}], options: ['comma'], - output: 'type Foo = { [a: string]: Foo, [b: string]: Bar }' + output: 'type Foo = { [a: string]: Foo, [b: string]: Bar }', }, { code: 'type Foo = { (): Foo, (): Bar }', errors: [{message: 'Prefer semicolons to commas in object and class types'}], options: ['semicolon'], - output: 'type Foo = { (): Foo; (): Bar }' + output: 'type Foo = { (): Foo; (): Bar }', }, { code: 'type Foo = { (): Foo; (): Bar }', errors: [{message: 'Prefer commas to semicolons in object and class types'}], options: ['comma'], - output: 'type Foo = { (): Foo, (): Bar }' + output: 'type Foo = { (): Foo, (): Bar }', }, { code: 'declare class Foo { a: Foo, }', errors: [{message: 'Prefer semicolons to commas in object and class types'}], options: ['semicolon'], - output: 'declare class Foo { a: Foo; }' + output: 'declare class Foo { a: Foo; }', }, { code: 'declare class Foo { a: Foo; }', errors: [{message: 'Prefer commas to semicolons in object and class types'}], options: ['comma'], - output: 'declare class Foo { a: Foo, }' + output: 'declare class Foo { a: Foo, }', }, { code: 'declare class Foo { [a: string]: Foo, }', errors: [{message: 'Prefer semicolons to commas in object and class types'}], options: ['semicolon'], - output: 'declare class Foo { [a: string]: Foo; }' + output: 'declare class Foo { [a: string]: Foo; }', }, { code: 'declare class Foo { a: Foo; }', errors: [{message: 'Prefer commas to semicolons in object and class types'}], options: ['comma'], - output: 'declare class Foo { a: Foo, }' + output: 'declare class Foo { a: Foo, }', }, { code: 'declare class Foo { (): Foo, }', errors: [{message: 'Prefer semicolons to commas in object and class types'}], options: ['semicolon'], - output: 'declare class Foo { (): Foo; }' + output: 'declare class Foo { (): Foo; }', }, { code: 'declare class Foo { (): Foo; }', errors: [{message: 'Prefer commas to semicolons in object and class types'}], options: ['comma'], - output: 'declare class Foo { (): Foo, }' + output: 'declare class Foo { (): Foo, }', }, { code: 'declare class Foo { static (): Foo, }', errors: [{message: 'Prefer semicolons to commas in object and class types'}], options: ['semicolon'], - output: 'declare class Foo { static (): Foo; }' + output: 'declare class Foo { static (): Foo; }', }, { code: 'declare class Foo { static (): Foo; }', errors: [{message: 'Prefer commas to semicolons in object and class types'}], options: ['comma'], - output: 'declare class Foo { static (): Foo, }' - } + output: 'declare class Foo { static (): Foo, }', + }, ], misconfigured: [ { @@ -96,92 +96,92 @@ export default { params: { allowedValues: [ 'semicolon', - 'comma' - ] + 'comma', + ], }, parentSchema: { enum: [ 'semicolon', - 'comma' + 'comma', ], - type: 'string' + type: 'string', }, schema: [ 'semicolon', - 'comma' + 'comma', ], - schemaPath: '#/items/0/enum' - } + schemaPath: '#/items/0/enum', + }, ], - options: ['period'] - } + options: ['period'], + }, ], valid: [ { code: 'type Foo = { a: Foo; b: Bar }', - options: ['semicolon'] + options: ['semicolon'], }, { code: 'type Foo = { a: Foo, b: Bar }', - options: ['comma'] + options: ['comma'], }, { code: 'type Foo = { [a: string]: Foo; [b: string]: Bar }', - options: ['semicolon'] + options: ['semicolon'], }, { code: 'type Foo = { [a: string]: Foo, [b: string]: Bar }', - options: ['comma'] + options: ['comma'], }, { code: 'type Foo = { (): Foo; (): Bar }', - options: ['semicolon'] + options: ['semicolon'], }, { code: 'type Foo = { (): Foo, (): Bar }', - options: ['comma'] + options: ['comma'], }, { - code: 'type Foo = { a: Foo, b: Bar }' + code: 'type Foo = { a: Foo, b: Bar }', }, { - code: 'type Foo = { [a: string]: Foo, [b: string]: Bar }' + code: 'type Foo = { [a: string]: Foo, [b: string]: Bar }', }, { - code: 'type Foo = { (): Foo, (): Bar }' + code: 'type Foo = { (): Foo, (): Bar }', }, { code: 'declare class Foo { a: Foo; }', - options: ['semicolon'] + options: ['semicolon'], }, { code: 'declare class Foo { a: Foo, }', - options: ['comma'] + options: ['comma'], }, { code: 'declare class Foo { [a: string]: Foo; }', - options: ['semicolon'] + options: ['semicolon'], }, { code: 'declare class Foo { [a: string]: Foo, }', - options: ['comma'] + options: ['comma'], }, { code: 'declare class Foo { (): Foo; }', - options: ['semicolon'] + options: ['semicolon'], }, { code: 'declare class Foo { (): Foo, }', - options: ['comma'] + options: ['comma'], }, { code: 'type Foo = { a: Foo, b: Bar }', options: ['semicolon'], settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } - } - ] + onlyFilesWithFlowAnnotation: true, + }, + }, + }, + ], }; diff --git a/tests/rules/assertions/requireCompoundTypeAlias.js b/tests/rules/assertions/requireCompoundTypeAlias.js index e8c57b84..3e116f3f 100644 --- a/tests/rules/assertions/requireCompoundTypeAlias.js +++ b/tests/rules/assertions/requireCompoundTypeAlias.js @@ -2,36 +2,36 @@ export default { invalid: [ { code: 'function foo(bar: "A" | "B") {}', - errors: [{message: 'All union types must be declared with named type alias.'}] + errors: [{message: 'All union types must be declared with named type alias.'}], }, { code: 'const foo: "A" | "B" = "A";', - errors: [{message: 'All union types must be declared with named type alias.'}] + errors: [{message: 'All union types must be declared with named type alias.'}], }, { code: 'type Foo = { bar: "A" | "B" };', - errors: [{message: 'All union types must be declared with named type alias.'}] + errors: [{message: 'All union types must be declared with named type alias.'}], }, { code: 'function foo(bar: { n: number } | { s: string }) {}', - errors: [{message: 'All union types must be declared with named type alias.'}] + errors: [{message: 'All union types must be declared with named type alias.'}], }, { code: 'function foo(bar: { n: number } & { s: string }) {}', - errors: [{message: 'All intersection types must be declared with named type alias.'}] + errors: [{message: 'All intersection types must be declared with named type alias.'}], }, { code: 'const foo: { n: number } & { s: string } = { n: 0, s: "" };', - errors: [{message: 'All intersection types must be declared with named type alias.'}] + errors: [{message: 'All intersection types must be declared with named type alias.'}], }, { code: 'type Foo = { bar: { n: number } & { s: string } };', - errors: [{message: 'All intersection types must be declared with named type alias.'}] + errors: [{message: 'All intersection types must be declared with named type alias.'}], }, { code: 'function foo(bar: { n: number } & { s: string }) {}', - errors: [{message: 'All intersection types must be declared with named type alias.'}] - } + errors: [{message: 'All intersection types must be declared with named type alias.'}], + }, ], misconfigured: [ { @@ -44,49 +44,49 @@ export default { params: { allowedValues: [ 'always', - 'never' - ] + 'never', + ], }, parentSchema: { enum: [ 'always', - 'never' + 'never', ], - type: 'string' + type: 'string', }, schema: [ 'always', - 'never' + 'never', ], - schemaPath: '#/items/0/enum' - } + schemaPath: '#/items/0/enum', + }, ], - options: ['sometimes'] - } + options: ['sometimes'], + }, ], valid: [ { - code: 'type Foo = "A" | "B";' + code: 'type Foo = "A" | "B";', }, { - code: 'type Bar = "A" | "B"; function foo(bar: Bar) {}' + code: 'type Bar = "A" | "B"; function foo(bar: Bar) {}', }, { - code: 'type Foo = { disjoint: "A", n: number } | { disjoint: "B", s: string };' + code: 'type Foo = { disjoint: "A", n: number } | { disjoint: "B", s: string };', }, { - code: 'type Foo = { n: number } & { s: string };' + code: 'type Foo = { n: number } & { s: string };', }, { - code: 'type Bar = { n: number } & { s: string }; function foo(bar: Bar) {}' + code: 'type Bar = { n: number } & { s: string }; function foo(bar: Bar) {}', }, { code: 'function foo(bar: "A" | "B") {}', - options: ['never'] + options: ['never'], }, { code: 'function foo(bar: { n: number } & { s: string }) {}', - options: ['never'] - } - ] + options: ['never'], + }, + ], }; diff --git a/tests/rules/assertions/requireExactType.js b/tests/rules/assertions/requireExactType.js index e079a531..f09d330d 100644 --- a/tests/rules/assertions/requireExactType.js +++ b/tests/rules/assertions/requireExactType.js @@ -6,35 +6,35 @@ export default { code: 'type foo = {};', errors: [ { - message: 'Type identifier \'foo\' must be exact.' - } - ] + message: 'Type identifier \'foo\' must be exact.', + }, + ], }, { code: 'type foo = { bar: string };', errors: [ { - message: 'Type identifier \'foo\' must be exact.' - } - ] + message: 'Type identifier \'foo\' must be exact.', + }, + ], }, { code: 'type foo = {};', errors: [ { - message: 'Type identifier \'foo\' must be exact.' - } + message: 'Type identifier \'foo\' must be exact.', + }, ], - options: ['always'] + options: ['always'], }, { code: 'type foo = { bar: string };', errors: [ { - message: 'Type identifier \'foo\' must be exact.' - } + message: 'Type identifier \'foo\' must be exact.', + }, ], - options: ['always'] + options: ['always'], }, // Never @@ -43,63 +43,63 @@ export default { code: 'type foo = {| |};', errors: [ { - message: 'Type identifier \'foo\' must not be exact.' - } + message: 'Type identifier \'foo\' must not be exact.', + }, ], - options: ['never'] + options: ['never'], }, { code: 'type foo = {| bar: string |};', errors: [ { - message: 'Type identifier \'foo\' must not be exact.' - } + message: 'Type identifier \'foo\' must not be exact.', + }, ], - options: ['never'] - } + options: ['never'], + }, ], valid: [ // Always { - code: 'type foo = {| |};' + code: 'type foo = {| |};', }, { - code: 'type foo = {| bar: string |};' + code: 'type foo = {| bar: string |};', }, { - code: 'type foo = { [key: string]: string };' + code: 'type foo = { [key: string]: string };', }, { - code: 'type foo = number;' + code: 'type foo = number;', }, { code: 'type foo = {| |};', - options: ['always'] + options: ['always'], }, { code: 'type foo = {| bar: string |};', - options: ['always'] + options: ['always'], }, { code: 'type foo = number;', - options: ['always'] + options: ['always'], }, // Never { code: 'type foo = { };', - options: ['never'] + options: ['never'], }, { code: 'type foo = { bar: string };', - options: ['never'] + options: ['never'], }, { code: 'type foo = number;', - options: ['never'] - } - ] + options: ['never'], + }, + ], }; diff --git a/tests/rules/assertions/requireInexactType.js b/tests/rules/assertions/requireInexactType.js index fac73491..36a09e33 100644 --- a/tests/rules/assertions/requireInexactType.js +++ b/tests/rules/assertions/requireInexactType.js @@ -6,35 +6,35 @@ export default { code: 'type foo = {};', errors: [ { - message: 'Type must be explicit inexact.' - } - ] + message: 'Type must be explicit inexact.', + }, + ], }, { code: 'type foo = { bar: string };', errors: [ { - message: 'Type must be explicit inexact.' - } - ] + message: 'Type must be explicit inexact.', + }, + ], }, { code: 'type foo = {};', errors: [ { - message: 'Type must be explicit inexact.' - } + message: 'Type must be explicit inexact.', + }, ], - options: ['always'] + options: ['always'], }, { code: 'type foo = { bar: string };', errors: [ { - message: 'Type must be explicit inexact.' - } + message: 'Type must be explicit inexact.', + }, ], - options: ['always'] + options: ['always'], }, // Never @@ -43,88 +43,88 @@ export default { code: 'type foo = {...};', errors: [ { - message: 'Type must not be explicit inexact.' - } + message: 'Type must not be explicit inexact.', + }, ], - options: ['never'] + options: ['never'], }, { code: 'type foo = { bar: string, ... };', errors: [ { - message: 'Type must not be explicit inexact.' - } + message: 'Type must not be explicit inexact.', + }, ], - options: ['never'] - } + options: ['never'], + }, ], valid: [ // Always { - code: 'type foo = { foo: string, ... };' + code: 'type foo = { foo: string, ... };', }, { - code: 'interface Foo { foo: string }' + code: 'interface Foo { foo: string }', }, { - code: 'declare class Foo { foo: string }' + code: 'declare class Foo { foo: string }', }, { - code: 'type foo = {| |};' + code: 'type foo = {| |};', }, { - code: 'type foo = {| bar: string |};' + code: 'type foo = {| bar: string |};', }, { - code: 'type foo = { [key: string]: string, ... };' + code: 'type foo = { [key: string]: string, ... };', }, { - code: 'type foo = number;' + code: 'type foo = number;', }, { code: 'type foo = {| |};', - options: ['always'] + options: ['always'], }, { code: 'type foo = {...};', - options: ['always'] + options: ['always'], }, { code: 'type foo = { bar: string, ... };', - options: ['always'] + options: ['always'], }, { code: 'type foo = {| bar: string |};', - options: ['always'] + options: ['always'], }, { code: 'type foo = number;', - options: ['always'] + options: ['always'], }, // Never { code: 'type foo = { };', - options: ['never'] + options: ['never'], }, { code: 'type foo = {| |};', - options: ['never'] + options: ['never'], }, { code: 'type foo = { bar: string };', - options: ['never'] + options: ['never'], }, { code: 'type foo = {| bar: string |};', - options: ['never'] + options: ['never'], }, { code: 'type foo = number;', - options: ['never'] - } - ] + options: ['never'], + }, + ], }; diff --git a/tests/rules/assertions/requireParameterType.js b/tests/rules/assertions/requireParameterType.js index cbdb3d34..eedc56da 100644 --- a/tests/rules/assertions/requireParameterType.js +++ b/tests/rules/assertions/requireParameterType.js @@ -4,149 +4,149 @@ export default { code: '(foo) => {}', errors: [ { - message: 'Missing "foo" parameter type annotation.' - } - ] + message: 'Missing "foo" parameter type annotation.', + }, + ], }, { code: 'function x(foo) {}', errors: [ { - message: 'Missing "foo" parameter type annotation.' - } - ] + message: 'Missing "foo" parameter type annotation.', + }, + ], }, { code: 'function x(foo) {}', errors: [ { - message: 'Missing "foo" parameter type annotation.' - } + message: 'Missing "foo" parameter type annotation.', + }, ], options: [ { - excludeArrowFunctions: true - } - ] + excludeArrowFunctions: true, + }, + ], }, { code: '(foo = \'FOO\') => {}', errors: [ { - message: 'Missing "foo" parameter type annotation.' - } - ] + message: 'Missing "foo" parameter type annotation.', + }, + ], }, { code: '(...foo) => {}', errors: [ { - message: 'Missing "foo" parameter type annotation.' - } - ] + message: 'Missing "foo" parameter type annotation.', + }, + ], }, { code: '({foo}) => {}', errors: [ { - message: 'Missing "{foo}" parameter type annotation.' - } - ] + message: 'Missing "{foo}" parameter type annotation.', + }, + ], }, { code: '([foo]) => {}', errors: [ { - message: 'Missing "[foo]" parameter type annotation.' - } - ] + message: 'Missing "[foo]" parameter type annotation.', + }, + ], }, { code: '({foo = 1} = {}) => {}', errors: [ { - message: 'Missing "{foo = 1}" parameter type annotation.' - } - ] + message: 'Missing "{foo = 1}" parameter type annotation.', + }, + ], }, { code: '// @flow\n(foo) => {}', errors: [ { - message: 'Missing "foo" parameter type annotation.' - } + message: 'Missing "foo" parameter type annotation.', + }, ], settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } + onlyFilesWithFlowAnnotation: true, + }, + }, }, { code: '(foo) => {}', errors: [ { - message: 'Missing "foo" parameter type annotation.' - } + message: 'Missing "foo" parameter type annotation.', + }, ], options: [ { - excludeArrowFunctions: 'expressionsOnly' - } - ] + excludeArrowFunctions: 'expressionsOnly', + }, + ], }, { code: 'function x(foo) {}', errors: [ { - message: 'Missing "foo" parameter type annotation.' - } + message: 'Missing "foo" parameter type annotation.', + }, ], options: [ { - excludeArrowFunctions: 'expressionsOnly' - } - ] + excludeArrowFunctions: 'expressionsOnly', + }, + ], }, { code: '(_foo: number, bar) => {}', errors: [ { - message: 'Missing "bar" parameter type annotation.' - } + message: 'Missing "bar" parameter type annotation.', + }, ], options: [ { - excludeParameterMatch: '^_' - } - ] + excludeParameterMatch: '^_', + }, + ], }, { code: '(_foo, bar) => {}', errors: [ { - message: 'Missing "bar" parameter type annotation.' - } + message: 'Missing "bar" parameter type annotation.', + }, ], options: [ { - excludeParameterMatch: '^_' - } - ] - } + excludeParameterMatch: '^_', + }, + ], + }, ], misconfigured: [ { errors: [ { data: { - excludeOtherStuff: true + excludeOtherStuff: true, }, dataPath: '[0]', keyword: 'additionalProperties', message: 'should NOT have additional properties', params: { - additionalProperty: 'excludeOtherStuff' + additionalProperty: 'excludeOtherStuff', }, parentSchema: { additionalProperties: false, @@ -155,20 +155,20 @@ export default { enum: [ false, true, - 'expressionsOnly' - ] + 'expressionsOnly', + ], }, excludeParameterMatch: { - type: 'string' - } + type: 'string', + }, }, - type: 'object' + type: 'object', }, schema: false, - schemaPath: '#/items/0/additionalProperties' - } + schemaPath: '#/items/0/additionalProperties', + }, ], - options: [{excludeOtherStuff: true}] + options: [{excludeOtherStuff: true}], }, { errors: [ @@ -181,25 +181,25 @@ export default { allowedValues: [ false, true, - 'expressionsOnly' - ] + 'expressionsOnly', + ], }, parentSchema: { enum: [ false, true, - 'expressionsOnly' - ] + 'expressionsOnly', + ], }, schema: [ false, true, - 'expressionsOnly' + 'expressionsOnly', ], - schemaPath: '#/items/0/properties/excludeArrowFunctions/enum' - } + schemaPath: '#/items/0/properties/excludeArrowFunctions/enum', + }, ], - options: [{excludeArrowFunctions: 'everything'}] + options: [{excludeArrowFunctions: 'everything'}], }, { errors: [ @@ -209,87 +209,87 @@ export default { keyword: 'type', message: 'should be string', params: { - type: 'string' + type: 'string', }, parentSchema: { - type: 'string' + type: 'string', }, schema: 'string', - schemaPath: '#/items/0/properties/excludeParameterMatch/type' - } + schemaPath: '#/items/0/properties/excludeParameterMatch/type', + }, ], - options: [{excludeParameterMatch: 3}] - } + options: [{excludeParameterMatch: 3}], + }, ], valid: [ { - code: '(foo: string) => {}' + code: '(foo: string) => {}', }, { - code: '(foo: string = \'FOO\') => {}' + code: '(foo: string = \'FOO\') => {}', }, { - code: '(...foo: string) => {}' + code: '(...foo: string) => {}', }, { - code: 'const f: Foo = (a, b) => 42;' + code: 'const f: Foo = (a, b) => 42;', }, { - code: '({foo}: {foo: string}) => {}' + code: '({foo}: {foo: string}) => {}', }, { - code: '([foo]: Array) => {}' + code: '([foo]: Array) => {}', }, { - code: 'type fn = (a: string, b: number) => number;\nconst f: fn = (a, b) => {}' + code: 'type fn = (a: string, b: number) => number;\nconst f: fn = (a, b) => {}', }, { code: '(foo) => {}', settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } + onlyFilesWithFlowAnnotation: true, + }, + }, }, { code: '(foo) => {}', options: [ { - excludeArrowFunctions: true - } - ] + excludeArrowFunctions: true, + }, + ], }, { code: '(foo) => 3', options: [ { - excludeArrowFunctions: 'expressionsOnly' - } - ] + excludeArrowFunctions: 'expressionsOnly', + }, + ], }, { code: '(_foo, bar: string) => {}', options: [ { - excludeParameterMatch: '^_' - } - ] + excludeParameterMatch: '^_', + }, + ], }, { code: '(_foo: number, bar: string) => {}', options: [ { - excludeParameterMatch: '^_' - } - ] + excludeParameterMatch: '^_', + }, + ], }, { code: '(foo) => {}', settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } - } - ] + onlyFilesWithFlowAnnotation: true, + }, + }, + }, + ], }; diff --git a/tests/rules/assertions/requireReadonlyReactProps.js b/tests/rules/assertions/requireReadonlyReactProps.js index d3685a46..96b3d732 100644 --- a/tests/rules/assertions/requireReadonlyReactProps.js +++ b/tests/rules/assertions/requireReadonlyReactProps.js @@ -6,89 +6,89 @@ export default { code: 'type Props = { }; class Foo extends React.Component { }', errors: [ { - message: 'Props must be $ReadOnly' - } - ] + message: 'Props must be $ReadOnly', + }, + ], }, { code: 'type OtherProps = { foo: string }; class Foo extends React.Component { }', errors: [ { - message: 'OtherProps must be $ReadOnly' - } - ] + message: 'OtherProps must be $ReadOnly', + }, + ], }, { code: 'class Foo extends React.Component<{}> { }', errors: [ { - message: 'Foo class props must be $ReadOnly' - } - ] + message: 'Foo class props must be $ReadOnly', + }, + ], }, { code: 'type Props = { bar: {} }; class Foo extends React.Component { }', errors: [ { - message: 'Props must be $ReadOnly' - } - ] + message: 'Props must be $ReadOnly', + }, + ], }, { code: 'type Props = { }; class Foo extends Component { }', errors: [ { - message: 'Props must be $ReadOnly' - } - ] + message: 'Props must be $ReadOnly', + }, + ], }, { code: 'type Props = { }; class Foo extends PureComponent { }', errors: [ { - message: 'Props must be $ReadOnly' - } - ] + message: 'Props must be $ReadOnly', + }, + ], }, { code: 'class Foo extends React.Component { }', errors: [ { - message: 'UnknownProps must be $ReadOnly' - } - ] + message: 'UnknownProps must be $ReadOnly', + }, + ], }, { code: 'export type Props = {}; class Foo extends Component { }', errors: [ { - message: 'Props must be $ReadOnly' - } - ] + message: 'Props must be $ReadOnly', + }, + ], }, { code: 'type Props = {| foo: string |}; class Foo extends Component { }', errors: [ { - message: 'Props must be $ReadOnly' - } - ] + message: 'Props must be $ReadOnly', + }, + ], }, { code: 'type Props = {| +foo: string, ...bar |}; class Foo extends Component { }', errors: [ { - message: 'Props must be $ReadOnly' - } - ] + message: 'Props must be $ReadOnly', + }, + ], }, { code: 'type Props = {| +foo: string, -bar: number |}; class Foo extends Component { }', errors: [ { - message: 'Props must be $ReadOnly' - } - ] + message: 'Props must be $ReadOnly', + }, + ], }, // functional components @@ -96,113 +96,113 @@ export default { code: 'type Props = { }; function Foo(props: Props) { return

}', errors: [ { - message: 'Props must be $ReadOnly' - } - ] + message: 'Props must be $ReadOnly', + }, + ], }, { code: 'type Props = { }; function Foo(props: Props) { return foo ?

: }', errors: [ { - message: 'Props must be $ReadOnly' - } - ] + message: 'Props must be $ReadOnly', + }, + ], }, { code: 'function Foo(props: {}) { return

}', errors: [ { - message: 'Foo component props must be $ReadOnly' - } - ] + message: 'Foo component props must be $ReadOnly', + }, + ], }, { code: 'function Foo(props: UnknownProps) { return

}', errors: [ { - message: 'UnknownProps must be $ReadOnly' - } - ] + message: 'UnknownProps must be $ReadOnly', + }, + ], }, { code: 'export type Props = {}; function Foo(props: Props) { return

}', errors: [ { - message: 'Props must be $ReadOnly' - } - ] - } + message: 'Props must be $ReadOnly', + }, + ], + }, ], valid: [ // class components { - code: 'class Foo extends React.Component<$ReadOnly<{}>> { }' + code: 'class Foo extends React.Component<$ReadOnly<{}>> { }', }, { - code: 'type Props = $ReadOnly<{}>; class Foo extends React.Component { }' + code: 'type Props = $ReadOnly<{}>; class Foo extends React.Component { }', }, { - code: 'type Props = $ReadOnly<{}>; class Foo extends React.PureComponent { }' + code: 'type Props = $ReadOnly<{}>; class Foo extends React.PureComponent { }', }, { - code: 'class Foo extends React.Component<$ReadOnly<{}, State>> { }' + code: 'class Foo extends React.Component<$ReadOnly<{}, State>> { }', }, { - code: 'type Props = $ReadOnly<{}>; class Foo extends React.Component { }' + code: 'type Props = $ReadOnly<{}>; class Foo extends React.Component { }', }, { - code: 'type Props = $ReadOnly<{}>; class Foo extends Component { }' + code: 'type Props = $ReadOnly<{}>; class Foo extends Component { }', }, { - code: 'type Props = $ReadOnly<{}>; class Foo extends PureComponent { }' + code: 'type Props = $ReadOnly<{}>; class Foo extends PureComponent { }', }, { - code: 'type FooType = {}; class Foo extends Bar { }' + code: 'type FooType = {}; class Foo extends Bar { }', }, { - code: 'class Foo { }' + code: 'class Foo { }', }, { - code: 'export type Props = $ReadOnly<{}>; class Foo extends Component { }' + code: 'export type Props = $ReadOnly<{}>; class Foo extends Component { }', }, { - code: 'export type Props = $ReadOnly<{}>; export class Foo extends Component { }' + code: 'export type Props = $ReadOnly<{}>; export class Foo extends Component { }', }, { - code: 'type Props = {| +foo: string |}; class Foo extends Component { }' + code: 'type Props = {| +foo: string |}; class Foo extends Component { }', }, { - code: 'type Props = {| +foo: string, +bar: number |}; class Foo extends Component { }' + code: 'type Props = {| +foo: string, +bar: number |}; class Foo extends Component { }', }, { - code: 'type Props = $FlowFixMe; class Foo extends Component { }' + code: 'type Props = $FlowFixMe; class Foo extends Component { }', }, { - code: 'type Props = {||}; class Foo extends Component { }' + code: 'type Props = {||}; class Foo extends Component { }', }, { - code: 'class Foo extends Component<{||}> { }' + code: 'class Foo extends Component<{||}> { }', }, // functional components { - code: 'type Props = {}; function Foo() { }' + code: 'type Props = {}; function Foo() { }', }, { - code: 'type Props = $ReadOnly<{}>; function Foo(props: Props) { }' + code: 'type Props = $ReadOnly<{}>; function Foo(props: Props) { }', }, { - code: 'type Props = {}; function Foo(props: OtherProps) { }' + code: 'type Props = {}; function Foo(props: OtherProps) { }', }, { - code: 'function Foo() { return

}' + code: 'function Foo() { return

}', }, { - code: 'function Foo(props: $FlowFixMe) { return

}' + code: 'function Foo(props: $FlowFixMe) { return

}', }, { - code: 'function Foo(props: {||}) { return

}' - } - ] + code: 'function Foo(props: {||}) { return

}', + }, + ], }; diff --git a/tests/rules/assertions/requireReturnType.js b/tests/rules/assertions/requireReturnType.js index 94b69e77..e198fbbc 100644 --- a/tests/rules/assertions/requireReturnType.js +++ b/tests/rules/assertions/requireReturnType.js @@ -4,427 +4,427 @@ export default { code: '(foo) => { return "foo"; }', errors: [ { - message: 'Missing return type annotation.' - } - ] + message: 'Missing return type annotation.', + }, + ], }, { code: '(foo) => { return "foo"; }', errors: [ { - message: 'Missing return type annotation.' - } + message: 'Missing return type annotation.', + }, ], options: [ - 'always' - ] + 'always', + ], }, { code: '(foo) => "foo"', errors: [ { - message: 'Missing return type annotation.' - } + message: 'Missing return type annotation.', + }, ], options: [ - 'always' - ] + 'always', + ], }, { code: '(foo) => ({})', errors: [ { - message: 'Missing return type annotation.' - } - ] + message: 'Missing return type annotation.', + }, + ], }, { code: '(foo): undefined => { return; }', errors: [ { - message: 'Must not annotate undefined return type.' - } - ] + message: 'Must not annotate undefined return type.', + }, + ], }, { code: '(foo): void => { return; }', errors: [ { - message: 'Must not annotate undefined return type.' - } - ] + message: 'Must not annotate undefined return type.', + }, + ], }, { code: '(foo): undefined => { return undefined; }', errors: [ { - message: 'Must not annotate undefined return type.' - } - ] + message: 'Must not annotate undefined return type.', + }, + ], }, { code: '(foo): void => { return void 0; }', errors: [ { - message: 'Must not annotate undefined return type.' - } - ] + message: 'Must not annotate undefined return type.', + }, + ], }, { code: '(foo): undefined => { return; }', errors: [ { - message: 'Must not annotate undefined return type.' - } + message: 'Must not annotate undefined return type.', + }, ], options: [ 'always', { - annotateUndefined: 'never' - } - ] + annotateUndefined: 'never', + }, + ], }, { code: '(foo): void => { return; }', errors: [ { - message: 'Must not annotate undefined return type.' - } + message: 'Must not annotate undefined return type.', + }, ], options: [ 'always', { - annotateUndefined: 'never' - } - ] + annotateUndefined: 'never', + }, + ], }, { code: '(foo) => { return; }', errors: [ { - message: 'Must annotate undefined return type.' - } + message: 'Must annotate undefined return type.', + }, ], options: [ 'always', { - annotateUndefined: 'always' - } - ] + annotateUndefined: 'always', + }, + ], }, { code: '(foo): undefined => { return undefined; }', errors: [ { - message: 'Must not annotate undefined return type.' - } + message: 'Must not annotate undefined return type.', + }, ], options: [ 'always', { - annotateUndefined: 'never' - } - ] + annotateUndefined: 'never', + }, + ], }, { code: '(foo) => { return undefined; }', errors: [ { - message: 'Must annotate undefined return type.' - } + message: 'Must annotate undefined return type.', + }, ], options: [ 'always', { - annotateUndefined: 'always' - } - ] + annotateUndefined: 'always', + }, + ], }, { code: '(foo) => { return void 0; }', errors: [ { - message: 'Must annotate undefined return type.' - } + message: 'Must annotate undefined return type.', + }, ], options: [ 'always', { - annotateUndefined: 'always' - } - ] + annotateUndefined: 'always', + }, + ], }, { code: '// @flow\n(foo) => { return 1; }', errors: [ { - message: 'Missing return type annotation.' - } + message: 'Missing return type annotation.', + }, ], settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } + onlyFilesWithFlowAnnotation: true, + }, + }, }, { code: '// @flow\n (foo) => { return undefined; }', errors: [ { - message: 'Must annotate undefined return type.' - } + message: 'Must annotate undefined return type.', + }, ], options: [ 'always', { - annotateUndefined: 'always' - } + annotateUndefined: 'always', + }, ], settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } + onlyFilesWithFlowAnnotation: true, + }, + }, }, { code: 'async () => { return 2; }', errors: [ { - message: 'Missing return type annotation.' - } + message: 'Missing return type annotation.', + }, ], options: [ - 'always' - ] + 'always', + ], }, { code: 'async () => {}', errors: [ { - message: 'Must annotate undefined return type.' - } + message: 'Must annotate undefined return type.', + }, ], options: [ 'always', { - annotateUndefined: 'always' - } - ] + annotateUndefined: 'always', + }, + ], }, { code: 'async function x() {}', errors: [ { - message: 'Must annotate undefined return type.' - } + message: 'Must annotate undefined return type.', + }, ], options: [ 'always', { - annotateUndefined: 'always' - } - ] + annotateUndefined: 'always', + }, + ], }, { code: 'async (): Promise => { return; }', errors: [ { - message: 'Must not annotate undefined return type.' - } + message: 'Must not annotate undefined return type.', + }, ], options: [ 'always', { - annotateUndefined: 'never' - } - ] + annotateUndefined: 'never', + }, + ], }, { code: 'async (): Promise => { return; }', errors: [ { - message: 'Must not annotate undefined return type.' - } + message: 'Must not annotate undefined return type.', + }, ], options: [ 'always', { - annotateUndefined: 'never' - } - ] + annotateUndefined: 'never', + }, + ], }, { code: 'class Test { constructor() { } }', errors: [ { - message: 'Must annotate undefined return type.' - } + message: 'Must annotate undefined return type.', + }, ], options: [ 'always', { - annotateUndefined: 'always' - } - ] + annotateUndefined: 'always', + }, + ], }, { code: 'class Test { foo() { return 42; } }', errors: [ { - message: 'Missing return type annotation.' - } - ] + message: 'Missing return type annotation.', + }, + ], }, { code: 'class Test { foo = () => { return 42; } }', errors: [ { - message: 'Missing return type annotation.' - } - ] + message: 'Missing return type annotation.', + }, + ], }, { code: 'class Test { foo = () => 42; }', errors: [ { - message: 'Missing return type annotation.' - } - ] + message: 'Missing return type annotation.', + }, + ], }, { code: 'function* x() {}', errors: [ { - message: 'Missing return type annotation.' - } + message: 'Missing return type annotation.', + }, ], options: [ - 'always' - ] + 'always', + ], }, { code: '() => { return 3; }', errors: [ { - message: 'Missing return type annotation.' - } + message: 'Missing return type annotation.', + }, ], options: [ 'always', { - excludeArrowFunctions: 'expressionsOnly' - } - ] + excludeArrowFunctions: 'expressionsOnly', + }, + ], }, { code: 'async () => { return 4; }', errors: [ { - message: 'Missing return type annotation.' - } + message: 'Missing return type annotation.', + }, ], options: [ 'always', { - excludeArrowFunctions: 'expressionsOnly' - } - ] + excludeArrowFunctions: 'expressionsOnly', + }, + ], }, { code: 'function foo() { return 42; }\nfunction bar() { return 42; }', errors: [ { - message: 'Missing return type annotation.' - } + message: 'Missing return type annotation.', + }, ], options: [ 'always', { includeOnlyMatching: [ - 'bar' - ] - } - ] + 'bar', + ], + }, + ], }, { code: 'const foo = () => { return 42; };\nconst bar = () => { return 42; }', errors: [ { - message: 'Missing return type annotation.' - } + message: 'Missing return type annotation.', + }, ], options: [ 'always', { includeOnlyMatching: [ - 'bar' - ] - } - ] + 'bar', + ], + }, + ], }, { code: 'const foo = { bar() { return 42; }, foobar: function() { return 42; } }', errors: [ { - message: 'Missing return type annotation.' + message: 'Missing return type annotation.', }, { - message: 'Missing return type annotation.' - } + message: 'Missing return type annotation.', + }, ], options: [ 'always', { includeOnlyMatching: [ - 'bar' - ] - } - ] + 'bar', + ], + }, + ], }, { code: 'const foo = { bar() { return 42; }, baz() { return 42; } }', errors: [ { - message: 'Missing return type annotation.' - } + message: 'Missing return type annotation.', + }, ], options: [ 'always', { excludeMatching: [ - 'bar' - ] - } - ] + 'bar', + ], + }, + ], }, { code: 'function * foo() { yield 2; }', errors: [ { - message: 'Missing return type annotation.' - } + message: 'Missing return type annotation.', + }, ], options: [ 'always', { - annotateUndefined: 'always' - } - ] + annotateUndefined: 'always', + }, + ], }, { code: 'async function * foo() { yield 2; }', errors: [ { - message: 'Missing return type annotation.' - } + message: 'Missing return type annotation.', + }, ], options: [ 'always', { - annotateUndefined: 'always' - } - ] - } + annotateUndefined: 'always', + }, + ], + }, ], misconfigured: [ { @@ -436,34 +436,34 @@ export default { message: 'should be equal to one of the allowed values', params: { allowedValues: [ - 'always' - ] + 'always', + ], }, parentSchema: { enum: [ - 'always' + 'always', ], - type: 'string' + type: 'string', }, schema: [ - 'always' + 'always', ], - schemaPath: '#/items/0/enum' - } + schemaPath: '#/items/0/enum', + }, ], - options: ['never'] + options: ['never'], }, { errors: [ { data: { - excludeOtherStuff: true + excludeOtherStuff: true, }, dataPath: '[1]', keyword: 'additionalProperties', message: 'should NOT have additional properties', params: { - additionalProperty: 'excludeOtherStuff' + additionalProperty: 'excludeOtherStuff', }, parentSchema: { additionalProperties: false, @@ -472,37 +472,37 @@ export default { enum: [ 'always', 'never', - 'ignore' + 'ignore', ], - type: 'string' + type: 'string', }, excludeArrowFunctions: { enum: [ false, true, - 'expressionsOnly' - ] + 'expressionsOnly', + ], }, excludeMatching: { items: { - type: 'string' + type: 'string', }, - type: 'array' + type: 'array', }, includeOnlyMatching: { items: { - type: 'string' + type: 'string', }, - type: 'array' - } + type: 'array', + }, }, - type: 'object' + type: 'object', }, schema: false, - schemaPath: '#/items/1/additionalProperties' - } + schemaPath: '#/items/1/additionalProperties', + }, ], - options: ['always', {excludeOtherStuff: true}] + options: ['always', {excludeOtherStuff: true}], }, { errors: [ @@ -515,26 +515,26 @@ export default { allowedValues: [ 'always', 'never', - 'ignore' - ] + 'ignore', + ], }, parentSchema: { enum: [ 'always', 'never', - 'ignore' + 'ignore', ], - type: 'string' + type: 'string', }, schema: [ 'always', 'never', - 'ignore' + 'ignore', ], - schemaPath: '#/items/1/properties/annotateUndefined/enum' - } + schemaPath: '#/items/1/properties/annotateUndefined/enum', + }, ], - options: ['always', {annotateUndefined: 'often'}] + options: ['always', {annotateUndefined: 'often'}], }, { errors: [ @@ -547,25 +547,25 @@ export default { allowedValues: [ false, true, - 'expressionsOnly' - ] + 'expressionsOnly', + ], }, parentSchema: { enum: [ false, true, - 'expressionsOnly' - ] + 'expressionsOnly', + ], }, schema: [ false, true, - 'expressionsOnly' + 'expressionsOnly', ], - schemaPath: '#/items/1/properties/excludeArrowFunctions/enum' - } + schemaPath: '#/items/1/properties/excludeArrowFunctions/enum', + }, ], - options: ['always', {excludeArrowFunctions: 'everything'}] + options: ['always', {excludeArrowFunctions: 'everything'}], }, { errors: [ @@ -575,19 +575,19 @@ export default { keyword: 'type', message: 'should be array', params: { - type: 'array' + type: 'array', }, parentSchema: { items: { - type: 'string' + type: 'string', }, - type: 'array' + type: 'array', }, schema: 'array', - schemaPath: '#/items/1/properties/excludeMatching/type' - } + schemaPath: '#/items/1/properties/excludeMatching/type', + }, ], - options: ['always', {excludeMatching: '^foo'}] + options: ['always', {excludeMatching: '^foo'}], }, { errors: [ @@ -597,172 +597,172 @@ export default { keyword: 'type', message: 'should be string', params: { - type: 'string' + type: 'string', }, parentSchema: { - type: 'string' + type: 'string', }, schema: 'string', - schemaPath: '#/items/1/properties/includeOnlyMatching/items/type' - } + schemaPath: '#/items/1/properties/includeOnlyMatching/items/type', + }, ], - options: ['always', {includeOnlyMatching: [false]}] - } + options: ['always', {includeOnlyMatching: [false]}], + }, ], valid: [ { - code: 'return;' + code: 'return;', }, { - code: '(foo): string => {}' + code: '(foo): string => {}', }, { - code: 'const f: Foo = (a, b) => 42;' + code: 'const f: Foo = (a, b) => 42;', }, { code: '(foo): string => {}', options: [ - 'always' - ] + 'always', + ], }, { - code: 'type fn = (a: string, b: number) => number;\nconst f: fn = (a, b) => { return 42; }' + code: 'type fn = (a: string, b: number) => number;\nconst f: fn = (a, b) => { return 42; }', }, { - code: '(foo) => { return; }' + code: '(foo) => { return; }', }, { - code: '(foo): Object => ( {} )' + code: '(foo): Object => ( {} )', }, { - code: '(foo) => { return undefined; }' + code: '(foo) => { return undefined; }', }, { - code: '(foo) => { return void 0; }' + code: '(foo) => { return void 0; }', }, { code: '(foo): undefined => { return; }', options: [ 'always', { - annotateUndefined: 'always' - } - ] + annotateUndefined: 'always', + }, + ], }, { code: '(foo): void => { return; }', options: [ 'always', { - annotateUndefined: 'always' - } - ] + annotateUndefined: 'always', + }, + ], }, { code: '(foo) => { return; }', options: [ 'always', { - annotateUndefined: 'never' - } - ] + annotateUndefined: 'never', + }, + ], }, { code: '(foo) => { return undefined; }', options: [ 'always', { - annotateUndefined: 'never' - } - ] + annotateUndefined: 'never', + }, + ], }, { code: '(foo) => { return void 0; }', options: [ 'always', { - annotateUndefined: 'never' - } - ] + annotateUndefined: 'never', + }, + ], }, { code: '(foo): undefined => { return undefined; }', options: [ 'always', { - annotateUndefined: 'always' - } - ] + annotateUndefined: 'always', + }, + ], }, { code: '(foo): void => { return void 0; }', options: [ 'always', { - annotateUndefined: 'always' - } - ] + annotateUndefined: 'always', + }, + ], }, { code: '(foo) => { return 1; }', options: [ - 'always' + 'always', ], settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } + onlyFilesWithFlowAnnotation: true, + }, + }, }, { code: '(foo) => { return undefined; }', options: [ 'always', { - annotateUndefined: 'always' - } + annotateUndefined: 'always', + }, ], settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } + onlyFilesWithFlowAnnotation: true, + }, + }, }, { code: 'async function doThing(): Promise {}', options: [ 'always', { - annotateUndefined: 'always' - } - ] + annotateUndefined: 'always', + }, + ], }, { code: 'async function doThing(): Promise {}', options: [ 'always', { - annotateUndefined: 'ignore' - } - ] + annotateUndefined: 'ignore', + }, + ], }, { code: 'async function doThing() {}', options: [ 'always', { - annotateUndefined: 'ignore' - } - ] + annotateUndefined: 'ignore', + }, + ], }, { code: 'function* doThing(): Generator { yield 2; }', options: [ 'always', { - annotateUndefined: 'always' - } - ] + annotateUndefined: 'always', + }, + ], }, { code: 'class Test { constructor() { } }', @@ -770,75 +770,75 @@ export default { 'always', { annotateUndefined: 'always', - excludeMatching: ['constructor'] - } - ] + excludeMatching: ['constructor'], + }, + ], }, { - code: 'class Test { constructor() { } }' + code: 'class Test { constructor() { } }', }, { code: 'class Test { foo() { return 42; } }', options: [ 'always', { - excludeMatching: ['foo'] - } - ] + excludeMatching: ['foo'], + }, + ], }, { code: 'class Test { foo = () => { return 42; } }', options: [ 'always', { - excludeMatching: ['foo'] - } - ] + excludeMatching: ['foo'], + }, + ], }, { code: 'class Test { foo = () => 42; }', options: [ 'always', { - excludeMatching: ['foo'] - } - ] + excludeMatching: ['foo'], + }, + ], }, { - code: 'class Test { foo = (): number => { return 42; } }' + code: 'class Test { foo = (): number => { return 42; } }', }, { - code: 'class Test { foo = (): number => 42; }' + code: 'class Test { foo = (): number => 42; }', }, { - code: 'async (foo): Promise => { return 3; }' + code: 'async (foo): Promise => { return 3; }', }, { code: '() => 3', options: [ 'always', { - excludeArrowFunctions: true - } - ] + excludeArrowFunctions: true, + }, + ], }, { code: '() => { return 4; }', options: [ 'always', { - excludeArrowFunctions: true - } - ] + excludeArrowFunctions: true, + }, + ], }, { code: '() => undefined', options: [ 'always', { - excludeArrowFunctions: true - } - ] + excludeArrowFunctions: true, + }, + ], }, { code: '() => undefined', @@ -846,9 +846,9 @@ export default { 'always', { annotateUndefined: 'always', - excludeArrowFunctions: true - } - ] + excludeArrowFunctions: true, + }, + ], }, { code: '() => { return undefined; }', @@ -856,27 +856,27 @@ export default { 'always', { annotateUndefined: 'always', - excludeArrowFunctions: true - } - ] + excludeArrowFunctions: true, + }, + ], }, { code: '() => 3', options: [ 'always', { - excludeArrowFunctions: 'expressionsOnly' - } - ] + excludeArrowFunctions: 'expressionsOnly', + }, + ], }, { code: 'async () => 3', options: [ 'always', { - excludeArrowFunctions: 'expressionsOnly' - } - ] + excludeArrowFunctions: 'expressionsOnly', + }, + ], }, { code: 'function foo() { return 42; }', @@ -884,10 +884,10 @@ export default { 'always', { excludeMatching: [ - 'foo' - ] - } - ] + 'foo', + ], + }, + ], }, { code: 'function foo() { return 42; }', @@ -895,10 +895,10 @@ export default { 'always', { includeOnlyMatching: [ - 'bar' - ] - } - ] + 'bar', + ], + }, + ], }, { code: 'function foo(): number { return 42; }\nfunction bar() { return 42; }', @@ -906,10 +906,10 @@ export default { 'always', { excludeMatching: [ - 'bar' - ] - } - ] + 'bar', + ], + }, + ], }, { code: 'function foo(): number { return 42; }\nfunction bar() { return 42; }', @@ -918,10 +918,10 @@ export default { { includeOnlyMatching: [ 'foo', - 'baz' - ] - } - ] + 'baz', + ], + }, + ], }, { code: 'function foo(): number { return 42; }\nfunction bar() { return 42; }', @@ -930,10 +930,10 @@ export default { { excludeMatching: [ '^b.*', - 'qux' - ] - } - ] + 'qux', + ], + }, + ], }, { code: 'function foo(): number { return 42; }\nfunction bar() { return 42; }', @@ -941,10 +941,10 @@ export default { 'always', { includeOnlyMatching: [ - '^f.*' - ] - } - ] + '^f.*', + ], + }, + ], }, { @@ -953,10 +953,10 @@ export default { 'always', { includeOnlyMatching: [ - 'bar' - ] - } - ] + 'bar', + ], + }, + ], }, { code: 'const foo = { bar() { return 42; } }', @@ -964,28 +964,28 @@ export default { 'always', { excludeMatching: [ - 'bar' - ] - } - ] + 'bar', + ], + }, + ], }, { code: 'function * foo(): Iterable { yield 2; }', options: [ 'always', { - annotateUndefined: 'always' - } - ] + annotateUndefined: 'always', + }, + ], }, { code: 'async function * foo(): AsyncIterable { yield 2; }', options: [ 'always', { - annotateUndefined: 'always' - } - ] - } - ] + annotateUndefined: 'always', + }, + ], + }, + ], }; diff --git a/tests/rules/assertions/requireTypesAtTop.js b/tests/rules/assertions/requireTypesAtTop.js index 80a9d5a6..d691a7b8 100644 --- a/tests/rules/assertions/requireTypesAtTop.js +++ b/tests/rules/assertions/requireTypesAtTop.js @@ -2,28 +2,28 @@ export default { invalid: [ { code: 'const foo = 3;\ntype Foo = number;', - errors: [{message: 'All type declaration should be at the top of the file, after any import declarations.'}] + errors: [{message: 'All type declaration should be at the top of the file, after any import declarations.'}], }, { code: 'const foo = 3;\nopaque type Foo = number;', - errors: [{message: 'All type declaration should be at the top of the file, after any import declarations.'}] + errors: [{message: 'All type declaration should be at the top of the file, after any import declarations.'}], }, { code: 'const foo = 3;\nexport type Foo = number;', - errors: [{message: 'All type declaration should be at the top of the file, after any import declarations.'}] + errors: [{message: 'All type declaration should be at the top of the file, after any import declarations.'}], }, { code: 'const foo = 3;\nexport opaque type Foo = number;', - errors: [{message: 'All type declaration should be at the top of the file, after any import declarations.'}] + errors: [{message: 'All type declaration should be at the top of the file, after any import declarations.'}], }, { code: 'const foo = 3;\ntype Foo = number | string;', - errors: [{message: 'All type declaration should be at the top of the file, after any import declarations.'}] + errors: [{message: 'All type declaration should be at the top of the file, after any import declarations.'}], }, { code: 'import bar from "./bar";\nconst foo = 3;\ntype Foo = number;', - errors: [{message: 'All type declaration should be at the top of the file, after any import declarations.'}] - } + errors: [{message: 'All type declaration should be at the top of the file, after any import declarations.'}], + }, ], misconfigured: [ { @@ -36,51 +36,51 @@ export default { params: { allowedValues: [ 'always', - 'never' - ] + 'never', + ], }, parentSchema: { enum: [ 'always', - 'never' + 'never', ], - type: 'string' + type: 'string', }, schema: [ 'always', - 'never' + 'never', ], - schemaPath: '#/items/0/enum' - } + schemaPath: '#/items/0/enum', + }, ], - options: ['sometimes'] - } + options: ['sometimes'], + }, ], valid: [ { - code: 'type Foo = number;\nconst foo = 3;' + code: 'type Foo = number;\nconst foo = 3;', }, { - code: 'opaque type Foo = number;\nconst foo = 3;' + code: 'opaque type Foo = number;\nconst foo = 3;', }, { - code: 'export type Foo = number;\nconst foo = 3;' + code: 'export type Foo = number;\nconst foo = 3;', }, { - code: 'export opaque type Foo = number;\nconst foo = 3;' + code: 'export opaque type Foo = number;\nconst foo = 3;', }, { - code: 'type Foo = number;\nconst foo = 3;' + code: 'type Foo = number;\nconst foo = 3;', }, { - code: 'import bar from "./bar";\ntype Foo = number;' + code: 'import bar from "./bar";\ntype Foo = number;', }, { - code: 'type Foo = number;\nimport bar from "./bar";' + code: 'type Foo = number;\nimport bar from "./bar";', }, { code: 'const foo = 3;\ntype Foo = number;', - options: ['never'] - } - ] + options: ['never'], + }, + ], }; diff --git a/tests/rules/assertions/requireValidFileAnnotation.js b/tests/rules/assertions/requireValidFileAnnotation.js index 12f2b3e4..e3c538a5 100644 --- a/tests/rules/assertions/requireValidFileAnnotation.js +++ b/tests/rules/assertions/requireValidFileAnnotation.js @@ -4,213 +4,213 @@ export default { code: ';// @flow', errors: [ { - message: 'Flow file annotation not at the top of the file.' - } - ] + message: 'Flow file annotation not at the top of the file.', + }, + ], }, { code: ';\n// @flow', errors: [ { - message: 'Flow file annotation not at the top of the file.' - } - ] + message: 'Flow file annotation not at the top of the file.', + }, + ], }, { code: '// @Flow', errors: [ { - message: 'Malformed Flow file annotation.' - } - ] + message: 'Malformed Flow file annotation.', + }, + ], }, { code: '// @NoFlow', errors: [ { - message: 'Malformed Flow file annotation.' - } - ] + message: 'Malformed Flow file annotation.', + }, + ], }, { code: '// @Noflow', errors: [ { - message: 'Malformed Flow file annotation.' - } - ] + message: 'Malformed Flow file annotation.', + }, + ], }, { code: '// @floweeeeeee', errors: [ { - message: 'Misspelled or malformed Flow file annotation.' - } - ] + message: 'Misspelled or malformed Flow file annotation.', + }, + ], }, { code: '// @nofloweeeeeee', errors: [ { - message: 'Misspelled or malformed Flow file annotation.' - } - ] + message: 'Misspelled or malformed Flow file annotation.', + }, + ], }, { code: 'a;', errors: [ { - message: 'Flow file annotation is missing.' - } + message: 'Flow file annotation is missing.', + }, ], options: [ - 'always' - ] + 'always', + ], }, { code: '/* @flow */', errors: [ { - message: 'Flow file annotation style must be `// @flow`' - } + message: 'Flow file annotation style must be `// @flow`', + }, ], options: [ 'always', { - annotationStyle: 'line' - } - ] + annotationStyle: 'line', + }, + ], }, { code: '// @flow', errors: [ { - message: 'Flow file annotation style must be `/* @flow */`' - } + message: 'Flow file annotation style must be `/* @flow */`', + }, ], options: [ 'always', { - annotationStyle: 'block' - } - ] + annotationStyle: 'block', + }, + ], }, { code: '// @flow', errors: [ { - message: 'Flow file annotation style must be `/* @flow */`' - } + message: 'Flow file annotation style must be `/* @flow */`', + }, ], options: [ 'always', { - annotationStyle: 'block' - } - ] + annotationStyle: 'block', + }, + ], }, { code: '// @flow', errors: [ { - message: 'Strict Flow file annotation is required, should be `// @flow strict`' - } + message: 'Strict Flow file annotation is required, should be `// @flow strict`', + }, ], options: [ 'always', { annotationStyle: 'line', - strict: true - } - ] + strict: true, + }, + ], }, { code: '/* @noflow */', errors: [ { - message: 'Flow file annotation style must be `// @noflow`' - } + message: 'Flow file annotation style must be `// @noflow`', + }, ], options: [ 'always', { - annotationStyle: 'line' - } - ] + annotationStyle: 'line', + }, + ], }, { code: '// @noflow', errors: [ { - message: 'Flow file annotation style must be `/* @noflow */`' - } + message: 'Flow file annotation style must be `/* @noflow */`', + }, ], options: [ 'always', { - annotationStyle: 'block' - } - ] + annotationStyle: 'block', + }, + ], }, { code: 'a;', errors: [ { - message: 'Flow file annotation is missing.' - } + message: 'Flow file annotation is missing.', + }, ], options: [ - 'always' + 'always', ], - output: '// @flow\na;' + output: '// @flow\na;', }, { code: 'a;', errors: [ { - message: 'Flow file annotation is missing.' - } + message: 'Flow file annotation is missing.', + }, ], options: [ 'always', { - annotationStyle: 'block' - } + annotationStyle: 'block', + }, ], - output: '/* @flow */\na;' + output: '/* @flow */\na;', }, { code: 'a;', errors: [ { - message: 'Flow file annotation is missing.' - } + message: 'Flow file annotation is missing.', + }, ], options: [ 'always', { annotationStyle: 'line', - strict: true - } + strict: true, + }, ], - output: '// @flow strict\na;' + output: '// @flow strict\na;', }, { code: '// @flow\na;\nb;', errors: [ { - message: 'Strict Flow file annotation is required, should be `// @flow strict`' - } + message: 'Strict Flow file annotation is required, should be `// @flow strict`', + }, ], options: [ 'always', { annotationStyle: 'line', - strict: true - } + strict: true, + }, ], - output: '// @flow strict\na;\nb;' - } + output: '// @flow strict\na;\nb;', + }, ], misconfigured: [ { @@ -223,24 +223,24 @@ export default { params: { allowedValues: [ 'always', - 'never' - ] + 'never', + ], }, parentSchema: { enum: [ 'always', - 'never' + 'never', ], - type: 'string' + type: 'string', }, schema: [ 'always', - 'never' + 'never', ], - schemaPath: '#/items/0/enum' - } + schemaPath: '#/items/0/enum', + }, ], - options: ['sometimes'] + options: ['sometimes'], }, { errors: [ @@ -253,70 +253,70 @@ export default { allowedValues: [ 'none', 'line', - 'block' - ] + 'block', + ], }, parentSchema: { enum: [ 'none', 'line', - 'block' + 'block', ], - type: 'string' + type: 'string', }, schema: [ 'none', 'line', - 'block' + 'block', ], - schemaPath: '#/items/1/properties/annotationStyle/enum' - } + schemaPath: '#/items/1/properties/annotationStyle/enum', + }, ], - options: ['never', {annotationStyle: 'upside-down'}] - } + options: ['never', {annotationStyle: 'upside-down'}], + }, ], valid: [ { - code: 'a;' + code: 'a;', }, { - code: '// @flow\na;' + code: '// @flow\na;', }, { - code: '//@flow\na;' + code: '//@flow\na;', }, { - code: '//**@flow\na;' + code: '//**@flow\na;', }, { - code: '/* foo @flow bar */\na;' + code: '/* foo @flow bar */\na;', }, { - code: '\n\n// @flow\na;' + code: '\n\n// @flow\na;', }, { - code: '// @flow\n// @FLow' + code: '// @flow\n// @FLow', }, { - code: '// @noflow\na;' + code: '// @noflow\na;', }, { code: 'a;', options: ['always'], settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } + onlyFilesWithFlowAnnotation: true, + }, + }, }, { code: '// @flow', options: [ 'always', { - annotationStyle: 'line' - } - ] + annotationStyle: 'line', + }, + ], }, { code: '// @noflow', @@ -324,9 +324,9 @@ export default { 'always', { annotationStyle: 'line', - strict: true - } - ] + strict: true, + }, + ], }, { code: '// @flow strict', @@ -334,31 +334,31 @@ export default { 'always', { annotationStyle: 'line', - strict: true - } - ] + strict: true, + }, + ], }, { code: '// @function', options: [ 'never', { - annotationStyle: 'none' - } - ] + annotationStyle: 'none', + }, + ], }, { code: '// @fixable', - options: ['never'] + options: ['never'], }, { code: '/* @flow */', options: [ 'always', { - annotationStyle: 'block' - } - ] - } - ] + annotationStyle: 'block', + }, + ], + }, + ], }; diff --git a/tests/rules/assertions/requireVariableType.js b/tests/rules/assertions/requireVariableType.js index 09c51c75..64bced58 100644 --- a/tests/rules/assertions/requireVariableType.js +++ b/tests/rules/assertions/requireVariableType.js @@ -4,90 +4,90 @@ export default { code: 'var foo = "bar"', errors: [ { - message: 'Missing "foo" variable type annotation.' - } - ] + message: 'Missing "foo" variable type annotation.', + }, + ], }, { code: 'var foo : string = "bar", bar = 1', errors: [ { - message: 'Missing "bar" variable type annotation.' - } - ] + message: 'Missing "bar" variable type annotation.', + }, + ], }, { code: 'var _foo = "bar", bar = 1', errors: [ { - message: 'Missing "bar" variable type annotation.' - } + message: 'Missing "bar" variable type annotation.', + }, ], options: [ { - excludeVariableMatch: '^_' - } - ] + excludeVariableMatch: '^_', + }, + ], }, { code: 'var foo = "bar", bar = 1; const oob : string = "oob"; let hey = "yah"', errors: [ { - message: 'Missing "hey" variable type annotation.' - } + message: 'Missing "hey" variable type annotation.', + }, ], options: [ { excludeVariableTypes: { let: false, - var: true - } - } - ] - } + var: true, + }, + }, + ], + }, ], misconfigured: [ { errors: [ { data: { - excludeOtherStuff: true + excludeOtherStuff: true, }, dataPath: '[0]', keyword: 'additionalProperties', message: 'should NOT have additional properties', params: { - additionalProperty: 'excludeOtherStuff' + additionalProperty: 'excludeOtherStuff', }, parentSchema: { additionalProperties: false, properties: { excludeVariableMatch: { - type: 'string' + type: 'string', }, excludeVariableTypes: { additionalProperties: false, properties: { const: { - type: 'boolean' + type: 'boolean', }, let: { - type: 'boolean' + type: 'boolean', }, var: { - type: 'boolean' - } + type: 'boolean', + }, }, - type: 'object' - } + type: 'object', + }, }, - type: 'object' + type: 'object', }, schema: false, - schemaPath: '#/items/0/additionalProperties' - } + schemaPath: '#/items/0/additionalProperties', + }, ], - options: [{excludeOtherStuff: true}] + options: [{excludeOtherStuff: true}], }, { errors: [ @@ -97,49 +97,49 @@ export default { keyword: 'type', message: 'should be string', params: { - type: 'string' + type: 'string', }, parentSchema: { - type: 'string' + type: 'string', }, schema: 'string', - schemaPath: '#/items/0/properties/excludeVariableMatch/type' - } + schemaPath: '#/items/0/properties/excludeVariableMatch/type', + }, ], - options: [{excludeVariableMatch: 99}] + options: [{excludeVariableMatch: 99}], }, { errors: [ { data: { - declare: false + declare: false, }, dataPath: '[0].excludeVariableTypes', keyword: 'additionalProperties', message: 'should NOT have additional properties', params: { - additionalProperty: 'declare' + additionalProperty: 'declare', }, parentSchema: { additionalProperties: false, properties: { const: { - type: 'boolean' + type: 'boolean', }, let: { - type: 'boolean' + type: 'boolean', }, var: { - type: 'boolean' - } + type: 'boolean', + }, }, - type: 'object' + type: 'object', }, schema: false, - schemaPath: '#/items/0/properties/excludeVariableTypes/additionalProperties' - } + schemaPath: '#/items/0/properties/excludeVariableTypes/additionalProperties', + }, ], - options: [{excludeVariableTypes: {declare: false}}] + options: [{excludeVariableTypes: {declare: false}}], }, { errors: [ @@ -149,42 +149,42 @@ export default { keyword: 'type', message: 'should be boolean', params: { - type: 'boolean' + type: 'boolean', }, parentSchema: { - type: 'boolean' + type: 'boolean', }, schema: 'boolean', - schemaPath: '#/items/0/properties/excludeVariableTypes/properties/let/type' - } + schemaPath: '#/items/0/properties/excludeVariableTypes/properties/let/type', + }, ], - options: [{excludeVariableTypes: {let: 'yes'}}] - } + options: [{excludeVariableTypes: {let: 'yes'}}], + }, ], valid: [ { - code: 'var foo : string = "bar"' + code: 'var foo : string = "bar"', }, { - code: 'var foo : string = "bar", bar : number = 1' + code: 'var foo : string = "bar", bar : number = 1', }, { code: 'var _foo = "bar", bar : number = 1', options: [ { - excludeVariableMatch: '^_' - } - ] + excludeVariableMatch: '^_', + }, + ], }, { code: 'var foo = "bar", bar = 1', options: [ { excludeVariableTypes: { - var: true - } - } - ] + var: true, + }, + }, + ], }, { code: 'var foo = "bar", bar = 1; const oob : string = "oob"; let hey = "yah"', @@ -192,10 +192,10 @@ export default { { excludeVariableTypes: { let: true, - var: true - } - } - ] - } - ] + var: true, + }, + }, + ], + }, + ], }; diff --git a/tests/rules/assertions/semi.js b/tests/rules/assertions/semi.js index 17cffb98..7dd267f0 100644 --- a/tests/rules/assertions/semi.js +++ b/tests/rules/assertions/semi.js @@ -4,42 +4,42 @@ export default { code: 'type FooType = {}', errors: [ { - message: 'Missing semicolon.' - } + message: 'Missing semicolon.', + }, ], options: [], - output: 'type FooType = {};' + output: 'type FooType = {};', }, { code: 'type FooType = {}', errors: [ { - message: 'Missing semicolon.' - } + message: 'Missing semicolon.', + }, ], options: ['always'], - output: 'type FooType = {};' + output: 'type FooType = {};', }, { code: 'type FooType = {};', errors: [ { - message: 'Extra semicolon.' - } + message: 'Extra semicolon.', + }, ], options: ['never'], - output: 'type FooType = {}' + output: 'type FooType = {}', }, { code: 'opaque type FooType = {}', errors: [ { - message: 'Missing semicolon.' - } + message: 'Missing semicolon.', + }, ], options: [], - output: 'opaque type FooType = {};' - } + output: 'opaque type FooType = {};', + }, ], misconfigured: [ { @@ -52,56 +52,56 @@ export default { params: { allowedValues: [ 'always', - 'never' - ] + 'never', + ], }, parentSchema: { enum: [ 'always', - 'never' + 'never', ], - type: 'string' + type: 'string', }, schema: [ 'always', - 'never' + 'never', ], - schemaPath: '#/items/0/enum' - } + schemaPath: '#/items/0/enum', + }, ], - options: ['temporarily'] - } + options: ['temporarily'], + }, ], valid: [ { - code: 'type FooType = {};' + code: 'type FooType = {};', }, { code: 'type FooType = {};', - options: ['always'] + options: ['always'], }, { code: 'type FooType = { a: number;\n b: string;\n };', - options: ['always'] + options: ['always'], }, { code: 'type FooType = { a: number;\n b: string;\n }', - options: ['never'] + options: ['never'], }, { code: 'type FooType = {}', - options: ['never'] + options: ['never'], }, { code: 'type FooType = {}', settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } + onlyFilesWithFlowAnnotation: true, + }, + }, }, { - code: 'opaque type FooType = {};' - } - ] + code: 'opaque type FooType = {};', + }, + ], }; diff --git a/tests/rules/assertions/sortKeys.js b/tests/rules/assertions/sortKeys.js index 111602ff..0f58def5 100644 --- a/tests/rules/assertions/sortKeys.js +++ b/tests/rules/assertions/sortKeys.js @@ -2,50 +2,50 @@ export default { invalid: [ { code: 'type FooType = { a: number, c: number, b: string }', - errors: [{message: 'Expected type annotations to be in ascending order. "b" should be before "c".'}] + errors: [{message: 'Expected type annotations to be in ascending order. "b" should be before "c".'}], }, { code: 'type FooType = { a: number, b: number, C: number }', - errors: [{message: 'Expected type annotations to be in ascending order. "C" should be before "b".'}] + errors: [{message: 'Expected type annotations to be in ascending order. "C" should be before "b".'}], }, { code: 'type FooType = { 1: number, 2: number, 10: number }', - errors: [{message: 'Expected type annotations to be in ascending order. "10" should be before "2".'}] + errors: [{message: 'Expected type annotations to be in ascending order. "10" should be before "2".'}], }, { code: 'type FooType = { a: number, b: number }', errors: [{message: 'Expected type annotations to be in descending order. "b" should be before "a".'}], - options: ['desc'] + options: ['desc'], }, { code: 'type FooType = { C: number, b: number, a: string }', errors: [{message: 'Expected type annotations to be in descending order. "b" should be before "C".'}], - options: ['desc'] + options: ['desc'], }, { code: 'type FooType = { 10: number, 2: number, 1: number }', errors: [{message: 'Expected type annotations to be in descending order. "2" should be before "10".'}], - options: ['desc'] + options: ['desc'], }, { code: 'type FooType = { a: number, c: number, C: number, b: string }', errors: [{message: 'Expected type annotations to be in insensitive ascending order. "b" should be before "C".'}], - options: ['asc', {caseSensitive: false}] + options: ['asc', {caseSensitive: false}], }, { code: 'type FooType = { a: number, C: number, c: number, b: string }', errors: [{message: 'Expected type annotations to be in insensitive ascending order. "b" should be before "c".'}], - options: ['asc', {caseSensitive: false}] + options: ['asc', {caseSensitive: false}], }, { code: 'type FooType = { 1: number, 10: number, 2: boolean }', errors: [{message: 'Expected type annotations to be in natural ascending order. "2" should be before "10".'}], - options: ['asc', {natural: true}] + options: ['asc', {natural: true}], }, { code: 'type FooType = { a: number, c: number, b: string }', errors: [{message: 'Expected type annotations to be in ascending order. "b" should be before "c".'}], - output: 'type FooType = { a: number, b: string, c: number }' + output: 'type FooType = { a: number, b: string, c: number }', }, /* eslint-disable no-restricted-syntax */ { @@ -63,7 +63,7 @@ export default { b: string, c: number, } - ` + `, }, { code: ` @@ -80,7 +80,7 @@ export default { b: string, c: number, } - ` + `, }, { code: ` @@ -97,7 +97,7 @@ export default { b: string, c: number, } - ` + `, }, { code: ` @@ -114,7 +114,7 @@ export default { b: string, c: ?number, } - ` + `, }, { code: ` @@ -131,7 +131,7 @@ export default { b: (param: string) => number, c: number, } - ` + `, }, { code: ` @@ -148,7 +148,7 @@ export default { b: (param: string) => number, c: number, } - ` + `, }, { code: ` @@ -165,7 +165,7 @@ export default { b: (param: string) => number, c: number, } - ` + `, }, { code: ` @@ -181,7 +181,7 @@ export default { `, errors: [ {message: 'Expected type annotations to be in ascending order. "x" should be before "z".'}, - {message: 'Expected type annotations to be in ascending order. "a" should be before "c".'} + {message: 'Expected type annotations to be in ascending order. "a" should be before "c".'}, ], output: ` type FooType = { @@ -193,7 +193,7 @@ export default { z: number, }, } - ` + `, }, { code: ` @@ -214,7 +214,7 @@ export default { errors: [ {message: 'Expected type annotations to be in ascending order. "k" should be before "l".'}, {message: 'Expected type annotations to be in ascending order. "x" should be before "z".'}, - {message: 'Expected type annotations to be in ascending order. "a" should be before "c".'} + {message: 'Expected type annotations to be in ascending order. "a" should be before "c".'}, ], output: ` type FooType = { @@ -230,7 +230,7 @@ export default { }, }, } - ` + `, }, { code: ` @@ -242,7 +242,7 @@ export default { `, errors: [ {message: 'Expected type annotations to be in ascending order. "b" should be before "c".'}, - {message: 'Expected type annotations to be in ascending order. "a" should be before "b".'} + {message: 'Expected type annotations to be in ascending order. "a" should be before "b".'}, ], output: ` type FooType = { @@ -250,7 +250,7 @@ export default { -b: number, +c: number, } - ` + `, }, { code: ` @@ -262,7 +262,7 @@ export default { `, errors: [ {message: 'Expected type annotations to be in ascending order. "b" should be before "c".'}, - {message: 'Expected type annotations to be in ascending order. "a" should be before "b".'} + {message: 'Expected type annotations to be in ascending order. "a" should be before "b".'}, ], output: ` type FooType = {| @@ -270,8 +270,8 @@ export default { -b: number, +c: number, |} - ` - } + `, + }, /* eslint-enable no-restricted-syntax */ ], misconfigured: [ @@ -285,54 +285,54 @@ export default { params: { allowedValues: [ 'asc', - 'desc' - ] + 'desc', + ], }, parentSchema: { enum: [ 'asc', - 'desc' + 'desc', ], - type: 'string' + type: 'string', }, schema: [ 'asc', - 'desc' + 'desc', ], - schemaPath: '#/items/0/enum' - } + schemaPath: '#/items/0/enum', + }, ], - options: ['random'] + options: ['random'], }, { errors: [ { data: { - language: 'jp-JP' + language: 'jp-JP', }, dataPath: '[1]', keyword: 'additionalProperties', message: 'should NOT have additional properties', params: { - additionalProperty: 'language' + additionalProperty: 'language', }, parentSchema: { additionalProperties: false, properties: { caseSensitive: { - type: 'boolean' + type: 'boolean', }, natural: { - type: 'boolean' - } + type: 'boolean', + }, }, - type: 'object' + type: 'object', }, schema: false, - schemaPath: '#/items/1/additionalProperties' - } + schemaPath: '#/items/1/additionalProperties', + }, ], - options: ['asc', {language: 'jp-JP'}] + options: ['asc', {language: 'jp-JP'}], }, { errors: [ @@ -342,16 +342,16 @@ export default { keyword: 'type', message: 'should be boolean', params: { - type: 'boolean' + type: 'boolean', }, parentSchema: { - type: 'boolean' + type: 'boolean', }, schema: 'boolean', - schemaPath: '#/items/1/properties/caseSensitive/type' - } + schemaPath: '#/items/1/properties/caseSensitive/type', + }, ], - options: ['desc', {caseSensitive: 'no'}] + options: ['desc', {caseSensitive: 'no'}], }, { errors: [ @@ -361,62 +361,62 @@ export default { keyword: 'type', message: 'should be boolean', params: { - type: 'boolean' + type: 'boolean', }, parentSchema: { - type: 'boolean' + type: 'boolean', }, schema: 'boolean', - schemaPath: '#/items/1/properties/natural/type' - } + schemaPath: '#/items/1/properties/natural/type', + }, ], - options: ['desc', {natural: 'no'}] - } + options: ['desc', {natural: 'no'}], + }, ], valid: [ { - code: 'type FooType = { a: number }' + code: 'type FooType = { a: number }', }, { - code: 'type FooType = { a: number, b: number, c: (boolean | number) }' + code: 'type FooType = { a: number, b: number, c: (boolean | number) }', }, { - code: 'type FooType = { C: number, a: string, b: foo }' + code: 'type FooType = { C: number, a: string, b: foo }', }, { - code: 'type FooType = { 1: number, 10: number, 2: boolean }' + code: 'type FooType = { 1: number, 10: number, 2: boolean }', }, { code: 'type FooType = { c: number, b: number, a: number }', - options: ['desc'] + options: ['desc'], }, { code: 'type FooType = { b: string, a: {}, C: number }', - options: ['desc'] + options: ['desc'], }, { code: 'type FooType = { 2: number, 10: number, 1: boolean }', - options: ['desc'] + options: ['desc'], }, { code: 'type FooType = { a: number, b: number, c: number, C: number }', - options: ['asc', {caseSensitive: false}] + options: ['asc', {caseSensitive: false}], }, { code: 'type FooType = { a: number, b: number, C: number, c: number }', - options: ['asc', {caseSensitive: false}] + options: ['asc', {caseSensitive: false}], }, { code: 'type FooType = { 1:number, 2: number, 10: number }', - options: ['asc', {natural: true}] + options: ['asc', {natural: true}], }, { code: 'type FooType = { b: number, a: number }', settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } - } - ] + onlyFilesWithFlowAnnotation: true, + }, + }, + }, + ], }; diff --git a/tests/rules/assertions/spaceAfterTypeColon.js b/tests/rules/assertions/spaceAfterTypeColon.js index 0ee9ed92..6458ed48 100644 --- a/tests/rules/assertions/spaceAfterTypeColon.js +++ b/tests/rules/assertions/spaceAfterTypeColon.js @@ -6,142 +6,142 @@ const ARROW_FUNCTION_PARAMS = { code: '(foo: string) => {}', errors: [{message: 'There must be no space after "foo" parameter type annotation colon.'}], options: ['never'], - output: '(foo:string) => {}' + output: '(foo:string) => {}', }, { code: '(foo: string) => {}', errors: [{message: 'There must be 1 space after "foo" parameter type annotation colon.'}], options: ['always'], - output: '(foo: string) => {}' + output: '(foo: string) => {}', }, { code: '(foo:(() => void)) => {}', errors: [{message: 'There must be a space after "foo" parameter type annotation colon.'}], options: ['always'], - output: '(foo: (() => void)) => {}' + output: '(foo: (() => void)) => {}', }, { code: '(foo: (() => void)) => {}', errors: [{message: 'There must be no space after "foo" parameter type annotation colon.'}], options: ['never'], - output: '(foo:(() => void)) => {}' + output: '(foo:(() => void)) => {}', }, { code: '(foo: (() => void)) => {}', errors: [{message: 'There must be 1 space after "foo" parameter type annotation colon.'}], options: ['always'], - output: '(foo: (() => void)) => {}' + output: '(foo: (() => void)) => {}', }, { code: '({ lorem, ipsum, dolor } : SomeType) => {}', errors: [{message: 'There must be 1 space after "{ lorem, ipsum, dolor }" parameter type annotation colon.'}], - output: '({ lorem, ipsum, dolor } : SomeType) => {}' + output: '({ lorem, ipsum, dolor } : SomeType) => {}', }, { code: '(foo:{ a: string, b: number }) => {}', errors: [{message: 'There must be a space after "foo" parameter type annotation colon.'}], - output: '(foo: { a: string, b: number }) => {}' + output: '(foo: { a: string, b: number }) => {}', }, { code: '({ a, b } :{ a: string, b: number }) => {}', errors: [{message: 'There must be a space after "{ a, b }" parameter type annotation colon.'}], - output: '({ a, b } : { a: string, b: number }) => {}' + output: '({ a, b } : { a: string, b: number }) => {}', }, { code: '([ a, b ] :string[]) => {}', errors: [{message: 'There must be a space after "[ a, b ]" parameter type annotation colon.'}], - output: '([ a, b ] : string[]) => {}' + output: '([ a, b ] : string[]) => {}', }, { code: '(i?:number) => {}', errors: [{message: 'There must be a space after "i" parameter type annotation colon.'}], - output: '(i?: number) => {}' + output: '(i?: number) => {}', }, { code: '(i?: number) => {}', errors: [{message: 'There must be 1 space after "i" parameter type annotation colon.'}], - output: '(i?: number) => {}' + output: '(i?: number) => {}', }, { code: '(i?: number) => {}', errors: [{message: 'There must be no space after "i" parameter type annotation colon.'}], options: ['never'], - output: '(i?:number) => {}' + output: '(i?:number) => {}', }, { code: '(foo:\n { a: string, b: number }) => {}', errors: [{message: 'There must not be a line break after "foo" parameter type annotation colon.'}], - output: '(foo: { a: string, b: number }) => {}' + output: '(foo: { a: string, b: number }) => {}', }, { code: '(foo:\n{ a: string, b: number }) => {}', errors: [{message: 'There must not be a line break after "foo" parameter type annotation colon.'}], - output: '(foo: { a: string, b: number }) => {}' + output: '(foo: { a: string, b: number }) => {}', }, { code: '(foo: \n{ a: string, b: number }) => {}', errors: [{message: 'There must not be a line break after "foo" parameter type annotation colon.'}], - output: '(foo: { a: string, b: number }) => {}' - } + output: '(foo: { a: string, b: number }) => {}', + }, ], valid: [ { - code: '(foo) => {}' + code: '(foo) => {}', }, { - code: '(foo: string) => {}' + code: '(foo: string) => {}', }, { - code: '(foo: (string|number)) => {}' + code: '(foo: (string|number)) => {}', }, { code: '(foo:string) => {}', - options: ['never'] + options: ['never'], }, { code: '(foo: string) => {}', - options: ['always'] + options: ['always'], }, { code: '(foo:(() => void)) => {}', - options: ['never'] + options: ['never'], }, { code: '(foo: (() => void)) => {}', - options: ['always'] + options: ['always'], }, { - code: '({ lorem, ipsum, dolor }: SomeType) => {}' + code: '({ lorem, ipsum, dolor }: SomeType) => {}', }, { - code: '(foo: { a: string, b: number }) => {}' + code: '(foo: { a: string, b: number }) => {}', }, { - code: '({ a, b }: ?{ a: string, b: number }) => {}' + code: '({ a, b }: ?{ a: string, b: number }) => {}', }, { - code: '([ a, b ]: string[]) => {}' + code: '([ a, b ]: string[]) => {}', }, { - code: '(i?: number) => {}' + code: '(i?: number) => {}', }, { code: '(i?:number) => {}', - options: ['never'] + options: ['never'], }, { code: '(foo:\n { a: string, b: number }) => {}', options: ['always', { - allowLineBreak: true - }] + allowLineBreak: true, + }], }, { code: '(foo:\r\n { a: string, b: number }) => {}', options: ['always', { - allowLineBreak: true - }] - } - ] + allowLineBreak: true, + }], + }, + ], }; const ARROW_FUNCTION_RETURN = { @@ -150,88 +150,88 @@ const ARROW_FUNCTION_RETURN = { code: '():Object => {}', errors: [{message: 'There must be a space after return type colon.'}], options: ['always'], - output: '(): Object => {}' + output: '(): Object => {}', }, { code: '(): Object => {}', errors: [{message: 'There must be no space after return type colon.'}], options: ['never'], - output: '():Object => {}' + output: '():Object => {}', }, { code: '(): Object => {}', errors: [{message: 'There must be 1 space after return type colon.'}], options: ['always'], - output: '(): Object => {}' + output: '(): Object => {}', }, { code: '():(() => void) => {}', errors: [{message: 'There must be a space after return type colon.'}], options: ['always'], - output: '(): (() => void) => {}' + output: '(): (() => void) => {}', }, { code: '(): (() => void) => {}', errors: [{message: 'There must be no space after return type colon.'}], options: ['never'], - output: '():(() => void) => {}' + output: '():(() => void) => {}', }, { code: '(): (() => void) => {}', errors: [{message: 'There must be 1 space after return type colon.'}], options: ['always'], - output: '(): (() => void) => {}' - } + output: '(): (() => void) => {}', + }, ], valid: [ { code: '():Object => {}', - options: ['never'] + options: ['never'], }, { code: '(): Object => {}', - options: ['always'] + options: ['always'], }, { code: '():(number | string) => {}', - options: ['never'] + options: ['never'], }, { code: '(): (number | string) => {}', - options: ['always'] + options: ['always'], }, { code: '():number|string => {}', - options: ['never'] + options: ['never'], }, { code: '(): number|string => {}', - options: ['always'] + options: ['always'], }, { code: '():(() => void) => {}', - options: ['never'] + options: ['never'], }, { code: '(): (() => void) => {}', - options: ['always'] + options: ['always'], }, { code: '():( () => void ) => {}', - options: ['never'] + options: ['never'], }, { code: '(): ( () => void ) => {}', - options: ['always'] + options: ['always'], }, { - code: '(): { a: number, b: string } => {}' + code: '(): { a: number, b: string } => {}', }, { code: '() :{ a:number, b:string } => {}', - options: ['never'] - } - ] + options: ['never'], + }, + ], }; const FUNCTION_PARAMS = { @@ -240,76 +240,76 @@ const FUNCTION_PARAMS = { code: 'export default function (foo: string) {}', errors: [{message: 'There must be no space after "foo" parameter type annotation colon.'}], options: ['never'], - output: 'export default function (foo:string) {}' + output: 'export default function (foo:string) {}', }, { code: 'function foo (foo: string) {}', errors: [{message: 'There must be no space after "foo" parameter type annotation colon.'}], options: ['never'], - output: 'function foo (foo:string) {}' + output: 'function foo (foo:string) {}', }, { code: '(foo:string) => {}', errors: [{message: 'There must be a space after "foo" parameter type annotation colon.'}], options: ['always'], - output: '(foo: string) => {}' + output: '(foo: string) => {}', }, { code: 'function foo (foo:string) {}', errors: [{message: 'There must be a space after "foo" parameter type annotation colon.'}], - output: 'function foo (foo: string) {}' + output: 'function foo (foo: string) {}', }, { code: 'async function foo({ lorem, ipsum, dolor }:SomeType) {}', errors: [{message: 'There must be a space after "{ lorem, ipsum, dolor }" parameter type annotation colon.'}], - output: 'async function foo({ lorem, ipsum, dolor }: SomeType) {}' + output: 'async function foo({ lorem, ipsum, dolor }: SomeType) {}', }, { code: 'function x(i?:number) {}', errors: [{message: 'There must be a space after "i" parameter type annotation colon.'}], - output: 'function x(i?: number) {}' + output: 'function x(i?: number) {}', }, { code: 'function x(i?: number) {}', errors: [{message: 'There must be 1 space after "i" parameter type annotation colon.'}], - output: 'function x(i?: number) {}' + output: 'function x(i?: number) {}', }, { code: 'function x(i?: number) {}', errors: [{message: 'There must be no space after "i" parameter type annotation colon.'}], options: ['never'], - output: 'function x(i?:number) {}' - } + output: 'function x(i?:number) {}', + }, ], valid: [ { - code: 'function x(foo: string) {}' + code: 'function x(foo: string) {}', }, { - code: 'class Foo { constructor(foo: string) {} }' + code: 'class Foo { constructor(foo: string) {} }', }, { code: 'function x(foo:string) {}', - options: ['never'] + options: ['never'], }, { code: 'class Foo { constructor(foo:string) {} }', - options: ['never'] + options: ['never'], }, { - code: 'async function foo({ lorem, ipsum, dolor }: SomeType) {}' + code: 'async function foo({ lorem, ipsum, dolor }: SomeType) {}', }, { - code: 'function x({ a, b }: { a: string, b: number }) {}' + code: 'function x({ a, b }: { a: string, b: number }) {}', }, { - code: 'function x(i?: number) {}' + code: 'function x(i?: number) {}', }, { code: 'function x(i?:number) {}', - options: ['never'] - } - ] + options: ['never'], + }, + ], }; const FUNCTION_RETURN = { @@ -317,37 +317,37 @@ const FUNCTION_RETURN = { { code: 'function a():x {}', errors: [{message: 'There must be a space after return type colon.'}], - output: 'function a(): x {}' + output: 'function a(): x {}', }, { code: 'function a(): x {}', errors: [{message: 'There must be 1 space after return type colon.'}], options: ['always'], - output: 'function a(): x {}' + output: 'function a(): x {}', }, { code: 'function a(): x {}', errors: [{message: 'There must be no space after return type colon.'}], options: ['never'], - output: 'function a():x {}' - } + output: 'function a():x {}', + }, ], valid: [ { - code: 'function a(): x {}' + code: 'function a(): x {}', }, { code: 'function a():x {}', - options: ['never'] + options: ['never'], }, { - code: 'function a(): (number | string) {}' + code: 'function a(): (number | string) {}', }, { code: 'function a() :(number | string) {}', - options: ['never'] - } - ] + options: ['never'], + }, + ], }; const FUNCTION_TYPE_PARAMS = { @@ -355,151 +355,151 @@ const FUNCTION_TYPE_PARAMS = { { code: 'type X = (foo:number) => string', errors: [{message: 'There must be a space after "foo" parameter type annotation colon.'}], - output: 'type X = (foo: number) => string' + output: 'type X = (foo: number) => string', }, { code: 'type X = (foo: number) => string', errors: [{message: 'There must be no space after "foo" parameter type annotation colon.'}], options: ['never'], - output: 'type X = (foo:number) => string' + output: 'type X = (foo:number) => string', }, { code: 'type X = (foo: number) => string', errors: [{message: 'There must be 1 space after "foo" parameter type annotation colon.'}], - output: 'type X = (foo: number) => string' + output: 'type X = (foo: number) => string', }, { code: 'type X = (foo:?number) => string', errors: [{message: 'There must be a space after "foo" parameter type annotation colon.'}], - output: 'type X = (foo: ?number) => string' + output: 'type X = (foo: ?number) => string', }, { code: 'type X = (foo:(number)) => string', errors: [{message: 'There must be a space after "foo" parameter type annotation colon.'}], - output: 'type X = (foo: (number)) => string' + output: 'type X = (foo: (number)) => string', }, { code: 'type X = (foo:((number))) => string', errors: [{message: 'There must be a space after "foo" parameter type annotation colon.'}], - output: 'type X = (foo: ((number))) => string' + output: 'type X = (foo: ((number))) => string', }, { code: 'type X = (foo: ((number))) => string', errors: [{message: 'There must be 1 space after "foo" parameter type annotation colon.'}], - output: 'type X = (foo: ((number))) => string' + output: 'type X = (foo: ((number))) => string', }, { code: 'type X = (foo: ((number))) => string', errors: [{message: 'There must be no space after "foo" parameter type annotation colon.'}], options: ['never'], - output: 'type X = (foo:((number))) => string' + output: 'type X = (foo:((number))) => string', }, { code: 'type X = (foo:?(number)) => string', errors: [{message: 'There must be a space after "foo" parameter type annotation colon.'}], - output: 'type X = (foo: ?(number)) => string' + output: 'type X = (foo: ?(number)) => string', }, { code: 'type TArrayPredicate = (el: T, i?:number) => boolean', errors: [{message: 'There must be a space after "i" parameter type annotation colon.'}], - output: 'type TArrayPredicate = (el: T, i?: number) => boolean' + output: 'type TArrayPredicate = (el: T, i?: number) => boolean', }, { code: 'type TArrayPredicate = (el: T, i?: number) => boolean', errors: [{message: 'There must be 1 space after "i" parameter type annotation colon.'}], - output: 'type TArrayPredicate = (el: T, i?: number) => boolean' + output: 'type TArrayPredicate = (el: T, i?: number) => boolean', }, { code: 'type TArrayPredicate = (el:T, i?: number) => boolean', errors: [{message: 'There must be no space after "i" parameter type annotation colon.'}], options: ['never'], - output: 'type TArrayPredicate = (el:T, i?:number) => boolean' - } + output: 'type TArrayPredicate = (el:T, i?:number) => boolean', + }, ], valid: [ { - code: 'type X = (foo: number) => string;' + code: 'type X = (foo: number) => string;', }, { - code: 'type X = (foo : number) => string;' + code: 'type X = (foo : number) => string;', }, { - code: 'type X = (foo: ?number) => string;' + code: 'type X = (foo: ?number) => string;', }, { - code: 'type X = (foo? : ?number) => string;' + code: 'type X = (foo? : ?number) => string;', }, { - code: 'type X = (foo: ?{ x: number }) => string;' + code: 'type X = (foo: ?{ x: number }) => string;', }, { code: 'type X = (foo:number) => string;', - options: ['never'] + options: ['never'], }, { code: 'type X = (foo:?{ x:number }) => string;', - options: ['never'] + options: ['never'], }, { - code: 'type X = (foo: (number)) => string' + code: 'type X = (foo: (number)) => string', }, { - code: 'type X = (foo: ((number))) => string' + code: 'type X = (foo: ((number))) => string', }, { code: 'type X = (foo:((number))) => string', - options: ['never'] + options: ['never'], }, { - code: 'type X = ?(foo: ((number))) => string' + code: 'type X = ?(foo: ((number))) => string', }, { code: 'type X = ?(foo:((number))) => string', - options: ['never'] + options: ['never'], }, { - code: 'type TArrayPredicate = (el: T, i?: number) => boolean' + code: 'type TArrayPredicate = (el: T, i?: number) => boolean', }, { code: 'type TArrayPredicate = (el:T, i?:number) => boolean', - options: ['never'] + options: ['never'], }, { - code: 'type X = (number) => string;' + code: 'type X = (number) => string;', }, { - code: 'type X = (?number) => string;' + code: 'type X = (?number) => string;', }, { - code: 'type X = number => string;' + code: 'type X = number => string;', }, { - code: 'type X = ?number => string;' + code: 'type X = ?number => string;', }, { - code: 'type X = ({ foo: bar }) => string;' + code: 'type X = ({ foo: bar }) => string;', }, { code: 'type X = (number) => string;', - options: ['always'] + options: ['always'], }, { code: 'type X = (?number) => string;', - options: ['always'] + options: ['always'], }, { code: 'type X = number => string;', - options: ['always'] + options: ['always'], }, { code: 'type X = ?number => string;', - options: ['always'] + options: ['always'], }, { code: 'type X = ({ foo: bar }) => string;', - options: ['always'] - } - ] + options: ['always'], + }, + ], }; const CLASS_PROPERTIES = { @@ -507,152 +507,152 @@ const CLASS_PROPERTIES = { { code: 'class X { foo:string }', errors: [{message: 'There must be a space after "foo" class property type annotation colon.'}], - output: 'class X { foo: string }' + output: 'class X { foo: string }', }, { code: 'class X { foo: string }', errors: [{message: 'There must be no space after "foo" class property type annotation colon.'}], options: ['never'], - output: 'class X { foo:string }' + output: 'class X { foo:string }', }, { code: 'class X { foo:?string }', errors: [{message: 'There must be a space after "foo" class property type annotation colon.'}], - output: 'class X { foo: ?string }' + output: 'class X { foo: ?string }', }, { code: 'class X { foo: ?string }', errors: [{message: 'There must be no space after "foo" class property type annotation colon.'}], options: ['never'], - output: 'class X { foo:?string }' + output: 'class X { foo:?string }', }, { code: 'class X { static foo:number }', errors: [{message: 'There must be a space after "foo" class property type annotation colon.'}], - output: 'class X { static foo: number }' + output: 'class X { static foo: number }', }, { code: 'class X { static foo: number }', errors: [{message: 'There must be no space after "foo" class property type annotation colon.'}], options: ['never'], - output: 'class X { static foo:number }' + output: 'class X { static foo:number }', }, { code: 'class X { static foo :number }', errors: [{message: 'There must be a space after "foo" class property type annotation colon.'}], - output: 'class X { static foo : number }' + output: 'class X { static foo : number }', }, { code: 'class X { static foo : number }', errors: [{message: 'There must be no space after "foo" class property type annotation colon.'}], options: ['never'], - output: 'class X { static foo :number }' + output: 'class X { static foo :number }', }, { code: 'declare class X { static foo:number }', errors: [{message: 'There must be a space after "foo" type annotation colon.'}], - output: 'declare class X { static foo: number }' + output: 'declare class X { static foo: number }', }, { code: 'declare class X { static foo: number }', errors: [{message: 'There must be no space after "foo" type annotation colon.'}], options: ['never'], - output: 'declare class X { static foo:number }' + output: 'declare class X { static foo:number }', }, { code: 'declare class X { static foo :number }', errors: [{message: 'There must be a space after "foo" type annotation colon.'}], - output: 'declare class X { static foo : number }' + output: 'declare class X { static foo : number }', }, { code: 'declare class X { static foo : number }', errors: [{message: 'There must be no space after "foo" type annotation colon.'}], options: ['never'], - output: 'declare class X { static foo :number }' + output: 'declare class X { static foo :number }', }, { code: 'class X { +foo:string }', errors: [{message: 'There must be a space after "foo" class property type annotation colon.'}], - output: 'class X { +foo: string }' + output: 'class X { +foo: string }', }, { code: 'class X { +foo: string }', errors: [{message: 'There must be 1 space after "foo" class property type annotation colon.'}], - output: 'class X { +foo: string }' + output: 'class X { +foo: string }', }, { code: 'class X { +foo: string }', errors: [{message: 'There must be no space after "foo" class property type annotation colon.'}], options: ['never'], - output: 'class X { +foo:string }' + output: 'class X { +foo:string }', }, { code: 'class X { static +foo:string }', errors: [{message: 'There must be a space after "foo" class property type annotation colon.'}], - output: 'class X { static +foo: string }' + output: 'class X { static +foo: string }', }, { code: 'class X { static +foo: string }', errors: [{message: 'There must be 1 space after "foo" class property type annotation colon.'}], - output: 'class X { static +foo: string }' + output: 'class X { static +foo: string }', }, { code: 'class X { static +foo: string }', errors: [{message: 'There must be no space after "foo" class property type annotation colon.'}], options: ['never'], - output: 'class X { static +foo:string }' - } + output: 'class X { static +foo:string }', + }, ], valid: [ { - code: 'class Foo { bar }' + code: 'class Foo { bar }', }, { - code: 'class Foo { bar = 3 }' + code: 'class Foo { bar = 3 }', }, { - code: 'class Foo { bar: string }' + code: 'class Foo { bar: string }', }, { - code: 'class Foo { bar: ?string }' + code: 'class Foo { bar: ?string }', }, { code: 'class Foo { bar:string }', - options: ['never'] + options: ['never'], }, { code: 'class Foo { bar:?string }', - options: ['never'] + options: ['never'], }, { - code: 'class X { static foo : number }' + code: 'class X { static foo : number }', }, { code: 'class X { static foo :number }', - options: ['never'] + options: ['never'], }, { - code: 'declare class X { static foo : number }' + code: 'declare class X { static foo : number }', }, { code: 'declare class X { static foo :number }', - options: ['never'] + options: ['never'], }, { - code: 'class X { +foo: string }' + code: 'class X { +foo: string }', }, { - code: 'class X { static +foo: string }' + code: 'class X { static +foo: string }', }, { code: 'class X { +foo:string }', - options: ['never'] + options: ['never'], }, { code: 'class X { static +foo:string }', - options: ['never'] - } - ] + options: ['never'], + }, + ], }; const OBJECT_TYPE_PROPERTIES = { @@ -660,212 +660,212 @@ const OBJECT_TYPE_PROPERTIES = { { code: 'type X = { foo:string }', errors: [{message: 'There must be a space after "foo" type annotation colon.'}], - output: 'type X = { foo: string }' + output: 'type X = { foo: string }', }, { code: 'type X = { foo:string }', errors: [{message: 'There must be a space after "foo" type annotation colon.'}], options: ['always'], - output: 'type X = { foo: string }' + output: 'type X = { foo: string }', }, { code: 'type X = { foo: string }', errors: [{message: 'There must be no space after "foo" type annotation colon.'}], options: ['never'], - output: 'type X = { foo:string }' + output: 'type X = { foo:string }', }, { code: 'type X = { foo: string }', errors: [{message: 'There must be 1 space after "foo" type annotation colon.'}], - output: 'type X = { foo: string }' + output: 'type X = { foo: string }', }, { code: 'type X = { foo?:string }', errors: [{message: 'There must be a space after "foo" type annotation colon.'}], - output: 'type X = { foo?: string }' + output: 'type X = { foo?: string }', }, { code: 'type X = { foo?: string }', errors: [{message: 'There must be no space after "foo" type annotation colon.'}], options: ['never'], - output: 'type X = { foo?:string }' + output: 'type X = { foo?:string }', }, { code: 'type X = { foo?:?string }', errors: [{message: 'There must be a space after "foo" type annotation colon.'}], - output: 'type X = { foo?: ?string }' + output: 'type X = { foo?: ?string }', }, { code: 'type X = { foo?: ?string }', errors: [{message: 'There must be 1 space after "foo" type annotation colon.'}], - output: 'type X = { foo?: ?string }' + output: 'type X = { foo?: ?string }', }, { code: 'type Foo = { barType:(string | () => void) }', errors: [{message: 'There must be a space after "barType" type annotation colon.'}], - output: 'type Foo = { barType: (string | () => void) }' + output: 'type Foo = { barType: (string | () => void) }', }, { code: 'type Foo = { barType:(((string | () => void))) }', errors: [{message: 'There must be a space after "barType" type annotation colon.'}], - output: 'type Foo = { barType: (((string | () => void))) }' + output: 'type Foo = { barType: (((string | () => void))) }', }, { code: 'type Foo = { barType: (string | () => void) }', errors: [{message: 'There must be no space after "barType" type annotation colon.'}], options: ['never'], - output: 'type Foo = { barType:(string | () => void) }' + output: 'type Foo = { barType:(string | () => void) }', }, { code: 'type Foo = { barType: (string | () => void) }', errors: [{message: 'There must be 1 space after "barType" type annotation colon.'}], - output: 'type Foo = { barType: (string | () => void) }' + output: 'type Foo = { barType: (string | () => void) }', }, { code: 'type Foo = { barType: ((string | () => void)) }', errors: [{message: 'There must be 1 space after "barType" type annotation colon.'}], - output: 'type Foo = { barType: ((string | () => void)) }' + output: 'type Foo = { barType: ((string | () => void)) }', }, { code: 'type X = { get:() => A; }', errors: [{message: 'There must be a space after "get" type annotation colon.'}], - output: 'type X = { get: () => A; }' + output: 'type X = { get: () => A; }', }, { code: 'type X = { get:() => A; }', errors: [{message: 'There must be a space after "get" type annotation colon.'}], - output: 'type X = { get: () => A; }' + output: 'type X = { get: () => A; }', }, { code: 'type X = { get: () => A; }', errors: [{message: 'There must be no space after "get" type annotation colon.'}], options: ['never'], - output: 'type X = { get:() => A; }' + output: 'type X = { get:() => A; }', }, { code: 'type X = { get: () => A; }', errors: [{message: 'There must be no space after "get" type annotation colon.'}], options: ['never'], - output: 'type X = { get:() => A; }' + output: 'type X = { get:() => A; }', }, { code: 'type X = { get: () => A; }', errors: [{message: 'There must be 1 space after "get" type annotation colon.'}], - output: 'type X = { get: () => A; }' + output: 'type X = { get: () => A; }', }, { code: 'type X = { get: () => A; }', errors: [{message: 'There must be 1 space after "get" type annotation colon.'}], - output: 'type X = { get: () => A; }' + output: 'type X = { get: () => A; }', }, { code: 'type X = { +foo:string }', errors: [{message: 'There must be a space after "foo" type annotation colon.'}], - output: 'type X = { +foo: string }' + output: 'type X = { +foo: string }', }, { code: 'type X = { +foo: string }', errors: [{message: 'There must be 1 space after "foo" type annotation colon.'}], - output: 'type X = { +foo: string }' + output: 'type X = { +foo: string }', }, { code: 'type X = { +foo: string }', errors: [{message: 'There must be no space after "foo" type annotation colon.'}], options: ['never'], - output: 'type X = { +foo:string }' + output: 'type X = { +foo:string }', }, { code: 'type X = { +foo?:string }', errors: [{message: 'There must be a space after "foo" type annotation colon.'}], - output: 'type X = { +foo?: string }' + output: 'type X = { +foo?: string }', }, { code: 'type X = { +foo?: string }', errors: [{message: 'There must be 1 space after "foo" type annotation colon.'}], - output: 'type X = { +foo?: string }' + output: 'type X = { +foo?: string }', }, { code: 'type X = { +foo?: string }', errors: [{message: 'There must be no space after "foo" type annotation colon.'}], options: ['never'], - output: 'type X = { +foo?:string }' - } + output: 'type X = { +foo?:string }', + }, ], valid: [ { - code: 'type X = { foo: string }' + code: 'type X = { foo: string }', }, { code: 'type X = { foo:string }', - options: ['never'] + options: ['never'], }, { - code: 'type X = { foo?: string }' + code: 'type X = { foo?: string }', }, { - code: 'type X = { foo?: ?string }' + code: 'type X = { foo?: ?string }', }, { code: 'type X = { foo?:?string }', - options: ['never'] + options: ['never'], }, { - code: 'type Foo = { barType: (string | () => void) }' + code: 'type Foo = { barType: (string | () => void) }', }, { - code: 'type Foo = { barType: ((string | () => void)) }' + code: 'type Foo = { barType: ((string | () => void)) }', }, { code: 'type Foo = { barType:(string | () => void) }', - options: ['never'] + options: ['never'], }, { code: 'type Foo = { barType:((string | () => void)) }', - options: ['never'] + options: ['never'], }, { - code: 'type X = { get(): A; }' + code: 'type X = { get(): A; }', }, { - code: 'type X = { get(): A; }' + code: 'type X = { get(): A; }', }, { code: 'type X = { get(): A; }', - options: ['never'] + options: ['never'], }, { code: 'type X = { get(): A; }', - options: ['never'] + options: ['never'], }, { - code: 'type X = { get: () => A; }' + code: 'type X = { get: () => A; }', }, { - code: 'type X = { get: () => A; }' + code: 'type X = { get: () => A; }', }, { code: 'type X = { get:() => A; }', - options: ['never'] + options: ['never'], }, { code: 'type X = { get:() => A; }', - options: ['never'] + options: ['never'], }, { - code: 'type X = { +foo: string }' + code: 'type X = { +foo: string }', }, { - code: 'type X = { +foo?: string }' + code: 'type X = { +foo?: string }', }, { code: 'type X = { +foo:string }', - options: ['never'] + options: ['never'], }, { code: 'type X = { +foo?:string }', - options: ['never'] - } - ] + options: ['never'], + }, + ], }; const OBJECT_TYPE_INDEXERS = { @@ -876,37 +876,37 @@ const OBJECT_TYPE_INDEXERS = { code: 'type X = { [a:b]: c }', errors: [{message: 'There must be a space after type annotation colon.'}], options: ['always'], - output: 'type X = { [a: b]: c }' + output: 'type X = { [a: b]: c }', }, { code: 'type X = { [a: b]:c }', errors: [{message: 'There must be no space after type annotation colon.'}], options: ['never'], - output: 'type X = { [a:b]:c }' + output: 'type X = { [a:b]:c }', }, { code: 'type X = { [a: b]: c }', errors: [{message: 'There must be 1 space after type annotation colon.'}], options: ['always'], - output: 'type X = { [a: b]: c }' + output: 'type X = { [a: b]: c }', }, { code: 'type X = { +[a:b]: c }', errors: [{message: 'There must be a space after type annotation colon.'}], options: ['always'], - output: 'type X = { +[a: b]: c }' + output: 'type X = { +[a: b]: c }', }, { code: 'type X = { +[a: b]:c }', errors: [{message: 'There must be no space after type annotation colon.'}], options: ['never'], - output: 'type X = { +[a:b]:c }' + output: 'type X = { +[a:b]:c }', }, { code: 'type X = { +[a: b]: c }', errors: [{message: 'There must be 1 space after type annotation colon.'}], options: ['always'], - output: 'type X = { +[a: b]: c }' + output: 'type X = { +[a: b]: c }', }, // [id:key]: value @@ -915,19 +915,19 @@ const OBJECT_TYPE_INDEXERS = { code: 'type X = { [a: b]:c }', errors: [{message: 'There must be a space after type annotation colon.'}], options: ['always'], - output: 'type X = { [a: b]: c }' + output: 'type X = { [a: b]: c }', }, { code: 'type X = { [a:b]: c }', errors: [{message: 'There must be no space after type annotation colon.'}], options: ['never'], - output: 'type X = { [a:b]:c }' + output: 'type X = { [a:b]:c }', }, { code: 'type X = { [a: b]: c }', errors: [{message: 'There must be 1 space after type annotation colon.'}], options: ['always'], - output: 'type X = { [a: b]: c }' + output: 'type X = { [a: b]: c }', }, // [id:key]: value @@ -936,74 +936,74 @@ const OBJECT_TYPE_INDEXERS = { code: 'type X = { [a:b]:c }', errors: [ {message: 'There must be a space after type annotation colon.'}, - {message: 'There must be a space after type annotation colon.'} + {message: 'There must be a space after type annotation colon.'}, ], options: ['always'], - output: 'type X = { [a: b]: c }' + output: 'type X = { [a: b]: c }', }, { code: 'type X = { [a: b]: c }', errors: [ {message: 'There must be no space after type annotation colon.'}, - {message: 'There must be no space after type annotation colon.'} + {message: 'There must be no space after type annotation colon.'}, ], options: ['never'], - output: 'type X = { [a:b]:c }' + output: 'type X = { [a:b]:c }', }, { code: 'type X = { [a: b]: c }', errors: [ {message: 'There must be 1 space after type annotation colon.'}, - {message: 'There must be 1 space after type annotation colon.'} + {message: 'There must be 1 space after type annotation colon.'}, ], options: ['always'], - output: 'type X = { [a: b]: c }' + output: 'type X = { [a: b]: c }', }, { code: 'type X = { [a:(b)]:(c) }', errors: [ {message: 'There must be a space after type annotation colon.'}, - {message: 'There must be a space after type annotation colon.'} + {message: 'There must be a space after type annotation colon.'}, ], options: ['always'], - output: 'type X = { [a: (b)]: (c) }' + output: 'type X = { [a: (b)]: (c) }', }, { code: 'type X = { [a: (b)]: (c) }', errors: [ {message: 'There must be no space after type annotation colon.'}, - {message: 'There must be no space after type annotation colon.'} + {message: 'There must be no space after type annotation colon.'}, ], options: ['never'], - output: 'type X = { [a:(b)]:(c) }' - } + output: 'type X = { [a:(b)]:(c) }', + }, ], valid: [ { code: 'type X = { [a: b]: c }', - options: ['always'] + options: ['always'], }, { code: 'type X = { [a:b]:c }', - options: ['never'] + options: ['never'], }, { code: 'type X = { +[a: b]: c }', - options: ['always'] + options: ['always'], }, { code: 'type X = { +[a:b]:c }', - options: ['never'] + options: ['never'], }, { code: 'type X = { [string]: c }', - options: ['always'] + options: ['always'], }, { code: 'type X = { [string]:c }', - options: ['never'] - } - ] + options: ['never'], + }, + ], }; const TYPE_CAST_EXPRESSIONS = { @@ -1012,57 +1012,57 @@ const TYPE_CAST_EXPRESSIONS = { code: 'const x = ({}: {})', errors: [{message: 'There must be no space after type cast colon.'}], options: ['never'], - output: 'const x = ({}:{})' + output: 'const x = ({}:{})', }, { code: 'const x = ({}:{})', errors: [{message: 'There must be a space after type cast colon.'}], options: ['always'], - output: 'const x = ({}: {})' + output: 'const x = ({}: {})', }, { code: 'const x = ({}: {})', errors: [{message: 'There must be 1 space after type cast colon.'}], options: ['always'], - output: 'const x = ({}: {})' + output: 'const x = ({}: {})', }, { code: '((x): (string))', errors: [{message: 'There must be no space after type cast colon.'}], options: ['never'], - output: '((x):(string))' + output: '((x):(string))', }, { code: '((x):(string))', errors: [{message: 'There must be a space after type cast colon.'}], options: ['always'], - output: '((x): (string))' + output: '((x): (string))', }, { code: '((x): (string))', errors: [{message: 'There must be 1 space after type cast colon.'}], options: ['always'], - output: '((x): (string))' - } + output: '((x): (string))', + }, ], valid: [ { code: 'const x = ({}:{})', - options: ['never'] + options: ['never'], }, { code: 'const x = ({}: {})', - options: ['always'] + options: ['always'], }, { code: '((x):(string))', - options: ['never'] + options: ['never'], }, { code: '((x): (string))', - options: ['always'] - } - ] + options: ['always'], + }, + ], }; const VARIABLE_EXPRESSIONS = { @@ -1071,35 +1071,35 @@ const VARIABLE_EXPRESSIONS = { code: 'const x:number = 7;', errors: [{message: 'There must be a space after const type annotation colon.'}], options: ['always'], - output: 'const x: number = 7;' + output: 'const x: number = 7;', }, { code: 'let x:number = 42;', errors: [{message: 'There must be a space after let type annotation colon.'}], options: ['always'], - output: 'let x: number = 42;' + output: 'let x: number = 42;', }, { code: 'var x:number = 42;', errors: [{message: 'There must be a space after var type annotation colon.'}], options: ['always'], - output: 'var x: number = 42;' - } + output: 'var x: number = 42;', + }, ], valid: [ { code: 'const x: number = 7;', - options: ['always'] + options: ['always'], }, { code: 'let x: number = 42;', - options: ['always'] + options: ['always'], }, { code: 'var x: number = 42;', - options: ['always'] - } - ] + options: ['always'], + }, + ], }; const ALL = [ @@ -1112,7 +1112,7 @@ const ALL = [ OBJECT_TYPE_PROPERTIES, OBJECT_TYPE_INDEXERS, TYPE_CAST_EXPRESSIONS, - VARIABLE_EXPRESSIONS + VARIABLE_EXPRESSIONS, ]; const MISCONFIGURED = [ @@ -1126,51 +1126,51 @@ const MISCONFIGURED = [ params: { allowedValues: [ 'always', - 'never' - ] + 'never', + ], }, parentSchema: { enum: [ 'always', - 'never' + 'never', ], - type: 'string' + type: 'string', }, schema: [ 'always', - 'never' + 'never', ], - schemaPath: '#/items/0/enum' - } + schemaPath: '#/items/0/enum', + }, ], - options: ['from time to time'] + options: ['from time to time'], }, { errors: [ { data: { - allowEmoji: true + allowEmoji: true, }, dataPath: '[1]', keyword: 'additionalProperties', message: 'should NOT have additional properties', params: { - additionalProperty: 'allowEmoji' + additionalProperty: 'allowEmoji', }, parentSchema: { additionalProperties: false, properties: { allowLineBreak: { - type: 'boolean' - } + type: 'boolean', + }, }, - type: 'object' + type: 'object', }, schema: false, - schemaPath: '#/items/1/additionalProperties' - } + schemaPath: '#/items/1/additionalProperties', + }, ], - options: ['always', {allowEmoji: true}] + options: ['always', {allowEmoji: true}], }, { errors: [ @@ -1180,17 +1180,17 @@ const MISCONFIGURED = [ keyword: 'type', message: 'should be boolean', params: { - type: 'boolean' + type: 'boolean', }, parentSchema: { - type: 'boolean' + type: 'boolean', }, schema: 'boolean', - schemaPath: '#/items/1/properties/allowLineBreak/type' - } + schemaPath: '#/items/1/properties/allowLineBreak/type', + }, ], - options: ['always', {allowLineBreak: 'why not?'}] - } + options: ['always', {allowLineBreak: 'why not?'}], + }, ]; export default { @@ -1200,5 +1200,5 @@ export default { misconfigured: MISCONFIGURED, valid: _.flatMap(ALL, (rules) => { return rules.valid; - }) + }), }; diff --git a/tests/rules/assertions/spaceBeforeGenericBracket.js b/tests/rules/assertions/spaceBeforeGenericBracket.js index 633a6293..ee23073e 100644 --- a/tests/rules/assertions/spaceBeforeGenericBracket.js +++ b/tests/rules/assertions/spaceBeforeGenericBracket.js @@ -3,31 +3,31 @@ export default { { code: 'type X = Promise ', errors: [{message: 'There must be no space before "Promise" generic type annotation bracket'}], - output: 'type X = Promise' + output: 'type X = Promise', }, { code: 'type X = Promise ', errors: [{message: 'There must be no space before "Promise" generic type annotation bracket'}], options: ['never'], - output: 'type X = Promise' + output: 'type X = Promise', }, { code: 'type X = Promise ', errors: [{message: 'There must be no space before "Promise" generic type annotation bracket'}], - output: 'type X = Promise' + output: 'type X = Promise', }, { code: 'type X = Promise', errors: [{message: 'There must be a space before "Promise" generic type annotation bracket'}], options: ['always'], - output: 'type X = Promise ' + output: 'type X = Promise ', }, { code: 'type X = Promise ', errors: [{message: 'There must be one space before "Promise" generic type annotation bracket'}], options: ['always'], - output: 'type X = Promise ' - } + output: 'type X = Promise ', + }, ], misconfigured: [ { @@ -40,33 +40,33 @@ export default { params: { allowedValues: [ 'always', - 'never' - ] + 'never', + ], }, parentSchema: { enum: [ 'always', - 'never' + 'never', ], - type: 'string' + type: 'string', }, schema: [ 'always', - 'never' + 'never', ], - schemaPath: '#/items/0/enum' - } + schemaPath: '#/items/0/enum', + }, ], - options: ['whenever'] - } + options: ['whenever'], + }, ], valid: [ { - code: 'type X = Promise' + code: 'type X = Promise', }, { code: 'type X = Promise ', - options: ['always'] - } - ] + options: ['always'], + }, + ], }; diff --git a/tests/rules/assertions/spaceBeforeTypeColon.js b/tests/rules/assertions/spaceBeforeTypeColon.js index 82967c32..a5c40936 100644 --- a/tests/rules/assertions/spaceBeforeTypeColon.js +++ b/tests/rules/assertions/spaceBeforeTypeColon.js @@ -6,118 +6,118 @@ const ARROW_FUNCTION_PARAMS = { code: '(foo : string) => {}', errors: [{message: 'There must be no space before "foo" parameter type annotation colon.'}], options: ['never'], - output: '(foo: string) => {}' + output: '(foo: string) => {}', }, { code: '(foo ? : string) => {}', errors: [{message: 'There must be no space before "foo" parameter type annotation colon.'}], options: ['never'], - output: '(foo ?: string) => {}' + output: '(foo ?: string) => {}', }, { code: '(foo: string) => {}', errors: [{message: 'There must be a space before "foo" parameter type annotation colon.'}], options: ['always'], - output: '(foo : string) => {}' + output: '(foo : string) => {}', }, { code: '(foo : string) => {}', errors: [{message: 'There must be 1 space before "foo" parameter type annotation colon.'}], options: ['always'], - output: '(foo : string) => {}' + output: '(foo : string) => {}', }, { code: '(foo?: string) => {}', errors: [{message: 'There must be a space before "foo" parameter type annotation colon.'}], options: ['always'], - output: '(foo? : string) => {}' + output: '(foo? : string) => {}', }, { code: '(foo ? : string) => {}', errors: [{message: 'There must be 1 space before "foo" parameter type annotation colon.'}], options: ['always'], - output: '(foo ? : string) => {}' + output: '(foo ? : string) => {}', }, { code: '(foo ?: string) => {}', errors: [{message: 'There must be a space before "foo" parameter type annotation colon.'}], options: ['always'], - output: '(foo ? : string) => {}' + output: '(foo ? : string) => {}', }, { code: '({ lorem, ipsum, dolor } : SomeType) => {}', errors: [{message: 'There must be no space before "{ lorem, ipsum, dolor }" parameter type annotation colon.'}], - output: '({ lorem, ipsum, dolor }: SomeType) => {}' + output: '({ lorem, ipsum, dolor }: SomeType) => {}', }, { code: '(foo : { a: string, b: number }) => {}', errors: [{message: 'There must be no space before "foo" parameter type annotation colon.'}], - output: '(foo: { a: string, b: number }) => {}' + output: '(foo: { a: string, b: number }) => {}', }, { code: '({ a, b } : { a: string, b: number }) => {}', errors: [{message: 'There must be no space before "{ a, b }" parameter type annotation colon.'}], - output: '({ a, b }: { a: string, b: number }) => {}' + output: '({ a, b }: { a: string, b: number }) => {}', }, { code: '([ a, b ] : string[]) => {}', errors: [{message: 'There must be no space before "[ a, b ]" parameter type annotation colon.'}], - output: '([ a, b ]: string[]) => {}' - } + output: '([ a, b ]: string[]) => {}', + }, ], valid: [ { - code: '(foo) => {}' + code: '(foo) => {}', }, { - code: '(foo: string) => {}' + code: '(foo: string) => {}', }, { - code: '(foo?: string) => {}' + code: '(foo?: string) => {}', }, { - code: '(foo ?: string) => {}' + code: '(foo ?: string) => {}', }, { code: '(foo: string) => {}', - options: ['never'] + options: ['never'], }, { code: '(foo : string) => {}', - options: ['always'] + options: ['always'], }, { code: '(foo? : string) => {}', - options: ['always'] + options: ['always'], }, { code: '(foo ? : string) => {}', - options: ['always'] + options: ['always'], }, { code: '(foo ? : string) => {}', - options: ['always'] + options: ['always'], }, { - code: '({ lorem, ipsum, dolor }: SomeType) => {}' + code: '({ lorem, ipsum, dolor }: SomeType) => {}', }, { - code: '(foo: { a: string, b: number }) => {}' + code: '(foo: { a: string, b: number }) => {}', }, { - code: '({ a, b }: ?{ a: string, b: number }) => {}' + code: '({ a, b }: ?{ a: string, b: number }) => {}', }, { - code: '(): { a: number, b: string } => {}' + code: '(): { a: number, b: string } => {}', }, { code: '() : { a : number, b : string } => {}', - options: ['always'] + options: ['always'], }, { - code: '([ a, b ]: string[]) => {}' - } - ] + code: '([ a, b ]: string[]) => {}', + }, + ], }; const ARROW_FUNCTION_RETURN = { @@ -125,37 +125,37 @@ const ARROW_FUNCTION_RETURN = { { code: '() : x => {}', errors: [{message: 'There must be no space before return type colon.'}], - output: '(): x => {}' + output: '(): x => {}', }, { code: '(): x => {}', errors: [{message: 'There must be a space before return type colon.'}], options: ['always'], - output: '() : x => {}' + output: '() : x => {}', }, { code: '() : x => {}', errors: [{message: 'There must be 1 space before return type colon.'}], options: ['always'], - output: '() : x => {}' - } + output: '() : x => {}', + }, ], valid: [ { - code: '(): x => {}' + code: '(): x => {}', }, { code: '() : x => {}', - options: ['always'] + options: ['always'], }, { - code: '(): (number | string) => {}' + code: '(): (number | string) => {}', }, { code: '() : (number | string) => {}', - options: ['always'] - } - ] + options: ['always'], + }, + ], }; const FUNCTION_PARAMS = { @@ -163,74 +163,74 @@ const FUNCTION_PARAMS = { { code: 'function x(foo : string) {}', errors: [{message: 'There must be no space before "foo" parameter type annotation colon.'}], - output: 'function x(foo: string) {}' + output: 'function x(foo: string) {}', }, { code: 'function x(foo: string) {}', errors: [{message: 'There must be a space before "foo" parameter type annotation colon.'}], options: ['always'], - output: 'function x(foo : string) {}' + output: 'function x(foo : string) {}', }, { code: 'var x = function (foo : string) {}', errors: [{message: 'There must be no space before "foo" parameter type annotation colon.'}], - output: 'var x = function (foo: string) {}' + output: 'var x = function (foo: string) {}', }, { code: 'var x = function (foo: string) {}', errors: [{message: 'There must be a space before "foo" parameter type annotation colon.'}], options: ['always'], - output: 'var x = function (foo : string) {}' + output: 'var x = function (foo : string) {}', }, { code: 'class Foo { constructor(foo : string ) {} }', errors: [{message: 'There must be no space before "foo" parameter type annotation colon.'}], - output: 'class Foo { constructor(foo: string ) {} }' + output: 'class Foo { constructor(foo: string ) {} }', }, { code: 'class Foo { constructor(foo: string ) {} }', errors: [{message: 'There must be a space before "foo" parameter type annotation colon.'}], options: ['always'], - output: 'class Foo { constructor(foo : string ) {} }' + output: 'class Foo { constructor(foo : string ) {} }', }, { code: 'async function foo({ lorem, ipsum, dolor } : SomeType) {}', errors: [{message: 'There must be no space before "{ lorem, ipsum, dolor }" parameter type annotation colon.'}], - output: 'async function foo({ lorem, ipsum, dolor }: SomeType) {}' - } + output: 'async function foo({ lorem, ipsum, dolor }: SomeType) {}', + }, ], valid: [ { - code: 'function x(foo: string) {}' + code: 'function x(foo: string) {}', }, { code: 'function x(foo : string) {}', - options: ['always'] + options: ['always'], }, { - code: 'var x = function (foo: string) {}' + code: 'var x = function (foo: string) {}', }, { code: 'var x = function (foo : string) {}', - options: ['always'] + options: ['always'], }, { - code: 'class X { foo({ bar }: Props = this.props) {} }' + code: 'class X { foo({ bar }: Props = this.props) {} }', }, { - code: 'class Foo { constructor(foo: string ) {} }' + code: 'class Foo { constructor(foo: string ) {} }', }, { code: 'class Foo { constructor(foo : string ) {} }', - options: ['always'] + options: ['always'], }, { - code: 'async function foo({ lorem, ipsum, dolor }: SomeType) {}' + code: 'async function foo({ lorem, ipsum, dolor }: SomeType) {}', }, { - code: 'function x({ a, b }: { a: string, b: number }) {}' - } - ] + code: 'function x({ a, b }: { a: string, b: number }) {}', + }, + ], }; const FUNCTION_RETURN = { @@ -238,37 +238,37 @@ const FUNCTION_RETURN = { { code: 'function a() : x {}', errors: [{message: 'There must be no space before return type colon.'}], - output: 'function a(): x {}' + output: 'function a(): x {}', }, { code: 'function a(): x {}', errors: [{message: 'There must be a space before return type colon.'}], options: ['always'], - output: 'function a() : x {}' + output: 'function a() : x {}', }, { code: 'function a() : x {}', errors: [{message: 'There must be 1 space before return type colon.'}], options: ['always'], - output: 'function a() : x {}' - } + output: 'function a() : x {}', + }, ], valid: [ { - code: 'function a(): x {}' + code: 'function a(): x {}', }, { code: 'function a() : x {}', - options: ['always'] + options: ['always'], }, { - code: 'function a(): (number | string) {}' + code: 'function a(): (number | string) {}', }, { code: 'function a() : (number | string) {}', - options: ['always'] - } - ] + options: ['always'], + }, + ], }; const FUNCTION_TYPE_PARAMS = { @@ -276,105 +276,105 @@ const FUNCTION_TYPE_PARAMS = { { code: 'type X = (foo :string) => string;', errors: [{message: 'There must be no space before "foo" parameter type annotation colon.'}], - output: 'type X = (foo:string) => string;' + output: 'type X = (foo:string) => string;', }, { code: 'type X = (foo:string) => string;', errors: [{message: 'There must be a space before "foo" parameter type annotation colon.'}], options: ['always'], - output: 'type X = (foo :string) => string;' + output: 'type X = (foo :string) => string;', }, { code: 'type X = (foo :string) => string;', errors: [{message: 'There must be 1 space before "foo" parameter type annotation colon.'}], options: ['always'], - output: 'type X = (foo :string) => string;' + output: 'type X = (foo :string) => string;', }, { code: 'type X = (foo? :string) => string;', errors: [{message: 'There must be no space before "foo" parameter type annotation colon.'}], - output: 'type X = (foo?:string) => string;' + output: 'type X = (foo?:string) => string;', }, { code: 'type X = (foo? :string) => string;', errors: [{message: 'There must be no space before "foo" parameter type annotation colon.'}], - output: 'type X = (foo?:string) => string;' + output: 'type X = (foo?:string) => string;', }, { code: 'type X = (foo?:string) => string;', errors: [{message: 'There must be a space before "foo" parameter type annotation colon.'}], options: ['always'], - output: 'type X = (foo? :string) => string;' + output: 'type X = (foo? :string) => string;', }, { code: 'type X = (foo? :?string) => string;', errors: [{message: 'There must be no space before "foo" parameter type annotation colon.'}], - output: 'type X = (foo?:?string) => string;' - } + output: 'type X = (foo?:?string) => string;', + }, ], valid: [ { - code: 'type X = (foo:string) => number;' + code: 'type X = (foo:string) => number;', }, { - code: 'type X = (foo: string) => number;' + code: 'type X = (foo: string) => number;', }, { - code: 'type X = (foo: ?string) => number;' + code: 'type X = (foo: ?string) => number;', }, { - code: 'type X = (foo?: string) => number;' + code: 'type X = (foo?: string) => number;', }, { - code: 'type X = (foo?: ?string) => number;' + code: 'type X = (foo?: ?string) => number;', }, { - code: 'type X = (foo ?: string) => number;' + code: 'type X = (foo ?: string) => number;', }, { code: 'type X = (foo? : string) => number', - options: ['always'] + options: ['always'], }, { code: 'type X = (foo? : ?string) => number', - options: ['always'] + options: ['always'], }, { - code: 'type X = (number) => string;' + code: 'type X = (number) => string;', }, { - code: 'type X = (?number) => string;' + code: 'type X = (?number) => string;', }, { - code: 'type X = number => string;' + code: 'type X = number => string;', }, { - code: 'type X = ?number => string;' + code: 'type X = ?number => string;', }, { - code: 'type X = ({ foo: bar }) => string;' + code: 'type X = ({ foo: bar }) => string;', }, { code: 'type X = (number) => string;', - options: ['always'] + options: ['always'], }, { code: 'type X = (?number) => string;', - options: ['always'] + options: ['always'], }, { code: 'type X = number => string;', - options: ['always'] + options: ['always'], }, { code: 'type X = ?number => string;', - options: ['always'] + options: ['always'], }, { code: 'type X = ({ foo : bar }) => string;', - options: ['always'] - } - ] + options: ['always'], + }, + ], }; const CLASS_PROPERTIES = { @@ -382,169 +382,169 @@ const CLASS_PROPERTIES = { { code: 'class X { foo :string }', errors: [{message: 'There must be no space before "foo" class property type annotation colon.'}], - output: 'class X { foo:string }' + output: 'class X { foo:string }', }, { code: 'class X { foo: string }', errors: [{message: 'There must be a space before "foo" class property type annotation colon.'}], options: ['always'], - output: 'class X { foo : string }' + output: 'class X { foo : string }', }, { code: 'class X { foo :?string }', errors: [{message: 'There must be no space before "foo" class property type annotation colon.'}], - output: 'class X { foo:?string }' + output: 'class X { foo:?string }', }, { code: 'class X { foo: ?string }', errors: [{message: 'There must be a space before "foo" class property type annotation colon.'}], options: ['always'], - output: 'class X { foo : ?string }' + output: 'class X { foo : ?string }', }, { code: 'class X { static foo : number }', errors: [{message: 'There must be no space before "foo" class property type annotation colon.'}], - output: 'class X { static foo: number }' + output: 'class X { static foo: number }', }, { code: 'class X { static foo :number }', errors: [{message: 'There must be no space before "foo" class property type annotation colon.'}], - output: 'class X { static foo:number }' + output: 'class X { static foo:number }', }, { code: 'class X { static foo: number }', errors: [{message: 'There must be a space before "foo" class property type annotation colon.'}], options: ['always'], - output: 'class X { static foo : number }' + output: 'class X { static foo : number }', }, { code: 'class X { static foo:number }', errors: [{message: 'There must be a space before "foo" class property type annotation colon.'}], options: ['always'], - output: 'class X { static foo :number }' + output: 'class X { static foo :number }', }, { code: 'declare class Foo { static bar :number; }', errors: [{message: 'There must be no space before "bar" type annotation colon.'}], - output: 'declare class Foo { static bar:number; }' + output: 'declare class Foo { static bar:number; }', }, { code: 'declare class Foo { static bar : number; }', errors: [{message: 'There must be no space before "bar" type annotation colon.'}], - output: 'declare class Foo { static bar: number; }' + output: 'declare class Foo { static bar: number; }', }, { code: 'declare class Foo { static bar:number; }', errors: [{message: 'There must be a space before "bar" type annotation colon.'}], options: ['always'], - output: 'declare class Foo { static bar :number; }' + output: 'declare class Foo { static bar :number; }', }, { code: 'declare class Foo { static bar: number; }', errors: [{message: 'There must be a space before "bar" type annotation colon.'}], options: ['always'], - output: 'declare class Foo { static bar : number; }' + output: 'declare class Foo { static bar : number; }', }, { code: 'class X { +foo: string }', errors: [{message: 'There must be a space before "foo" class property type annotation colon.'}], options: ['always'], - output: 'class X { +foo : string }' + output: 'class X { +foo : string }', }, { code: 'class X { +foo : string }', errors: [{message: 'There must be 1 space before "foo" class property type annotation colon.'}], options: ['always'], - output: 'class X { +foo : string }' + output: 'class X { +foo : string }', }, { code: 'class X { +foo : string }', errors: [{message: 'There must be no space before "foo" class property type annotation colon.'}], options: ['never'], - output: 'class X { +foo: string }' + output: 'class X { +foo: string }', }, { code: 'class X { static +foo: string }', errors: [{message: 'There must be a space before "foo" class property type annotation colon.'}], options: ['always'], - output: 'class X { static +foo : string }' + output: 'class X { static +foo : string }', }, { code: 'class X { static +foo : string }', errors: [{message: 'There must be 1 space before "foo" class property type annotation colon.'}], options: ['always'], - output: 'class X { static +foo : string }' + output: 'class X { static +foo : string }', }, { code: 'class X { static +foo : string }', errors: [{message: 'There must be no space before "foo" class property type annotation colon.'}], options: ['never'], - output: 'class X { static +foo: string }' - } + output: 'class X { static +foo: string }', + }, ], valid: [ { - code: 'class Foo { bar }' + code: 'class Foo { bar }', }, { - code: 'class Foo { bar = 3 }' + code: 'class Foo { bar = 3 }', }, { - code: 'class Foo { bar: string }' + code: 'class Foo { bar: string }', }, { - code: 'class Foo { bar: ?string }' + code: 'class Foo { bar: ?string }', }, { - code: 'class Foo { bar:?string }' + code: 'class Foo { bar:?string }', }, { code: 'class Foo { bar : string }', - options: ['always'] + options: ['always'], }, { - code: 'class X { static foo:number }' + code: 'class X { static foo:number }', }, { - code: 'class X { static foo: number }' + code: 'class X { static foo: number }', }, { code: 'class X { static foo :number }', - options: ['always'] + options: ['always'], }, { code: 'class X { static foo : number }', - options: ['always'] + options: ['always'], }, { - code: 'declare class Foo { static bar:number; }' + code: 'declare class Foo { static bar:number; }', }, { code: 'declare class Foo { static bar :number; }', - options: ['always'] + options: ['always'], }, { - code: 'declare class Foo { static bar: number; }' + code: 'declare class Foo { static bar: number; }', }, { code: 'declare class Foo { static bar : number; }', - options: ['always'] + options: ['always'], }, { - code: 'class X { +foo: string }' + code: 'class X { +foo: string }', }, { - code: 'class X { static +foo: string }' + code: 'class X { static +foo: string }', }, { code: 'class X { +foo : string }', - options: ['always'] + options: ['always'], }, { code: 'class X { static +foo : string }', - options: ['always'] - } - ] + options: ['always'], + }, + ], }; const OBJECT_TYPE_PROPERTIES = { @@ -552,119 +552,119 @@ const OBJECT_TYPE_PROPERTIES = { { code: 'type X = { foo : string }', errors: [{message: 'There must be no space before "foo" type annotation colon.'}], - output: 'type X = { foo: string }' + output: 'type X = { foo: string }', }, { code: 'type X = { foo : string }', errors: [{message: 'There must be no space before "foo" type annotation colon.'}], options: ['never'], - output: 'type X = { foo: string }' + output: 'type X = { foo: string }', }, { code: 'type X = { foo: string }', errors: [{message: 'There must be a space before "foo" type annotation colon.'}], options: ['always'], - output: 'type X = { foo : string }' + output: 'type X = { foo : string }', }, { code: 'type X = { foo : string }', errors: [{message: 'There must be 1 space before "foo" type annotation colon.'}], options: ['always'], - output: 'type X = { foo : string }' + output: 'type X = { foo : string }', }, { code: 'type X = { foo? : string }', errors: [{message: 'There must be no space before "foo" type annotation colon.'}], - output: 'type X = { foo?: string }' + output: 'type X = { foo?: string }', }, { code: 'type X = { foo?: string }', errors: [{message: 'There must be a space before "foo" type annotation colon.'}], options: ['always'], - output: 'type X = { foo? : string }' + output: 'type X = { foo? : string }', }, { code: 'type X = { foo? : string }', errors: [{message: 'There must be 1 space before "foo" type annotation colon.'}], options: ['always'], - output: 'type X = { foo? : string }' + output: 'type X = { foo? : string }', }, { code: 'type X = { foo ?: string }', errors: [{message: 'There must be a space before "foo" type annotation colon.'}], options: ['always'], - output: 'type X = { foo ? : string }' + output: 'type X = { foo ? : string }', }, { code: 'type X = { +foo: string }', errors: [{message: 'There must be a space before "foo" type annotation colon.'}], options: ['always'], - output: 'type X = { +foo : string }' + output: 'type X = { +foo : string }', }, { code: 'type X = { +foo : string }', errors: [{message: 'There must be 1 space before "foo" type annotation colon.'}], options: ['always'], - output: 'type X = { +foo : string }' + output: 'type X = { +foo : string }', }, { code: 'type X = { +foo : string }', errors: [{message: 'There must be no space before "foo" type annotation colon.'}], options: ['never'], - output: 'type X = { +foo: string }' + output: 'type X = { +foo: string }', }, { code: 'type X = { +foo?: string }', errors: [{message: 'There must be a space before "foo" type annotation colon.'}], options: ['always'], - output: 'type X = { +foo? : string }' + output: 'type X = { +foo? : string }', }, { code: 'type X = { +foo? : string }', errors: [{message: 'There must be 1 space before "foo" type annotation colon.'}], options: ['always'], - output: 'type X = { +foo? : string }' + output: 'type X = { +foo? : string }', }, { code: 'type X = { +foo? : string }', errors: [{message: 'There must be no space before "foo" type annotation colon.'}], options: ['never'], - output: 'type X = { +foo?: string }' - } + output: 'type X = { +foo?: string }', + }, ], valid: [ { - code: 'type X = { foo: string }' + code: 'type X = { foo: string }', }, { code: 'type X = { foo : string }', - options: ['always'] + options: ['always'], }, { - code: 'type X = { foo?: string }' + code: 'type X = { foo?: string }', }, { - code: 'type X = { foo ?: string }' + code: 'type X = { foo ?: string }', }, { code: 'type X = { foo? : string }', - options: ['always'] + options: ['always'], }, { - code: 'type X = { +foo: string }' + code: 'type X = { +foo: string }', }, { - code: 'type X = { +foo?: string }' + code: 'type X = { +foo?: string }', }, { code: 'type X = { +foo : string }', - options: ['always'] + options: ['always'], }, { code: 'type X = { +foo? : string }', - options: ['always'] - } - ] + options: ['always'], + }, + ], }; const OBJECT_TYPE_INDEXERS = { @@ -675,37 +675,37 @@ const OBJECT_TYPE_INDEXERS = { code: 'type X = { [a: b] : c }', errors: [{message: 'There must be a space before type annotation colon.'}], options: ['always'], - output: 'type X = { [a : b] : c }' + output: 'type X = { [a : b] : c }', }, { code: 'type X = { [a : b]: c }', errors: [{message: 'There must be no space before type annotation colon.'}], options: ['never'], - output: 'type X = { [a: b]: c }' + output: 'type X = { [a: b]: c }', }, { code: 'type X = { [a : b] : c }', errors: [{message: 'There must be 1 space before type annotation colon.'}], options: ['always'], - output: 'type X = { [a : b] : c }' + output: 'type X = { [a : b] : c }', }, { code: 'type X = { +[a:b] : c }', errors: [{message: 'There must be a space before type annotation colon.'}], options: ['always'], - output: 'type X = { +[a :b] : c }' + output: 'type X = { +[a :b] : c }', }, { code: 'type X = { +[a : b]: c }', errors: [{message: 'There must be no space before type annotation colon.'}], options: ['never'], - output: 'type X = { +[a: b]: c }' + output: 'type X = { +[a: b]: c }', }, { code: 'type X = { +[a : b] : c }', errors: [{message: 'There must be 1 space before type annotation colon.'}], options: ['always'], - output: 'type X = { +[a : b] : c }' + output: 'type X = { +[a : b] : c }', }, // [id:key]: value @@ -714,19 +714,19 @@ const OBJECT_TYPE_INDEXERS = { code: 'type X = { [a : b]: c }', errors: [{message: 'There must be a space before type annotation colon.'}], options: ['always'], - output: 'type X = { [a : b] : c }' + output: 'type X = { [a : b] : c }', }, { code: 'type X = { [a: b] : c }', errors: [{message: 'There must be no space before type annotation colon.'}], options: ['never'], - output: 'type X = { [a: b]: c }' + output: 'type X = { [a: b]: c }', }, { code: 'type X = { [a : b] : c }', errors: [{message: 'There must be 1 space before type annotation colon.'}], options: ['always'], - output: 'type X = { [a : b] : c }' + output: 'type X = { [a : b] : c }', }, // [id:key]: value @@ -735,82 +735,82 @@ const OBJECT_TYPE_INDEXERS = { code: 'type X = { [a:b]:c }', errors: [ {message: 'There must be a space before type annotation colon.'}, - {message: 'There must be a space before type annotation colon.'} + {message: 'There must be a space before type annotation colon.'}, ], options: ['always'], - output: 'type X = { [a :b] :c }' + output: 'type X = { [a :b] :c }', }, { code: 'type X = { [a : b] : c }', errors: [ {message: 'There must be no space before type annotation colon.'}, - {message: 'There must be no space before type annotation colon.'} + {message: 'There must be no space before type annotation colon.'}, ], options: ['never'], - output: 'type X = { [a: b]: c }' + output: 'type X = { [a: b]: c }', }, { code: 'type X = { [a : b] : c }', errors: [ {message: 'There must be 1 space before type annotation colon.'}, - {message: 'There must be 1 space before type annotation colon.'} + {message: 'There must be 1 space before type annotation colon.'}, ], options: ['always'], - output: 'type X = { [a : b] : c }' + output: 'type X = { [a : b] : c }', }, { code: 'type X = { [a:(b)]:(c) }', errors: [ {message: 'There must be a space before type annotation colon.'}, - {message: 'There must be a space before type annotation colon.'} + {message: 'There must be a space before type annotation colon.'}, ], options: ['always'], - output: 'type X = { [a :(b)] :(c) }' + output: 'type X = { [a :(b)] :(c) }', }, { code: 'type X = { [a : (b)] : (c) }', errors: [ {message: 'There must be no space before type annotation colon.'}, - {message: 'There must be no space before type annotation colon.'} + {message: 'There must be no space before type annotation colon.'}, ], options: ['never'], - output: 'type X = { [a: (b)]: (c) }' - } + output: 'type X = { [a: (b)]: (c) }', + }, ], valid: [ { code: 'type X = { [a : b] : c }', - options: ['always'] + options: ['always'], }, { code: 'type X = { [a:b]:c }', - options: ['never'] + options: ['never'], }, { code: 'type X = { [string] : c }', - options: ['always'] + options: ['always'], }, { code: 'type X = { [string]:c }', - options: ['never'] + options: ['never'], }, { code: 'type X = { +[a : b] : c }', - options: ['always'] + options: ['always'], }, { code: 'type X = { +[a:b]:c }', - options: ['never'] + options: ['never'], }, { code: 'type X = { [a : (b)] : (c) }', - options: ['always'] + options: ['always'], }, { code: 'type X = { [a:(b)]:(c) }', - options: ['never'] - } - ] + options: ['never'], + }, + ], }; const TYPE_CAST_EXPRESSIONS = { @@ -819,57 +819,57 @@ const TYPE_CAST_EXPRESSIONS = { code: 'const x = ({} :{})', errors: [{message: 'There must be no space before type cast colon.'}], options: ['never'], - output: 'const x = ({}:{})' + output: 'const x = ({}:{})', }, { code: 'const x = ({}:{})', errors: [{message: 'There must be a space before type cast colon.'}], options: ['always'], - output: 'const x = ({} :{})' + output: 'const x = ({} :{})', }, { code: 'const x = ({} :{})', errors: [{message: 'There must be 1 space before type cast colon.'}], options: ['always'], - output: 'const x = ({} :{})' + output: 'const x = ({} :{})', }, { code: '((x) : string)', errors: [{message: 'There must be no space before type cast colon.'}], options: ['never'], - output: '((x): string)' + output: '((x): string)', }, { code: '((x): string)', errors: [{message: 'There must be a space before type cast colon.'}], options: ['always'], - output: '((x) : string)' + output: '((x) : string)', }, { code: '((x) : string)', errors: [{message: 'There must be 1 space before type cast colon.'}], options: ['always'], - output: '((x) : string)' - } + output: '((x) : string)', + }, ], valid: [ { code: 'const x = ({}:{})', - options: ['never'] + options: ['never'], }, { code: 'const x = ({} :{})', - options: ['always'] + options: ['always'], }, { code: '((x): string)', - options: ['never'] + options: ['never'], }, { code: '((x) : string)', - options: ['always'] - } - ] + options: ['always'], + }, + ], }; const VARIABLE_EXPRESSIONS = { @@ -878,35 +878,35 @@ const VARIABLE_EXPRESSIONS = { code: 'const x:number = 7;', errors: [{message: 'There must be a space before const type annotation colon.'}], options: ['always'], - output: 'const x :number = 7;' + output: 'const x :number = 7;', }, { code: 'let x:number = 42;', errors: [{message: 'There must be a space before let type annotation colon.'}], options: ['always'], - output: 'let x :number = 42;' + output: 'let x :number = 42;', }, { code: 'var x:number = 42;', errors: [{message: 'There must be a space before var type annotation colon.'}], options: ['always'], - output: 'var x :number = 42;' - } + output: 'var x :number = 42;', + }, ], valid: [ { code: 'const x :number = 7;', - options: ['always'] + options: ['always'], }, { code: 'let x :number = 42;', - options: ['always'] + options: ['always'], }, { code: 'var x :number = 42;', - options: ['always'] - } - ] + options: ['always'], + }, + ], }; const ALL = [ @@ -919,7 +919,7 @@ const ALL = [ OBJECT_TYPE_PROPERTIES, OBJECT_TYPE_INDEXERS, TYPE_CAST_EXPRESSIONS, - VARIABLE_EXPRESSIONS + VARIABLE_EXPRESSIONS, ]; const MISCONFIGURED = [ @@ -933,25 +933,25 @@ const MISCONFIGURED = [ params: { allowedValues: [ 'always', - 'never' - ] + 'never', + ], }, parentSchema: { enum: [ 'always', - 'never' + 'never', ], - type: 'string' + type: 'string', }, schema: [ 'always', - 'never' + 'never', ], - schemaPath: '#/items/0/enum' - } + schemaPath: '#/items/0/enum', + }, ], - options: ['wherever'] - } + options: ['wherever'], + }, ]; export default { @@ -961,5 +961,5 @@ export default { misconfigured: MISCONFIGURED, valid: _.flatMap(ALL, (rules) => { return rules.valid; - }) + }), }; diff --git a/tests/rules/assertions/spreadExactType.js b/tests/rules/assertions/spreadExactType.js index 4ce35b5e..ee7aaab9 100644 --- a/tests/rules/assertions/spreadExactType.js +++ b/tests/rules/assertions/spreadExactType.js @@ -2,19 +2,19 @@ export default { invalid: [ { code: 'type bar = {...{test: string}}', - errors: [{message: 'Use $Exact to make type spreading safe.'}] + errors: [{message: 'Use $Exact to make type spreading safe.'}], }, { code: 'type foo = {test: number}; type bar = {...foo}', - errors: [{message: 'Use $Exact to make type spreading safe.'}] - } + errors: [{message: 'Use $Exact to make type spreading safe.'}], + }, ], valid: [ { - code: 'type bar = {...$Exact<{test: string}>}' + code: 'type bar = {...$Exact<{test: string}>}', }, { - code: 'type foo = {test: number}; type bar = {...$Exact}' - } - ] + code: 'type foo = {test: number}; type bar = {...$Exact}', + }, + ], }; diff --git a/tests/rules/assertions/typeIdMatch.js b/tests/rules/assertions/typeIdMatch.js index dd4df27b..c24259df 100644 --- a/tests/rules/assertions/typeIdMatch.js +++ b/tests/rules/assertions/typeIdMatch.js @@ -4,21 +4,21 @@ export default { code: 'type foo = {};', errors: [ { - message: 'Type identifier \'foo\' does not match pattern \'/^([A-Z][a-z0-9]*)+Type$/\'.' - } - ] + message: 'Type identifier \'foo\' does not match pattern \'/^([A-Z][a-z0-9]*)+Type$/\'.', + }, + ], }, { code: 'type FooType = {};', errors: [ { - message: 'Type identifier \'FooType\' does not match pattern \'/^foo$/\'.' - } + message: 'Type identifier \'FooType\' does not match pattern \'/^foo$/\'.', + }, ], options: [ - '^foo$' - ] - } + '^foo$', + ], + }, ], misconfigured: [ { @@ -29,35 +29,35 @@ export default { keyword: 'type', message: 'should be string', params: { - type: 'string' + type: 'string', }, parentSchema: { - type: 'string' + type: 'string', }, schema: 'string', - schemaPath: '#/items/0/type' - } + schemaPath: '#/items/0/type', + }, ], - options: [7] - } + options: [7], + }, ], valid: [ { - code: 'type FooType = {};' + code: 'type FooType = {};', }, { code: 'type foo = {};', options: [ - '^foo$' - ] + '^foo$', + ], }, { code: 'type foo = {};', settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } - } - ] + onlyFilesWithFlowAnnotation: true, + }, + }, + }, + ], }; diff --git a/tests/rules/assertions/typeImportStyle.js b/tests/rules/assertions/typeImportStyle.js index 05e6bb3f..2e71ffa0 100644 --- a/tests/rules/assertions/typeImportStyle.js +++ b/tests/rules/assertions/typeImportStyle.js @@ -3,59 +3,59 @@ export default { { code: 'import type {A, B} from \'a\';', errors: [{message: 'Unexpected "import type"'}], - output: 'import {type A, type B} from \'a\';' + output: 'import {type A, type B} from \'a\';', }, { code: 'import type {A, B} from \'a\';', errors: [{message: 'Unexpected "import type"'}], options: ['identifier'], - output: 'import {type A, type B} from \'a\';' + output: 'import {type A, type B} from \'a\';', }, { code: 'import type {A, B as C} from \'a\';', errors: [{message: 'Unexpected "import type"'}], options: ['identifier'], - output: 'import {type A, type B as C} from \'a\';' + output: 'import {type A, type B as C} from \'a\';', }, { code: 'import type A from \'a\';', errors: [{message: 'Unexpected "import type"'}], options: ['identifier'], - output: 'import {type default as A} from \'a\';' + output: 'import {type default as A} from \'a\';', }, { code: 'import {type A, type B} from \'a\';', errors: [ {message: 'Unexpected type import'}, - {message: 'Unexpected type import'} + {message: 'Unexpected type import'}, ], - options: ['declaration'] - } + options: ['declaration'], + }, ], valid: [ { - code: 'import {type A, type B} from \'a\';' + code: 'import {type A, type B} from \'a\';', }, { code: 'import {type A, type B} from \'a\';', - options: ['identifier'] + options: ['identifier'], }, { code: 'import type {A, B} from \'a\';', - options: ['declaration'] + options: ['declaration'], }, { code: 'import typeof * as A from \'a\';', - options: ['identifier'] + options: ['identifier'], }, { code: 'import type A from \'a\';', - options: ['identifier', {ignoreTypeDefault: true}] + options: ['identifier', {ignoreTypeDefault: true}], }, { code: 'declare module "m" { import type A from \'a\'; }', - options: ['identifier'] - } - ] + options: ['identifier'], + }, + ], }; diff --git a/tests/rules/assertions/unionIntersectionSpacing.js b/tests/rules/assertions/unionIntersectionSpacing.js index de9ea0b1..779c7093 100644 --- a/tests/rules/assertions/unionIntersectionSpacing.js +++ b/tests/rules/assertions/unionIntersectionSpacing.js @@ -3,39 +3,39 @@ const UNION = { { code: 'type X = string| number;', errors: [{message: 'There must be a space before union type annotation separator'}], - output: 'type X = string | number;' + output: 'type X = string | number;', }, { code: 'type X = string| number;', errors: [{message: 'There must be a space before union type annotation separator'}], options: ['always'], - output: 'type X = string | number;' + output: 'type X = string | number;', }, { code: 'type X = string |number;', errors: [{message: 'There must be a space after union type annotation separator'}], - output: 'type X = string | number;' + output: 'type X = string | number;', }, { code: 'type X = string|number;', errors: [ {message: 'There must be a space before union type annotation separator'}, - {message: 'There must be a space after union type annotation separator'} + {message: 'There must be a space after union type annotation separator'}, ], - output: 'type X = string | number;' + output: 'type X = string | number;', }, { code: 'type X = {x: string}|{y: number};', errors: [ {message: 'There must be a space before union type annotation separator'}, - {message: 'There must be a space after union type annotation separator'} + {message: 'There must be a space after union type annotation separator'}, ], - output: 'type X = {x: string} | {y: number};' + output: 'type X = {x: string} | {y: number};', }, { code: 'type X = string | number |boolean;', errors: [{message: 'There must be a space after union type annotation separator'}], - output: 'type X = string | number | boolean;' + output: 'type X = string | number | boolean;', }, { code: 'type X = string|number|boolean;', @@ -43,35 +43,35 @@ const UNION = { {message: 'There must be a space before union type annotation separator'}, {message: 'There must be a space after union type annotation separator'}, {message: 'There must be a space before union type annotation separator'}, - {message: 'There must be a space after union type annotation separator'} + {message: 'There must be a space after union type annotation separator'}, ], - output: 'type X = string | number | boolean;' + output: 'type X = string | number | boolean;', }, { code: 'type X = (string)| number;', errors: [{message: 'There must be a space before union type annotation separator'}], - output: 'type X = (string) | number;' + output: 'type X = (string) | number;', }, { code: 'type X = ((string))|(number | foo);', errors: [ {message: 'There must be a space before union type annotation separator'}, - {message: 'There must be a space after union type annotation separator'} + {message: 'There must be a space after union type annotation separator'}, ], - output: 'type X = ((string)) | (number | foo);' + output: 'type X = ((string)) | (number | foo);', }, { code: 'type X = string |number;', errors: [{message: 'There must be no space before union type annotation separator'}], options: ['never'], - output: 'type X = string|number;' + output: 'type X = string|number;', }, { code: 'type X = string| number;', errors: [{message: 'There must be no space after union type annotation separator'}], options: ['never'], - output: 'type X = string|number;' - } + output: 'type X = string|number;', + }, ], valid: [ {code: 'type X = string | number;'}, @@ -80,10 +80,10 @@ const UNION = { {code: 'type X = ((string)) | (number | foo);'}, { code: 'type X = string|number', - options: ['never'] + options: ['never'], }, { - code: 'type X =\n| string\n| number' + code: 'type X =\n| string\n| number', }, { code: [ @@ -91,18 +91,18 @@ const UNION = { 'type X =', '| string', '| number', - '}' - ].join('\n') + '}', + ].join('\n'), }, { code: 'type X = string| number;', settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } - } - ] + onlyFilesWithFlowAnnotation: true, + }, + }, + }, + ], }; const INTERSECTION = { @@ -110,39 +110,39 @@ const INTERSECTION = { { code: 'type X = string& number;', errors: [{message: 'There must be a space before intersection type annotation separator'}], - output: 'type X = string & number;' + output: 'type X = string & number;', }, { code: 'type X = string& number;', errors: [{message: 'There must be a space before intersection type annotation separator'}], options: ['always'], - output: 'type X = string & number;' + output: 'type X = string & number;', }, { code: 'type X = string &number;', errors: [{message: 'There must be a space after intersection type annotation separator'}], - output: 'type X = string & number;' + output: 'type X = string & number;', }, { code: 'type X = {x: string}&{y: number};', errors: [ {message: 'There must be a space before intersection type annotation separator'}, - {message: 'There must be a space after intersection type annotation separator'} + {message: 'There must be a space after intersection type annotation separator'}, ], - output: 'type X = {x: string} & {y: number};' + output: 'type X = {x: string} & {y: number};', }, { code: 'type X = string&number;', errors: [ {message: 'There must be a space before intersection type annotation separator'}, - {message: 'There must be a space after intersection type annotation separator'} + {message: 'There must be a space after intersection type annotation separator'}, ], - output: 'type X = string & number;' + output: 'type X = string & number;', }, { code: 'type X = string & number &boolean;', errors: [{message: 'There must be a space after intersection type annotation separator'}], - output: 'type X = string & number & boolean;' + output: 'type X = string & number & boolean;', }, { code: 'type X = string&number&boolean;', @@ -150,35 +150,35 @@ const INTERSECTION = { {message: 'There must be a space before intersection type annotation separator'}, {message: 'There must be a space after intersection type annotation separator'}, {message: 'There must be a space before intersection type annotation separator'}, - {message: 'There must be a space after intersection type annotation separator'} + {message: 'There must be a space after intersection type annotation separator'}, ], - output: 'type X = string & number & boolean;' + output: 'type X = string & number & boolean;', }, { code: 'type X = (string)& number;', errors: [{message: 'There must be a space before intersection type annotation separator'}], - output: 'type X = (string) & number;' + output: 'type X = (string) & number;', }, { code: 'type X = ((string))&(number & foo);', errors: [ {message: 'There must be a space before intersection type annotation separator'}, - {message: 'There must be a space after intersection type annotation separator'} + {message: 'There must be a space after intersection type annotation separator'}, ], - output: 'type X = ((string)) & (number & foo);' + output: 'type X = ((string)) & (number & foo);', }, { code: 'type X = string &number;', errors: [{message: 'There must be no space before intersection type annotation separator'}], options: ['never'], - output: 'type X = string&number;' + output: 'type X = string&number;', }, { code: 'type X = string& number;', errors: [{message: 'There must be no space after intersection type annotation separator'}], options: ['never'], - output: 'type X = string&number;' - } + output: 'type X = string&number;', + }, ], valid: [ {code: 'type X = string & number;'}, @@ -187,10 +187,10 @@ const INTERSECTION = { {code: 'type X = ((string)) & (number & foo);'}, { code: 'type X = string&number', - options: ['never'] + options: ['never'], }, { - code: 'type X =\n& string\n& number' + code: 'type X =\n& string\n& number', }, { code: [ @@ -198,18 +198,18 @@ const INTERSECTION = { 'type X =', '& string', '& number', - '}' - ].join('\n') + '}', + ].join('\n'), }, { code: 'type X = string& number;', settings: { flowtype: { - onlyFilesWithFlowAnnotation: true - } - } - } - ] + onlyFilesWithFlowAnnotation: true, + }, + }, + }, + ], }; const MISCONFIGURED = [ @@ -223,29 +223,29 @@ const MISCONFIGURED = [ params: { allowedValues: [ 'always', - 'never' - ] + 'never', + ], }, parentSchema: { enum: [ 'always', - 'never' + 'never', ], - type: 'string' + type: 'string', }, schema: [ 'always', - 'never' + 'never', ], - schemaPath: '#/items/0/enum' - } + schemaPath: '#/items/0/enum', + }, ], - options: ['however'] - } + options: ['however'], + }, ]; export default { invalid: [...UNION.invalid, ...INTERSECTION.invalid], misconfigured: MISCONFIGURED, - valid: [...UNION.valid, ...INTERSECTION.valid] + valid: [...UNION.valid, ...INTERSECTION.valid], }; diff --git a/tests/rules/assertions/useFlowType.js b/tests/rules/assertions/useFlowType.js index b002ad35..7fe91ff2 100644 --- a/tests/rules/assertions/useFlowType.js +++ b/tests/rules/assertions/useFlowType.js @@ -1,5 +1,5 @@ import { - RuleTester + RuleTester, } from 'eslint'; import noUnusedVarsRule from 'eslint/lib/rules/no-unused-vars'; import useFlowType from '../../../src/rules/useFlowType'; @@ -8,66 +8,66 @@ const VALID_WITH_USE_FLOW_TYPE = [ { code: 'declare class A {}', errors: [ - '\'A\' is defined but never used.' - ] + '\'A\' is defined but never used.', + ], }, { code: 'declare function A(): Y', errors: [ - '\'A\' is defined but never used.' - ] + '\'A\' is defined but never used.', + ], }, { code: 'declare module A {}', errors: [ - '\'A\' is defined but never used.' - ] + '\'A\' is defined but never used.', + ], }, { code: 'declare module A { declare var a: Y }', errors: [ - '\'A\' is defined but never used.' - ] + '\'A\' is defined but never used.', + ], }, { code: 'declare var A: Y', errors: [ - '\'A\' is defined but never used.' - ] + '\'A\' is defined but never used.', + ], }, { code: 'import type A from "a"; type X> = { b: B }; let x: X; console.log(x);', errors: [ - '\'A\' is defined but never used.' - ] + '\'A\' is defined but never used.', + ], }, { code: 'import type A from "a"; type X> = { b: B }; let x: X; console.log(x);', errors: [ - '\'A\' is defined but never used.' - ] - } + '\'A\' is defined but never used.', + ], + }, ]; const ALWAYS_INVALID = [ { code: 'type A = Y', errors: [ - '\'A\' is defined but never used.' - ] + '\'A\' is defined but never used.', + ], }, { code: 'function x() {}; x()', errors: [ - '\'A\' is defined but never used.' - ] + '\'A\' is defined but never used.', + ], }, { code: 'import type A from "a";', errors: [ - '\'A\' is defined but never used.' - ] - } + '\'A\' is defined but never used.', + ], + }, ]; const ALWAYS_VALID = [ @@ -81,7 +81,7 @@ const ALWAYS_VALID = [ 'import type A from "a"; (function(): A {})', '(function(): A {}); import type A from "a";', 'declare interface A {}', - 'declare type A = {}' + 'declare type A = {}', ]; /** @@ -92,26 +92,26 @@ const ALWAYS_VALID = [ */ { const ruleTester = new RuleTester({ - parser: 'babel-eslint' + parser: 'babel-eslint', }); ruleTester.run('no-unused-vars must not trigger an error in these cases', noUnusedVarsRule, { invalid: [], - valid: ALWAYS_VALID + valid: ALWAYS_VALID, }); } { const ruleTester = new RuleTester({ - parser: 'babel-eslint' + parser: 'babel-eslint', }); ruleTester.run('no-unused-vars must trigger an error in these cases', noUnusedVarsRule, { invalid: [ ...ALWAYS_INVALID, - ...VALID_WITH_USE_FLOW_TYPE + ...VALID_WITH_USE_FLOW_TYPE, ], - valid: [] + valid: [], }); } @@ -119,14 +119,14 @@ const ALWAYS_VALID = [ const ruleTester = new RuleTester({ parser: 'babel-eslint', rules: { - 'use-flow-type': 1 - } + 'use-flow-type': 1, + }, }); ruleTester.defineRule('use-flow-type', useFlowType); ruleTester.run('use-flow-type must not affect no-unused-vars behavior in these cases', noUnusedVarsRule, { invalid: ALWAYS_INVALID, - valid: ALWAYS_VALID + valid: ALWAYS_VALID, }); } @@ -137,9 +137,9 @@ export default { return { code: subject.code, rules: { - 'no-unused-vars': 1 - } + 'no-unused-vars': 1, + }, }; - }) - ] + }), + ], }; diff --git a/tests/rules/assertions/validSyntax.js b/tests/rules/assertions/validSyntax.js index d6334c0c..5b679a65 100644 --- a/tests/rules/assertions/validSyntax.js +++ b/tests/rules/assertions/validSyntax.js @@ -5,10 +5,10 @@ export default { ], valid: [ { - code: 'function x(foo: string = "1") {}' + code: 'function x(foo: string = "1") {}', }, { - code: 'function x(foo: Type = bar()) {}' - } - ] + code: 'function x(foo: Type = bar()) {}', + }, + ], }; diff --git a/tests/rules/index.js b/tests/rules/index.js index 0f137179..c809eb7a 100644 --- a/tests/rules/index.js +++ b/tests/rules/index.js @@ -1,10 +1,10 @@ import assert from 'assert'; import { - camelCase + camelCase, } from 'lodash'; import Ajv from 'ajv'; import { - RuleTester + RuleTester, } from 'eslint'; import plugin from '../../src'; @@ -48,12 +48,12 @@ const reportingRules = [ 'type-import-style', 'union-intersection-spacing', 'use-flow-type', - 'valid-syntax' + 'valid-syntax', ]; const parser = require.resolve('babel-eslint'); const ajv = new Ajv({ - verbose: true + verbose: true, }); for (const ruleName of reportingRules) { @@ -73,7 +73,7 @@ for (const ruleName of reportingRules) { const validateSchema = ajv.compile({ items: schema, - type: 'array' + type: 'array', }); validateSchema(misconfiguration.options);