UNPKG

1.43 kBJavaScriptView Raw
1/**
2 * @fileoverview Rule to check for properties whose identifier ends with the string Sync
3 * @author Matt DuVall<http://mattduvall.com/>
4 */
5
6/* jshint node:true */
7
8"use strict";
9
10//------------------------------------------------------------------------------
11// Rule Definition
12//------------------------------------------------------------------------------
13
14module.exports = {
15 meta: {
16 docs: {
17 description: "disallow synchronous methods",
18 category: "Node.js and CommonJS",
19 recommended: false
20 },
21
22 schema: [
23 {
24 type: "object",
25 properties: {
26 allowAtRootLevel: {
27 type: "boolean"
28 }
29 },
30 additionalProperties: false
31 }
32 ]
33 },
34
35 create(context) {
36 const selector = context.options[0] && context.options[0].allowAtRootLevel
37 ? ":function MemberExpression[property.name=/.*Sync$/]"
38 : "MemberExpression[property.name=/.*Sync$/]";
39
40 return {
41 [selector](node) {
42 context.report({
43 node,
44 message: "Unexpected sync method: '{{propertyName}}'.",
45 data: {
46 propertyName: node.property.name
47 }
48 });
49 }
50 };
51
52 }
53};