UNPKG

1.55 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 type: "suggestion",
17
18 docs: {
19 description: "disallow synchronous methods",
20 category: "Node.js and CommonJS",
21 recommended: false,
22 url: "https://eslint.org/docs/rules/no-sync"
23 },
24
25 schema: [
26 {
27 type: "object",
28 properties: {
29 allowAtRootLevel: {
30 type: "boolean",
31 default: false
32 }
33 },
34 additionalProperties: false
35 }
36 ]
37 },
38
39 create(context) {
40 const selector = context.options[0] && context.options[0].allowAtRootLevel
41 ? ":function MemberExpression[property.name=/.*Sync$/]"
42 : "MemberExpression[property.name=/.*Sync$/]";
43
44 return {
45 [selector](node) {
46 context.report({
47 node,
48 message: "Unexpected sync method: '{{propertyName}}'.",
49 data: {
50 propertyName: node.property.name
51 }
52 });
53 }
54 };
55
56 }
57};