UNPKG

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