@agilebot/eslint-plugin 0.3.7 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +120 -2
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license @agilebot/eslint-plugin v0.3.7
2
+ * @license @agilebot/eslint-plugin v0.3.8
3
3
  *
4
4
  * Copyright (c) Agilebot, Inc. and its affiliates.
5
5
  *
@@ -8,9 +8,9 @@
8
8
  */
9
9
  'use strict';
10
10
 
11
+ var eslintUtils = require('@agilebot/eslint-utils');
11
12
  var fs = require('node:fs');
12
13
  var path = require('node:path');
13
- var eslintUtils = require('@agilebot/eslint-utils');
14
14
  var utils = require('@typescript-eslint/utils');
15
15
 
16
16
  function _interopNamespaceDefault(e) {
@@ -72,6 +72,123 @@ var enforceMuiIconAlias = {
72
72
  }
73
73
  };
74
74
 
75
+ var funcNaming = {
76
+ meta: {
77
+ docs: {
78
+ description: 'Enforce function naming convention'
79
+ },
80
+ schema: [{
81
+ type: 'object',
82
+ properties: {
83
+ format: {
84
+ "enum": ['camelCase', 'PascalCase']
85
+ }
86
+ }
87
+ }],
88
+ messages: {
89
+ invalidFuncNaming: 'Invalid function naming for non-React component, expected {{format}}',
90
+ invalidReactFCNaming: 'Invalid naming convention for React functional component, expected PascalCase'
91
+ }
92
+ },
93
+ create(context) {
94
+ if (!context.options[0]) {
95
+ throw new Error('Missing options');
96
+ }
97
+ const format = context.options[0].format;
98
+ function validate({
99
+ node,
100
+ fnName
101
+ }) {
102
+ let isPass;
103
+ switch (format) {
104
+ case 'camelCase':
105
+ if (!eslintUtils.isCamelCase(fnName)) {
106
+ isPass = false;
107
+ }
108
+ break;
109
+ case 'PascalCase':
110
+ if (!eslintUtils.isPascalCase(fnName)) {
111
+ isPass = false;
112
+ }
113
+ break;
114
+ }
115
+ if (isPass === false) {
116
+ context.report({
117
+ node: node,
118
+ messageId: 'invalidFuncNaming',
119
+ data: {
120
+ format
121
+ }
122
+ });
123
+ }
124
+ }
125
+ function checkJSXElement(node) {
126
+ if (!node) {
127
+ return false;
128
+ }
129
+ if (node.type === 'JSXElement' || node.type === 'JSXFragment') {
130
+ return true;
131
+ }
132
+ if (node.type === 'BlockStatement') {
133
+ for (const statement of node.body) {
134
+ if (statement.type === 'ReturnStatement') {
135
+ if (checkJSXElement(statement.argument)) {
136
+ return true;
137
+ }
138
+ } else if (checkJSXElement(statement)) {
139
+ return true;
140
+ }
141
+ }
142
+ }
143
+ if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression') {
144
+ return checkJSXElement(node.body);
145
+ }
146
+ return false;
147
+ }
148
+ return {
149
+ MethodDefinition(node) {
150
+ if (node.kind === 'method') ;
151
+ },
152
+ FunctionDeclaration(node) {
153
+ if (node.type === 'FunctionDeclaration' && node.id) {
154
+ const fnName = node.id.name;
155
+ const isReactComponent = checkJSXElement(node.body);
156
+ if (!isReactComponent) {
157
+ validate({
158
+ node,
159
+ fnName
160
+ });
161
+ }
162
+ }
163
+ },
164
+ VariableDeclarator(node) {
165
+ if (node.init && ['FunctionExpression', 'ArrowFunctionExpression'].includes(node.init.type)) {
166
+ const fnName = node.id.name;
167
+ let isReactComponent = checkJSXElement(node.init.body);
168
+ if (node.id.typeAnnotation && node.id.typeAnnotation.typeAnnotation) {
169
+ const typeAnnotation = node.id.typeAnnotation.typeAnnotation;
170
+ if (typeAnnotation.type === 'TSTypeReference' && typeAnnotation.typeName.type === 'Identifier') {
171
+ const typeName = typeAnnotation.typeName.name;
172
+ if (['FC', 'React.FC', 'FunctionComponent', 'React.FunctionComponent'].includes(typeName)) {
173
+ isReactComponent = true;
174
+ }
175
+ }
176
+ }
177
+ if (!isReactComponent) {
178
+ validate({
179
+ node,
180
+ fnName
181
+ });
182
+ }
183
+ }
184
+ },
185
+ Property(node) {
186
+ if (node.value.type === 'FunctionExpression') ;
187
+ }
188
+ };
189
+ }
190
+ };
191
+
75
192
  function getSetting(context, name) {
76
193
  return context.settings["agilebot/".concat(name)];
77
194
  }
@@ -2511,6 +2628,7 @@ var tssUnusedClasses = {
2511
2628
  var ruleFiles = /*#__PURE__*/Object.freeze({
2512
2629
  __proto__: null,
2513
2630
  rules_enforce_mui_icon_alias: enforceMuiIconAlias,
2631
+ rules_func_naming: funcNaming,
2514
2632
  rules_import_monorepo: importMonorepo,
2515
2633
  rules_intl_id_missing: intlIdMissing,
2516
2634
  rules_intl_id_naming: intlIdNaming,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agilebot/eslint-plugin",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "description": "Agilebot's ESLint plugin",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "dependencies": {
21
21
  "@typescript-eslint/utils": "~7.9.0",
22
22
  "eslint-plugin-react": "^7.34.1",
23
- "@agilebot/eslint-utils": "0.3.7"
23
+ "@agilebot/eslint-utils": "0.3.8"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "eslint": "^7.0.0 || ^8.0.0"