Skip to content

Commit

Permalink
feat: create rule for no-promise-fibers-usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusccastroo committed Dec 14, 2023
1 parent 8782d89 commit ced133c
Show file tree
Hide file tree
Showing 3 changed files with 7,017 additions and 13,086 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* @fileoverview This rule checks the usage of Meteor Promise Fibers methods.
* @author Matheus Castro
* @copyright 2023 Renan Castro. All rights reserved.
* See LICENSE file in root directory for full license.
*/

const promiseFiberPrototypeAwait = "await";

Check failure on line 8 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Replace `"await"` with `'await'`

Check failure on line 8 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Replace `"await"` with `'await'`
const promiseFiberMethods = [

Check failure on line 9 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Replace `⏎··"await",⏎··"awaitAll",⏎··"async",⏎··"asyncApply",⏎` with `'await',·'awaitAll',·'async',·'asyncApply'`

Check failure on line 9 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Replace `⏎··"await",⏎··"awaitAll",⏎··"async",⏎··"asyncApply",⏎` with `'await',·'awaitAll',·'async',·'asyncApply'`
"await",
"awaitAll",
"async",
"asyncApply",
];

const isGlobalPromiseFiber = (node) => {
const nodeObjectName = node &&

Check failure on line 17 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Insert `⏎···`

Check failure on line 17 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Insert `⏎···`
node.object &&
node.object.type === "Identifier" &&

Check failure on line 19 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Replace `"Identifier"` with `'Identifier'`

Check failure on line 19 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Replace `"Identifier"` with `'Identifier'`
node.object.name;

return nodeObjectName === "Promise";

Check failure on line 22 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Replace `"Promise"` with `'Promise'`

Check failure on line 22 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Replace `"Promise"` with `'Promise'`
};

const isUsingNotAllowedPromiseFiberMethod = (node) => {
if (!isGlobalPromiseFiber(node)) {
return;
}

const nodePropertyName = node &&

Check failure on line 30 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Insert `⏎···`

Check failure on line 30 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Insert `⏎···`
node.property &&
node.property.type === "Identifier" &&

Check failure on line 32 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Replace `"Identifier"` with `'Identifier'`

Check failure on line 32 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Replace `"Identifier"` with `'Identifier'`
node.property.name;

return promiseFiberMethods.includes(nodePropertyName);
}

Check failure on line 36 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Insert `;`

Check failure on line 36 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Missing semicolon

Check failure on line 36 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Insert `;`

Check failure on line 36 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Missing semicolon

const isPromisePrototypeAwaitCall = (node) => {
const isMemberExpression = node && node.type === "MemberExpression";

Check failure on line 39 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Replace `"MemberExpression"` with `'MemberExpression'`

Check failure on line 39 in npm-packages/eslint-plugin-meteor/lib/rules/no-promise-fibers-usage.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Replace `"MemberExpression"` with `'MemberExpression'`
if (!isMemberExpression) {
return;
}

const isAccessingGlobalPromise = node &&
node.object &&
node.object.type === "Identifier" &&
node.object.name === "Promise";
if (isAccessingGlobalPromise) {
return;
}

const nodePropertyName = node &&
node.property &&
node.property.type === "Identifier" &&
node.property.name;

return nodePropertyName === promiseFiberPrototypeAwait;
};

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Detect `Promise` Fibers abstraction calls',
recommended: true,
},
},
create: (context) => ({
MemberExpression: (node) => {
if (isUsingNotAllowedPromiseFiberMethod(node)) {
return context.report(node, "Fibers abstractions for Promises should be replaced by native methods");
}

if (isPromisePrototypeAwaitCall(node)) {
return context.report(node, "Promise Fibers prototype await call is not allowed");
}
},
}),
};
Loading

0 comments on commit ced133c

Please sign in to comment.