From 5f6f9aad85ec87d4193aec70057a02b733e893d2 Mon Sep 17 00:00:00 2001 From: Gajus Kuizinas Date: Mon, 25 Oct 2021 20:32:50 -0500 Subject: [PATCH] fix: restore eslint canonical --- package.json | 2 +- src/bin/addAssertions.js | 4 ++-- src/bin/checkDocs.js | 4 ++-- src/bin/checkTests.js | 2 +- src/rules/arrayStyle/index.js | 2 +- src/rules/arrayStyle/isSimpleType.js | 4 ++-- src/rules/interfaceIdMatch.js | 2 +- src/rules/newlineAfterFlowAnnotation.js | 2 +- src/rules/noFlowFixMeComments.js | 6 +++--- src/rules/noInternalFlowType.js | 2 +- src/rules/noPrimitiveConstructorTypes.js | 2 +- src/rules/noUnusedExpressions.js | 1 + src/rules/requireParameterType.js | 2 +- src/rules/requireReadonlyReactProps.js | 4 ++-- src/rules/requireReturnType.js | 2 +- src/rules/requireValidFileAnnotation.js | 8 ++++---- src/rules/requireVariableType.js | 2 +- src/rules/typeIdMatch.js | 2 +- src/utilities/isFlowFileAnnotation.js | 4 ++-- src/utilities/isNoFlowFileAnnotation.js | 4 ++-- tests/rules/index.js | 2 +- 21 files changed, 32 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 426a87c3..90c93e82 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "ajv": "^8.6.3", "babel-plugin-add-module-exports": "^1.0.4", "eslint": "^8.1.0", - "eslint-config-canonical": "^32.0.1", + "eslint-config-canonical": "^32.1.1", "eslint-plugin-eslint-plugin": "^4.0.1", "gitdown": "^3.1.4", "glob": "^7.2.0", diff --git a/src/bin/addAssertions.js b/src/bin/addAssertions.js index a762922c..76906743 100644 --- a/src/bin/addAssertions.js +++ b/src/bin/addAssertions.js @@ -61,10 +61,10 @@ const updateDocuments = (assertions) => { documentBody = fs.readFileSync(readmeDocumentPath, 'utf8'); - documentBody = documentBody.replace(//gi, (assertionsBlock) => { + documentBody = documentBody.replace(//ugi, (assertionsBlock) => { let exampleBody; - const ruleName = assertionsBlock.match(/assertions ([a-z]+)/i)[1]; + const ruleName = assertionsBlock.match(/assertions ([a-z]+)/ui)[1]; const ruleAssertions = assertions[ruleName]; diff --git a/src/bin/checkDocs.js b/src/bin/checkDocs.js index bbe0cc04..15c4d9b3 100644 --- a/src/bin/checkDocs.js +++ b/src/bin/checkDocs.js @@ -23,7 +23,7 @@ const getDocIndexRules = () => { const content = fs.readFileSync(path.resolve(__dirname, '../../.README/README.md'), 'utf-8'); const rules = content.split('\n').map((line) => { - const match = /^{"gitdown": "include", "file": "([^"]+)"}$/.exec(line); + const match = /^{"gitdown": "include", "file": "([^"]+)"}$/u.exec(line); if (match === null) { return null; @@ -44,7 +44,7 @@ const getDocIndexRules = () => { const hasCorrectAssertions = (docPath, name) => { const content = fs.readFileSync(docPath, 'utf-8'); - const match = //.exec(content); + const match = //u.exec(content); if (match === null) { return false; diff --git a/src/bin/checkTests.js b/src/bin/checkTests.js index 580d8ece..957234b6 100644 --- a/src/bin/checkTests.js +++ b/src/bin/checkTests.js @@ -15,7 +15,7 @@ const getTestIndexRules = () => { if (line === '];') { acc.inRulesArray = false; } else { - acc.rules.push(line.replace(/^\s*'([^']+)',?$/, '$1')); + acc.rules.push(line.replace(/^\s*'([^']+)',?$/u, '$1')); } } else if (line === 'const reportingRules = [') { acc.inRulesArray = true; diff --git a/src/rules/arrayStyle/index.js b/src/rules/arrayStyle/index.js index cc861a84..ba63460c 100644 --- a/src/rules/arrayStyle/index.js +++ b/src/rules/arrayStyle/index.js @@ -9,7 +9,7 @@ const schema = [ ]; const inlineType = (type) => { - const inlined = type.replace(/\s+/g, ' '); + const inlined = type.replace(/\s+/ug, ' '); if (inlined.length <= 50) { return inlined; diff --git a/src/rules/arrayStyle/isSimpleType.js b/src/rules/arrayStyle/isSimpleType.js index 0b987e5b..b21b3a54 100644 --- a/src/rules/arrayStyle/isSimpleType.js +++ b/src/rules/arrayStyle/isSimpleType.js @@ -19,8 +19,8 @@ */ const simpleTypePatterns = [ - /^(?:Any|Array|Boolean|Generic|Mixed|Number|String|Void)TypeAnnotation$/, - /.+LiteralTypeAnnotation$/, + /^(?:Any|Array|Boolean|Generic|Mixed|Number|String|Void)TypeAnnotation$/u, + /.+LiteralTypeAnnotation$/u, ]; export default (node) => { diff --git a/src/rules/interfaceIdMatch.js b/src/rules/interfaceIdMatch.js index 47b689f5..de14d029 100644 --- a/src/rules/interfaceIdMatch.js +++ b/src/rules/interfaceIdMatch.js @@ -5,7 +5,7 @@ const schema = [ ]; const create = (context) => { - const pattern = new RegExp(context.options[0] || '^([A-Z][a-z0-9]*)+Type$'); + const pattern = new RegExp(context.options[0] || '^([A-Z][a-z0-9]*)+Type$', 'u'); const checkInterface = (interfaceDeclarationNode) => { const interfaceIdentifierName = interfaceDeclarationNode.id.name; diff --git a/src/rules/newlineAfterFlowAnnotation.js b/src/rules/newlineAfterFlowAnnotation.js index 0433f42e..2ad4b86d 100644 --- a/src/rules/newlineAfterFlowAnnotation.js +++ b/src/rules/newlineAfterFlowAnnotation.js @@ -1,7 +1,7 @@ import _ from 'lodash'; const looksLikeFlowFileAnnotation = (comment) => { - return /@(?:no)?flo/i.test(comment); + return /@(?:no)?flo/ui.test(comment); }; const schema = [ diff --git a/src/rules/noFlowFixMeComments.js b/src/rules/noFlowFixMeComments.js index 3c5363fc..ea7a33d8 100644 --- a/src/rules/noFlowFixMeComments.js +++ b/src/rules/noFlowFixMeComments.js @@ -11,7 +11,7 @@ const isIdentifier = function (node, name) { }; const create = (context) => { - const allowedPattern = context.options[0] ? new RegExp(context.options[0]) : null; + const allowedPattern = context.options[0] ? new RegExp(context.options[0], 'u') : null; const extraMessage = allowedPattern ? ' Fix it or match `' + allowedPattern.toString() + '`.' : ''; const passesExtraRegex = function (value) { @@ -25,14 +25,14 @@ const create = (context) => { const handleComment = function (comment) { const value = comment.value.trim(); - if (value.match(/\$FlowFixMe/) && !passesExtraRegex(value)) { + if (value.match(/\$FlowFixMe/u) && !passesExtraRegex(value)) { context.report(comment, message + extraMessage); } }; return { GenericTypeAnnotation (node) { - if (isIdentifier(node.id, /\$FlowFixMe/)) { + if (isIdentifier(node.id, /\$FlowFixMe/u)) { context.report({ message, node: node.id, diff --git a/src/rules/noInternalFlowType.js b/src/rules/noInternalFlowType.js index bf6dd0a2..7d90544e 100644 --- a/src/rules/noInternalFlowType.js +++ b/src/rules/noInternalFlowType.js @@ -22,7 +22,7 @@ const ReactComponents = [ const create = (context) => { return { Identifier (node) { - const match = node.name.match(/^React\$(?.+)/); + const match = node.name.match(/^React\$(?.+)/u); if (match !== null && match.groups !== null && match.groups !== undefined) { const {internalTypeName} = match.groups; if (ReactComponents.includes(internalTypeName)) { diff --git a/src/rules/noPrimitiveConstructorTypes.js b/src/rules/noPrimitiveConstructorTypes.js index 9a50108b..a649263f 100644 --- a/src/rules/noPrimitiveConstructorTypes.js +++ b/src/rules/noPrimitiveConstructorTypes.js @@ -3,7 +3,7 @@ import _ from 'lodash'; const schema = []; const create = (context) => { - const regex = /^(Boolean|Number|String)$/; + const regex = /^(Boolean|Number|String)$/u; return { GenericTypeAnnotation: (node) => { diff --git a/src/rules/noUnusedExpressions.js b/src/rules/noUnusedExpressions.js index ffd11839..9e0b6bdd 100644 --- a/src/rules/noUnusedExpressions.js +++ b/src/rules/noUnusedExpressions.js @@ -20,6 +20,7 @@ const create = (context) => { ) { return; } + // eslint-disable-next-line @babel/new-cap coreChecks.ExpressionStatement(node); }, }; diff --git a/src/rules/requireParameterType.js b/src/rules/requireParameterType.js index a527eeb6..2c1bf365 100644 --- a/src/rules/requireParameterType.js +++ b/src/rules/requireParameterType.js @@ -22,7 +22,7 @@ const schema = [ const create = iterateFunctionNodes((context) => { const skipArrows = _.get(context, 'options[0].excludeArrowFunctions'); - const excludeParameterMatch = new RegExp(_.get(context, 'options[0].excludeParameterMatch', 'a^')); + const excludeParameterMatch = new RegExp(_.get(context, 'options[0].excludeParameterMatch', 'a^'), 'u'); return (functionNode) => { // It is save to ignore FunctionTypeAnnotation nodes in this rule. diff --git a/src/rules/requireReadonlyReactProps.js b/src/rules/requireReadonlyReactProps.js index b1e553c9..f396a0e3 100644 --- a/src/rules/requireReadonlyReactProps.js +++ b/src/rules/requireReadonlyReactProps.js @@ -12,8 +12,8 @@ const schema = [ }, ]; -const reComponentName = /^(Pure)?Component$/; -const reReadOnly = /^\$(ReadOnly|FlowFixMe)$/; +const reComponentName = /^(Pure)?Component$/u; +const reReadOnly = /^\$(ReadOnly|FlowFixMe)$/u; const isReactComponent = (node) => { if (!node.superClass) { diff --git a/src/rules/requireReturnType.js b/src/rules/requireReturnType.js index 0227cbed..dbce24b8 100644 --- a/src/rules/requireReturnType.js +++ b/src/rules/requireReturnType.js @@ -36,7 +36,7 @@ const schema = [ ]; const makeRegExp = (str) => { - return new RegExp(str); + return new RegExp(str, 'u'); }; const isUndefinedReturnType = (returnNode) => { diff --git a/src/rules/requireValidFileAnnotation.js b/src/rules/requireValidFileAnnotation.js index 72d0cbcd..175fc752 100644 --- a/src/rules/requireValidFileAnnotation.js +++ b/src/rules/requireValidFileAnnotation.js @@ -10,7 +10,7 @@ const defaults = { }; const looksLikeFlowFileAnnotation = (comment) => { - return /@(?:no)?flo/i.test(comment); + return /@(?:no)?flo/ui.test(comment); }; const isValidAnnotationStyle = (node, style) => { @@ -22,15 +22,15 @@ const isValidAnnotationStyle = (node, style) => { }; const checkAnnotationSpelling = (comment) => { - return /@[a-z]+\b/.test(comment) && fuzzyStringMatch(comment.replace(/no/i, ''), '@flow', 0.2); + return /@[a-z]+\b/u.test(comment) && fuzzyStringMatch(comment.replace(/no/ui, ''), '@flow', 0.2); }; const isFlowStrict = (comment) => { - return /^@flow\sstrict\b/.test(comment); + return /^@flow\sstrict\b/u.test(comment); }; const noFlowAnnotation = (comment) => { - return /^@noflow\b/.test(comment); + return /^@noflow\b/u.test(comment); }; const schema = [ diff --git a/src/rules/requireVariableType.js b/src/rules/requireVariableType.js index 3ad30477..9acd64e6 100644 --- a/src/rules/requireVariableType.js +++ b/src/rules/requireVariableType.js @@ -38,7 +38,7 @@ const create = (context) => { return () => {}; } - const excludeVariableMatch = new RegExp(_.get(context, 'options[0].excludeVariableMatch', 'a^')); + const excludeVariableMatch = new RegExp(_.get(context, 'options[0].excludeVariableMatch', 'a^'), 'u'); const excludeVariableTypes = _.get(context, 'options[0].excludeVariableTypes', {}); return { diff --git a/src/rules/typeIdMatch.js b/src/rules/typeIdMatch.js index cc9f643f..e3c84984 100644 --- a/src/rules/typeIdMatch.js +++ b/src/rules/typeIdMatch.js @@ -5,7 +5,7 @@ const schema = [ ]; const create = (context) => { - const pattern = new RegExp(context.options[0] || '^([A-Z][a-z0-9]*)+Type$'); + const pattern = new RegExp(context.options[0] || '^([A-Z][a-z0-9]*)+Type$', 'u'); const checkType = (typeAliasNode) => { const typeIdentifierName = typeAliasNode.id.name; diff --git a/src/utilities/isFlowFileAnnotation.js b/src/utilities/isFlowFileAnnotation.js index 01ac445c..fe21c52f 100644 --- a/src/utilities/isFlowFileAnnotation.js +++ b/src/utilities/isFlowFileAnnotation.js @@ -1,11 +1,11 @@ import _ from 'lodash'; -const FLOW_MATCHER = /^@(?:no)?flow$/; +const FLOW_MATCHER = /^@(?:no)?flow$/u; export default (comment, strict) => { // The flow parser splits comments with the following regex to look for the @flow flag. // See https://github.com/facebook/flow/blob/a96249b93541f2f7bfebd8d62085bf7a75de02f2/src/parsing/docblock.ml#L39 - return _.some(comment.split(/[\t\n\r */\\]+/), (commentPart) => { + return _.some(comment.split(/[\t\n\r */\\]+/u), (commentPart) => { const match = commentPart.match(FLOW_MATCHER); if (match === null) { diff --git a/src/utilities/isNoFlowFileAnnotation.js b/src/utilities/isNoFlowFileAnnotation.js index 027ba515..f4df5b98 100644 --- a/src/utilities/isNoFlowFileAnnotation.js +++ b/src/utilities/isNoFlowFileAnnotation.js @@ -1,11 +1,11 @@ import _ from 'lodash'; -const FLOW_MATCHER = /^@noflow$/; +const FLOW_MATCHER = /^@noflow$/u; export default (comment, strict) => { // The flow parser splits comments with the following regex to look for the @flow flag. // See https://github.com/facebook/flow/blob/a96249b93541f2f7bfebd8d62085bf7a75de02f2/src/parsing/docblock.ml#L39 - return _.some(comment.split(/[\t\n\r */\\]+/), (commentPart) => { + return _.some(comment.split(/[\t\n\r */\\]+/u), (commentPart) => { const match = commentPart.match(FLOW_MATCHER); if (match === null) { diff --git a/tests/rules/index.js b/tests/rules/index.js index 3204ca96..9392c266 100644 --- a/tests/rules/index.js +++ b/tests/rules/index.js @@ -13,7 +13,7 @@ const ruleTester = new RuleTester({ babelOptions: { plugins: [ '@babel/plugin-transform-react-jsx', - '@babel/plugin-syntax-flow' + '@babel/plugin-syntax-flow', ], }, requireConfigFile: false,