diff --git a/src/bin/addAssertions.js b/src/bin/addAssertions.js index 2b4f0e58..a762922c 100644 --- a/src/bin/addAssertions.js +++ b/src/bin/addAssertions.js @@ -4,8 +4,8 @@ * @file This script is used to inline assertions into the README.md documents. */ -import path from 'path'; import fs from 'fs'; +import path from 'path'; import glob from 'glob'; import _ from 'lodash'; @@ -43,7 +43,7 @@ const getAssertions = () => { }); const assertionCodes = _.map(assertionFiles, (filePath) => { - // eslint-disable-next-line global-require, import/no-dynamic-require + // eslint-disable-next-line import/no-dynamic-require const codes = require(filePath); return { diff --git a/src/bin/checkTests.js b/src/bin/checkTests.js index 688ee648..580d8ece 100644 --- a/src/bin/checkTests.js +++ b/src/bin/checkTests.js @@ -10,7 +10,6 @@ import { const getTestIndexRules = () => { const content = fs.readFileSync(path.resolve(__dirname, '../../tests/rules/index.js'), 'utf-8'); - // eslint-disable-next-line unicorn/no-reduce const result = content.split('\n').reduce((acc, line) => { if (acc.inRulesArray) { if (line === '];') { diff --git a/src/index.js b/src/index.js index 96b8b572..b8a9369d 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,8 @@ -/* eslint-disable import/max-dependencies */ import _ from 'lodash'; import recommended from './configs/recommended.json'; import arrayStyleComplexType from './rules/arrayStyleComplexType'; import arrayStyleSimpleType from './rules/arrayStyleSimpleType'; +import arrowParens from './rules/arrowParens'; import booleanStyle from './rules/booleanStyle'; import defineFlowType from './rules/defineFlowType'; import delimiterDangle from './rules/delimiterDangle'; @@ -13,20 +13,20 @@ import newlineAfterFlowAnnotation from './rules/newlineAfterFlowAnnotation'; import noDupeKeys from './rules/noDupeKeys'; import noExistentialType from './rules/noExistentialType'; import noFlowFixMeComments from './rules/noFlowFixMeComments'; +import noInternalFlowType from './rules/noInternalFlowType'; +import noMixed from './rules/noMixed'; import noMutableArray from './rules/noMutableArray'; import noPrimitiveConstructorTypes from './rules/noPrimitiveConstructorTypes'; import noTypesMissingFileAnnotation from './rules/noTypesMissingFileAnnotation'; import noUnusedExpressions from './rules/noUnusedExpressions'; import noWeakTypes from './rules/noWeakTypes'; -import noInternalFlowType from './rules/noInternalFlowType'; -import noMixed from './rules/noMixed'; import objectTypeCurlySpacing from './rules/objectTypeCurlySpacing'; import objectTypeDelimiter from './rules/objectTypeDelimiter'; import quotes from './rules/quotes'; -import requireIndexerName from './rules/requireIndexerName'; import requireCompoundTypeAlias from './rules/requireCompoundTypeAlias'; -import requireInexactType from './rules/requireInexactType'; import requireExactType from './rules/requireExactType'; +import requireIndexerName from './rules/requireIndexerName'; +import requireInexactType from './rules/requireInexactType'; import requireParameterType from './rules/requireParameterType'; import requireReadonlyReactProps from './rules/requireReadonlyReactProps'; import requireReturnType from './rules/requireReturnType'; @@ -39,15 +39,16 @@ import sortTypeUnionIntersectionMembers from './rules/sortTypeUnionIntersectionM import spaceAfterTypeColon from './rules/spaceAfterTypeColon'; import spaceBeforeGenericBracket from './rules/spaceBeforeGenericBracket'; import spaceBeforeTypeColon from './rules/spaceBeforeTypeColon'; +import spreadExactType from './rules/spreadExactType'; import typeIdMatch from './rules/typeIdMatch'; import typeImportStyle from './rules/typeImportStyle'; import unionIntersectionSpacing from './rules/unionIntersectionSpacing'; import useFlowType from './rules/useFlowType'; import useReadOnlySpread from './rules/useReadOnlySpread'; import validSyntax from './rules/validSyntax'; -import spreadExactType from './rules/spreadExactType'; -import arrowParens from './rules/arrowParens'; -import {checkFlowFileAnnotation} from './utilities'; +import { + checkFlowFileAnnotation, +} from './utilities'; const rules = { 'array-style-complex-type': arrayStyleComplexType, diff --git a/src/rules/arrayStyle/index.js b/src/rules/arrayStyle/index.js index 6de8be22..cc861a84 100644 --- a/src/rules/arrayStyle/index.js +++ b/src/rules/arrayStyle/index.js @@ -46,32 +46,31 @@ export default (defaultConfig, simpleType) => { // verbose GenericTypeAnnotation (node) { - if (node.id.name === 'Array') { - // Don't report on un-parameterized Array annotations. There are valid cases for this, - // but regardless, we must NOT crash when encountering them. - if (node.typeParameters && node.typeParameters.params.length === 1) { - const elementTypeNode = node.typeParameters.params[0]; - const rawElementType = context.getSourceCode().getText(elementTypeNode); - const inlinedType = inlineType(rawElementType); - const wrappedInlinedType = needWrap(elementTypeNode) ? '(' + inlinedType + ')' : inlinedType; + // Don't report on un-parameterized Array annotations. There are valid cases for this, + // but regardless, we must NOT crash when encountering them. + if (node.id.name === 'Array' && + node.typeParameters && node.typeParameters.params.length === 1) { + const elementTypeNode = node.typeParameters.params[0]; + const rawElementType = context.getSourceCode().getText(elementTypeNode); + const inlinedType = inlineType(rawElementType); + const wrappedInlinedType = needWrap(elementTypeNode) ? '(' + inlinedType + ')' : inlinedType; - if (isSimpleType(elementTypeNode) === simpleType && !verbose) { - context.report({ - data: { - type: inlinedType, - wrappedType: wrappedInlinedType, - }, - fix (fixer) { - if (needWrap(elementTypeNode)) { - return fixer.replaceText(node, '(' + rawElementType + ')[]'); - } else { - return fixer.replaceText(node, rawElementType + '[]'); - } - }, - message: 'Use "{{ wrappedType }}[]", not "Array<{{ type }}>"', - node, - }); - } + if (isSimpleType(elementTypeNode) === simpleType && !verbose) { + context.report({ + data: { + type: inlinedType, + wrappedType: wrappedInlinedType, + }, + fix (fixer) { + if (needWrap(elementTypeNode)) { + return fixer.replaceText(node, '(' + rawElementType + ')[]'); + } else { + return fixer.replaceText(node, rawElementType + '[]'); + } + }, + message: 'Use "{{ wrappedType }}[]", not "Array<{{ type }}>"', + node, + }); } } }, diff --git a/src/rules/defineFlowType.js b/src/rules/defineFlowType.js index b172ec69..5caf26ab 100644 --- a/src/rules/defineFlowType.js +++ b/src/rules/defineFlowType.js @@ -14,7 +14,7 @@ const create = (context) => { if (ref.identifier.name === ident.name) { // use "__defineGeneric" since we don't have a reference to "escope.Variable" - // eslint-disable-next-line no-underscore-dangle + globalScope.__defineGeneric( ident.name, globalScope.set, diff --git a/src/rules/genericSpacing.js b/src/rules/genericSpacing.js index 552fd8bf..ad2805dc 100644 --- a/src/rules/genericSpacing.js +++ b/src/rules/genericSpacing.js @@ -1,4 +1,6 @@ -import {spacingFixers} from '../utilities'; +import { + spacingFixers, +} from '../utilities'; const schema = [ { diff --git a/src/rules/noTypesMissingFileAnnotation.js b/src/rules/noTypesMissingFileAnnotation.js index a1cf2dd9..55bda717 100644 --- a/src/rules/noTypesMissingFileAnnotation.js +++ b/src/rules/noTypesMissingFileAnnotation.js @@ -1,4 +1,6 @@ -import {isFlowFile} from '../utilities'; +import { + isFlowFile, +} from '../utilities'; /** * Disallows the use for flow types without a valid file annotation. diff --git a/src/rules/objectTypeCurlySpacing.js b/src/rules/objectTypeCurlySpacing.js index 38a2b23c..1571ef16 100644 --- a/src/rules/objectTypeCurlySpacing.js +++ b/src/rules/objectTypeCurlySpacing.js @@ -1,4 +1,6 @@ -import {spacingFixers} from '../utilities'; +import { + spacingFixers, +} from '../utilities'; const schema = [ { diff --git a/src/rules/objectTypeDelimiter.js b/src/rules/objectTypeDelimiter.js index 4f9059e7..8ce00837 100644 --- a/src/rules/objectTypeDelimiter.js +++ b/src/rules/objectTypeDelimiter.js @@ -37,16 +37,14 @@ const create = (context) => { lastToken = parentTokens[parentTokens.indexOf(lastToken) + 1]; } - if (lastToken.type === 'Punctuator') { - if (lastToken.value === BAD.char) { - context.report({ - fix (fixer) { - return fixer.replaceText(lastToken, GOOD.char); - }, - message: 'Prefer ' + GOOD.name + 's to ' + BAD.name + 's in object and class types', - node: lastToken, - }); - } + if (lastToken.type === 'Punctuator' && lastToken.value === BAD.char) { + context.report({ + fix (fixer) { + return fixer.replaceText(lastToken, GOOD.char); + }, + message: 'Prefer ' + GOOD.name + 's to ' + BAD.name + 's in object and class types', + node: lastToken, + }); } }; diff --git a/src/rules/requireIndexerName.js b/src/rules/requireIndexerName.js index 4c0ae7b1..ed1105cb 100644 --- a/src/rules/requireIndexerName.js +++ b/src/rules/requireIndexerName.js @@ -1,4 +1,6 @@ -import {getParameterName} from '../utilities'; +import { + getParameterName, +} from '../utilities'; const schema = [ { diff --git a/src/rules/spaceBeforeGenericBracket.js b/src/rules/spaceBeforeGenericBracket.js index 7a796a8c..af2f239f 100644 --- a/src/rules/spaceBeforeGenericBracket.js +++ b/src/rules/spaceBeforeGenericBracket.js @@ -1,4 +1,6 @@ -import {spacingFixers} from '../utilities'; +import { + spacingFixers, +} from '../utilities'; const schema = [ { diff --git a/src/rules/typeColonSpacing/evaluateFunctions.js b/src/rules/typeColonSpacing/evaluateFunctions.js index f6ccd5a7..a06b1cee 100644 --- a/src/rules/typeColonSpacing/evaluateFunctions.js +++ b/src/rules/typeColonSpacing/evaluateFunctions.js @@ -1,7 +1,9 @@ import _ from 'lodash'; -import {iterateFunctionNodes} from '../../utilities'; -import evaluateTypical from './evaluateTypical'; +import { + iterateFunctionNodes, +} from '../../utilities'; import evaluateReturnType from './evaluateReturnType'; +import evaluateTypical from './evaluateTypical'; export default iterateFunctionNodes((context, report) => { const checkParam = evaluateTypical(context, report, 'parameter'); diff --git a/src/rules/typeColonSpacing/evaluateObjectTypeIndexer.js b/src/rules/typeColonSpacing/evaluateObjectTypeIndexer.js index 31baf346..b35654d9 100644 --- a/src/rules/typeColonSpacing/evaluateObjectTypeIndexer.js +++ b/src/rules/typeColonSpacing/evaluateObjectTypeIndexer.js @@ -1,4 +1,6 @@ -import {getTokenAfterParens, getTokenBeforeParens} from '../../utilities'; +import { + getTokenAfterParens, getTokenBeforeParens, +} from '../../utilities'; export default (context, report) => { const sourceCode = context.getSourceCode(); diff --git a/src/rules/typeColonSpacing/evaluateObjectTypeProperty.js b/src/rules/typeColonSpacing/evaluateObjectTypeProperty.js index 3bd3c915..570ed8f7 100644 --- a/src/rules/typeColonSpacing/evaluateObjectTypeProperty.js +++ b/src/rules/typeColonSpacing/evaluateObjectTypeProperty.js @@ -1,7 +1,8 @@ -import {getParameterName, quoteName} from '../../utilities'; +import { + getParameterName, quoteName, +} from '../../utilities'; const getColon = (context, objectTypeProperty) => { - // eslint-disable-next-line init-declarations let tokenIndex = 1; if (objectTypeProperty.optional) { diff --git a/src/rules/typeColonSpacing/evaluateTypical.js b/src/rules/typeColonSpacing/evaluateTypical.js index 5d3c3f02..94710c93 100644 --- a/src/rules/typeColonSpacing/evaluateTypical.js +++ b/src/rules/typeColonSpacing/evaluateTypical.js @@ -1,5 +1,7 @@ import _ from 'lodash'; -import {getParameterName, quoteName} from '../../utilities'; +import { + getParameterName, quoteName, +} from '../../utilities'; export default (context, report, typeForMessage) => { const sourceCode = context.getSourceCode(); diff --git a/src/rules/typeColonSpacing/evaluateVariables.js b/src/rules/typeColonSpacing/evaluateVariables.js index ac437eac..fc60f408 100644 --- a/src/rules/typeColonSpacing/evaluateVariables.js +++ b/src/rules/typeColonSpacing/evaluateVariables.js @@ -1,5 +1,7 @@ import _ from 'lodash'; -import {getParameterName, quoteName} from '../../utilities'; +import { + getParameterName, quoteName, +} from '../../utilities'; export default (context, report) => { const sourceCode = context.getSourceCode(); diff --git a/src/rules/typeColonSpacing/index.js b/src/rules/typeColonSpacing/index.js index e64cb757..d4519626 100644 --- a/src/rules/typeColonSpacing/index.js +++ b/src/rules/typeColonSpacing/index.js @@ -1,10 +1,10 @@ -import reporter from './reporter'; +import evaluateFunctions from './evaluateFunctions'; import evaluateObjectTypeIndexer from './evaluateObjectTypeIndexer'; import evaluateObjectTypeProperty from './evaluateObjectTypeProperty'; import evaluateTypeCastExpression from './evaluateTypeCastExpression'; import evaluateTypical from './evaluateTypical'; -import evaluateFunctions from './evaluateFunctions'; import evaluateVariables from './evaluateVariables'; +import reporter from './reporter'; export default (direction, context, options) => { const report = reporter(direction, context, options); diff --git a/src/rules/typeColonSpacing/reporter.js b/src/rules/typeColonSpacing/reporter.js index cb47d1f9..7c7b5459 100644 --- a/src/rules/typeColonSpacing/reporter.js +++ b/src/rules/typeColonSpacing/reporter.js @@ -1,4 +1,6 @@ -import {spacingFixers} from '../../utilities'; +import { + spacingFixers, +} from '../../utilities'; const hasLineBreak = (direction, colon, context) => { const sourceCode = context.getSourceCode(); diff --git a/src/rules/unionIntersectionSpacing.js b/src/rules/unionIntersectionSpacing.js index 09b5a6f2..e5fab221 100644 --- a/src/rules/unionIntersectionSpacing.js +++ b/src/rules/unionIntersectionSpacing.js @@ -1,4 +1,6 @@ -import {spacingFixers, getTokenAfterParens} from '../utilities'; +import { + spacingFixers, getTokenAfterParens, +} from '../utilities'; const schema = [ { diff --git a/src/utilities/index.js b/src/utilities/index.js index 64d80c5f..66034ae2 100644 --- a/src/utilities/index.js +++ b/src/utilities/index.js @@ -3,16 +3,36 @@ // eslint-disable-next-line import/no-namespace import * as spacingFixers from './spacingFixers'; -export {default as checkFlowFileAnnotation} from './checkFlowFileAnnotation'; -export {default as fuzzyStringMatch} from './fuzzyStringMatch'; -export {default as getParameterName} from './getParameterName'; -export {default as getTokenAfterParens} from './getTokenAfterParens'; -export {default as getTokenBeforeParens} from './getTokenBeforeParens'; -export {default as isFlowFile} from './isFlowFile'; -export {default as isNoFlowFile} from './isNoFlowFile'; -export {default as isFlowFileAnnotation} from './isFlowFileAnnotation'; -export {default as iterateFunctionNodes} from './iterateFunctionNodes'; -export {default as quoteName} from './quoteName'; +export { + default as checkFlowFileAnnotation, +} from './checkFlowFileAnnotation'; +export { + default as fuzzyStringMatch, +} from './fuzzyStringMatch'; +export { + default as getParameterName, +} from './getParameterName'; +export { + default as getTokenAfterParens, +} from './getTokenAfterParens'; +export { + default as getTokenBeforeParens, +} from './getTokenBeforeParens'; +export { + default as isFlowFile, +} from './isFlowFile'; +export { + default as isNoFlowFile, +} from './isNoFlowFile'; +export { + default as isFlowFileAnnotation, +} from './isFlowFileAnnotation'; +export { + default as iterateFunctionNodes, +} from './iterateFunctionNodes'; +export { + default as quoteName, +} from './quoteName'; export { spacingFixers, diff --git a/tests/rules/assertions/arrowParens.js b/tests/rules/assertions/arrowParens.js index d2432dba..75bed534 100644 --- a/tests/rules/assertions/arrowParens.js +++ b/tests/rules/assertions/arrowParens.js @@ -1,4 +1,3 @@ -/* eslint-disable sort-keys */ const type = 'ArrowFunctionExpression'; export default { @@ -285,11 +284,9 @@ 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 } {code: '() => {}', diff --git a/tests/rules/assertions/defineFlowType.js b/tests/rules/assertions/defineFlowType.js index f4d95529..8e421c07 100644 --- a/tests/rules/assertions/defineFlowType.js +++ b/tests/rules/assertions/defineFlowType.js @@ -131,7 +131,6 @@ const VALID_WITH_DEFINE_FLOW_TYPE = [ // This tests to ensure we have a robust handling of @flow comments { - // eslint-disable-next-line no-restricted-syntax code: ` /** * Copyright 2019 no corp diff --git a/tests/rules/assertions/sortKeys.js b/tests/rules/assertions/sortKeys.js index 8fa41e1f..dc6d08e2 100644 --- a/tests/rules/assertions/sortKeys.js +++ b/tests/rules/assertions/sortKeys.js @@ -40,7 +40,6 @@ export default { errors: [{message: 'Expected type annotations to be in ascending order. "b" must be before "c".'}], output: 'type FooType = { a: number, b: string, c: number }', }, - /* eslint-disable no-restricted-syntax */ { code: ` type FooType = { @@ -438,7 +437,6 @@ export default { |} `, }, - /* eslint-enable no-restricted-syntax */ // https://github.com/gajus/eslint-plugin-flowtype/issues/455 { diff --git a/tests/rules/index.js b/tests/rules/index.js index 069e54f6..3694375c 100644 --- a/tests/rules/index.js +++ b/tests/rules/index.js @@ -1,11 +1,11 @@ import assert from 'assert'; -import { - camelCase, -} from 'lodash'; import Ajv from 'ajv'; import { RuleTester, } from 'eslint'; +import { + camelCase, +} from 'lodash'; import plugin from '../../src'; const ruleTester = new RuleTester(); @@ -65,7 +65,7 @@ const ajv = new Ajv({ }); for (const ruleName of reportingRules) { - // eslint-disable-next-line global-require, import/no-dynamic-require + // eslint-disable-next-line import/no-dynamic-require const assertions = require('./assertions/' + camelCase(ruleName)); if (assertions.misconfigured) {