forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create rule for
no-meteor-wrap-async-usage
.
- Loading branch information
1 parent
8770401
commit 9c83016
Showing
3 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
npm-packages/eslint-plugin-meteor/lib/rules/no-meteor-wrap-async-usage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @fileoverview This rule checks the usage of Meteor.wrapAsync method. | ||
* @author Matheus Castro | ||
* @copyright 2023 Matheus Castro. All rights reserved. | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
|
||
const meteorIdentifier = "Meteor"; | ||
const wrapAsyncMethodName = "wrapAsync"; | ||
const isAccessingMeteorWrapAsync = (node) => { | ||
const isMemberExpression = node && node.type === "MemberExpression"; | ||
if (!isMemberExpression) { | ||
return; | ||
} | ||
|
||
const nodeObjectName = node && | ||
node.object && | ||
node.object.type === "Identifier" && | ||
node.object.name; | ||
const nodePropertyName = node && | ||
node.property && | ||
node.property.type === "Identifier" && | ||
node.property.name; | ||
|
||
const isMeteorObject = nodeObjectName && nodeObjectName.toLowerCase() === meteorIdentifier.toLowerCase(); | ||
const isWrapAsyncAccess = nodePropertyName && nodePropertyName === wrapAsyncMethodName; | ||
|
||
return isMeteorObject && isWrapAsyncAccess; | ||
}; | ||
|
||
module.exports = { | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: 'Detect `Meteor.wrapAsync` calls', | ||
recommended: true, | ||
}, | ||
}, | ||
create: (context) => ({ | ||
MemberExpression: (node) => { | ||
if (!isAccessingMeteorWrapAsync(node)) { | ||
return; | ||
} | ||
|
||
context.report(node, "Meteor wrapAsync is going to be removed on Meteor 3.0"); | ||
}, | ||
}), | ||
}; |
80 changes: 80 additions & 0 deletions
80
npm-packages/eslint-plugin-meteor/tests/lib/rules/no-meteor-wrap-async-usage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* @fileoverview This rule checks the usage of Meteor.wrapAsync method. | ||
* @author Matheus Castro | ||
* @copyright 2023 Matheus Castro. All rights reserved. | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
|
||
const { RuleTester } = require('eslint'); | ||
const rule = require('../../../lib/rules/no-meteor-wrap-async-usage'); | ||
|
||
const ruleTester = new RuleTester({ | ||
parserOptions: { | ||
ecmaVersion: 2015, | ||
}, | ||
}); | ||
|
||
ruleTester.run('no-meteor-wrap-async-usage', rule, { | ||
only: true, | ||
valid: [ | ||
{ code: 'Meteor.userAsync()' }, | ||
{ code: 'Meteor.userIdAsync()' }, | ||
{ code: 'Meteor.callAsync()' }, | ||
{ code: 'Meteor.call()' }, | ||
{ code: 'this.wrapAsync' }, | ||
{ code: 'object.wrapAsync' }, | ||
{ code: 'object.wrapAsync()' }, | ||
{ code: 'Object.wrapAsync()()' }, | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: 'Meteor.wrapAsync', | ||
errors: [ | ||
{ message: 'Meteor wrapAsync is going to be removed on Meteor 3.0', type: 'MemberExpression' }, | ||
], | ||
}, | ||
{ | ||
code: 'const asd = Meteor.wrapAsync', | ||
errors: [ | ||
{ message: 'Meteor wrapAsync is going to be removed on Meteor 3.0', type: 'MemberExpression' }, | ||
], | ||
}, | ||
{ | ||
code: 'const asd = Meteor.wrapAsync()', | ||
errors: [ | ||
{ message: 'Meteor wrapAsync is going to be removed on Meteor 3.0', type: 'MemberExpression' }, | ||
], | ||
}, | ||
{ | ||
code: 'const asd = Meteor.wrapAsync(() => {})', | ||
errors: [ | ||
{ message: 'Meteor wrapAsync is going to be removed on Meteor 3.0', type: 'MemberExpression' }, | ||
], | ||
}, | ||
{ | ||
code: 'Meteor.wrapAsync()', | ||
errors: [ | ||
{ message: 'Meteor wrapAsync is going to be removed on Meteor 3.0', type: 'MemberExpression' }, | ||
], | ||
}, | ||
{ | ||
code: 'Meteor.wrapAsync(() => {})', | ||
errors: [ | ||
{ message: 'Meteor wrapAsync is going to be removed on Meteor 3.0', type: 'MemberExpression' }, | ||
], | ||
}, | ||
{ | ||
code: 'Meteor.wrapAsync()()', | ||
errors: [ | ||
{ message: 'Meteor wrapAsync is going to be removed on Meteor 3.0', type: 'MemberExpression' }, | ||
], | ||
}, | ||
{ | ||
code: 'Meteor.wrapAsync(() => {})()', | ||
errors: [ | ||
{ message: 'Meteor wrapAsync is going to be removed on Meteor 3.0', type: 'MemberExpression' }, | ||
], | ||
}, | ||
], | ||
}); |