diff --git a/src/rules/newlineAfterFlowAnnotation.js b/src/rules/newlineAfterFlowAnnotation.js index 8b3fd6f..9e3d57e 100644 --- a/src/rules/newlineAfterFlowAnnotation.js +++ b/src/rules/newlineAfterFlowAnnotation.js @@ -1,6 +1,4 @@ -import _ from 'lodash'; - -const looksLikeFlowFileAnnotation = (comment) => /@(?:no)?flo/ui.test(comment); +const looksLikeFlowFileAnnotation = (comment) => /^\s*.*@(?:no)?flow(.|\s)*/u.test(comment); const schema = [ { @@ -19,8 +17,7 @@ const create = (context) => { Program(node) { const sourceCode = context.getSourceCode(); - const potentialFlowFileAnnotation = _.find( - context.getSourceCode().getAllComments(), + const potentialFlowFileAnnotation = sourceCode.getAllComments().find( (comment) => looksLikeFlowFileAnnotation(comment.value), ); diff --git a/src/rules/noFlowSuppressionsInStrictFiles.js b/src/rules/noFlowSuppressionsInStrictFiles.js index c65d0ed..e2ba994 100644 --- a/src/rules/noFlowSuppressionsInStrictFiles.js +++ b/src/rules/noFlowSuppressionsInStrictFiles.js @@ -4,7 +4,7 @@ import type { Rule$Create } from 'eslint'; import { suppressionTypes } from '../utilities'; -const FLOW_STRICT_MATCHER = /^\s*@(?:no)?flow\s*strict(?:-local)?\s*$/u; +const FLOW_STRICT_MATCHER = /^\s*.*@(?:no)?flow\s*strict(?:-local)?\s*.*/u; const isStrictFlowFile = (context) => context .getAllComments() diff --git a/src/utilities/index.js b/src/utilities/index.js index f25ad8e..cc49e27 100644 --- a/src/utilities/index.js +++ b/src/utilities/index.js @@ -1,5 +1,4 @@ // @flow -// eslint-disable-next-line import/no-namespace import * as spacingFixers from './spacingFixers'; export { diff --git a/tests/rules/assertions/newlineAfterFlowAnnotation.js b/tests/rules/assertions/newlineAfterFlowAnnotation.js index af42351..9159ba7 100644 --- a/tests/rules/assertions/newlineAfterFlowAnnotation.js +++ b/tests/rules/assertions/newlineAfterFlowAnnotation.js @@ -23,6 +23,22 @@ export default { options: ['never'], output: '// @flow\n', }, + { + code: `/* +* @flow +* +* something multi lined +*/ +const text: string = 42;`, + errors: [{ message: 'Expected newline after flow annotation' }], + output: `/* +* @flow +* +* something multi lined +*/ + +const text: string = 42;`, + }, ], valid: [ { @@ -37,5 +53,15 @@ export default { code: '// @flow\nimport Foo from \'./foo\';', options: ['never'], }, + { + code: `/* +* @flow +* +* something multi lined +*/ + +const text: string = 42;`, + options: ['always'], + }, ], }; diff --git a/tests/rules/assertions/noFlowSuppressionsInStrictFiles.js b/tests/rules/assertions/noFlowSuppressionsInStrictFiles.js index 0f3745a..cba5c55 100644 --- a/tests/rules/assertions/noFlowSuppressionsInStrictFiles.js +++ b/tests/rules/assertions/noFlowSuppressionsInStrictFiles.js @@ -16,6 +16,23 @@ export default { invalid('// @flow strict\n\n// $FlowFixMe\nconst text: string = 42;'), invalid('// @flow strict-local\n\n// $FlowFixMe\nconst text: string = 42;'), invalid('// @flow strict\n\n// $FlowExpectedError[xxx]\nconst text: string = 42;'), + invalid('/* @flow strict */\n\n// $FlowExpectedError[xxx]\nconst text: string = 42;'), + invalid(`/* +* @flow strict +* +* something multi lined +*/ + +// $FlowExpectedError[xxx] +const text: string = 42;`), + invalid(`/* +* @flow strict +* +* something multi lined +*/ + +/* $FlowIgnore[xxx] */ +const text: string = 42;`), invalid( '// @flow strict\n\n// $FlowFixMe\nconst text: string = 42;', {