Skip to content

Commit

Permalink
fix: restore eslint canonical
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Oct 26, 2021
1 parent e9a334b commit 5f6f9aa
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/bin/addAssertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ const updateDocuments = (assertions) => {

documentBody = fs.readFileSync(readmeDocumentPath, 'utf8');

documentBody = documentBody.replace(/<!-- assertions ([a-z]+?) -->/gi, (assertionsBlock) => {
documentBody = documentBody.replace(/<!-- assertions ([a-z]+?) -->/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];

Expand Down
4 changes: 2 additions & 2 deletions src/bin/checkDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,7 +44,7 @@ const getDocIndexRules = () => {
const hasCorrectAssertions = (docPath, name) => {
const content = fs.readFileSync(docPath, 'utf-8');

const match = /<!-- assertions ([A-Za-z]+) -->/.exec(content);
const match = /<!-- assertions ([A-Za-z]+) -->/u.exec(content);

if (match === null) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/checkTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/arrayStyle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/rules/arrayStyle/isSimpleType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/interfaceIdMatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/newlineAfterFlowAnnotation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';

const looksLikeFlowFileAnnotation = (comment) => {
return /@(?:no)?flo/i.test(comment);
return /@(?:no)?flo/ui.test(comment);
};

const schema = [
Expand Down
6 changes: 3 additions & 3 deletions src/rules/noFlowFixMeComments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noInternalFlowType.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ReactComponents = [
const create = (context) => {
return {
Identifier (node) {
const match = node.name.match(/^React\$(?<internalTypeName>.+)/);
const match = node.name.match(/^React\$(?<internalTypeName>.+)/u);
if (match !== null && match.groups !== null && match.groups !== undefined) {
const {internalTypeName} = match.groups;
if (ReactComponents.includes(internalTypeName)) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noPrimitiveConstructorTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions src/rules/noUnusedExpressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const create = (context) => {
) {
return;
}
// eslint-disable-next-line @babel/new-cap
coreChecks.ExpressionStatement(node);
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/rules/requireParameterType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/rules/requireReadonlyReactProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/requireReturnType.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const schema = [
];

const makeRegExp = (str) => {
return new RegExp(str);
return new RegExp(str, 'u');
};

const isUndefinedReturnType = (returnNode) => {
Expand Down
8 changes: 4 additions & 4 deletions src/rules/requireValidFileAnnotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion src/rules/requireVariableType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/typeIdMatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/isFlowFileAnnotation.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/isNoFlowFileAnnotation.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5f6f9aa

Please sign in to comment.