@blumintinc/eslint-plugin-blumint 0.1.2 → 0.1.3

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.
package/lib/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.testingAFunction = void 0;
4
3
  const array_methods_this_context_1 = require("./rules/array-methods-this-context");
5
4
  const export_if_in_doubt_1 = require("./rules/export-if-in-doubt");
6
5
  const extract_global_constants_1 = require("./rules/extract-global-constants");
@@ -14,7 +13,7 @@ const prefer_type_over_interface_1 = require("./rules/prefer-type-over-interface
14
13
  module.exports = {
15
14
  meta: {
16
15
  name: '@blumintinc/eslint-plugin-blumint',
17
- version: '0.1.2',
16
+ version: '0.1.3',
18
17
  },
19
18
  parseOptions: {
20
19
  ecmaVersion: 2020,
@@ -49,9 +48,4 @@ module.exports = {
49
48
  'prefer-type-over-interface': prefer_type_over_interface_1.preferTypeOverInterface,
50
49
  },
51
50
  };
52
- const testingAFunction = (input) => {
53
- const a = input?.A;
54
- return a;
55
- };
56
- exports.testingAFunction = testingAFunction;
57
51
  //# sourceMappingURL=index.js.map
@@ -50,7 +50,7 @@ exports.arrayMethodsThisContext = (0, createRule_1.createRule)({
50
50
  meta: {
51
51
  type: 'problem',
52
52
  docs: {
53
- description: 'Disallow async callbacks for Array.filter',
53
+ description: 'Prevent misuse of Array methods in OOP',
54
54
  recommended: 'error',
55
55
  },
56
56
  schema: [],
@@ -13,7 +13,8 @@ exports.extractGlobalConstants = (0, createRule_1.createRule)({
13
13
  const scope = context.getScope();
14
14
  const hasDependencies = node.declarations.some((declaration) => declaration.init &&
15
15
  ASTHelpers_1.ASTHelpers.declarationIncludesIdentifier(declaration.init));
16
- if (!hasDependencies && scope.type === 'function') {
16
+ if (!hasDependencies &&
17
+ (scope.type === 'function' || scope.type === 'block')) {
17
18
  const constName = node.declarations[0].id.name;
18
19
  context.report({
19
20
  node,
@@ -49,7 +50,7 @@ exports.extractGlobalConstants = (0, createRule_1.createRule)({
49
50
  meta: {
50
51
  type: 'suggestion',
51
52
  docs: {
52
- description: 'Extract constants/functions from React components to the global scope when possible',
53
+ description: 'Extract constants/functions to the global scope when possible',
53
54
  recommended: 'error',
54
55
  },
55
56
  schema: [],
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ASTHelpers = void 0;
4
- // import { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint';
5
4
  class ASTHelpers {
6
5
  static blockIncludesIdentifier(block) {
7
6
  for (const statement of block.body) {
@@ -15,10 +14,14 @@ class ASTHelpers {
15
14
  if (!node) {
16
15
  return false;
17
16
  }
18
- console.log('visting node of type', node.type);
19
17
  switch (node.type) {
20
18
  case 'BlockStatement':
21
- return ASTHelpers.blockIncludesIdentifier(node);
19
+ return node.body.some((statement) => statement.type === 'BlockStatement' &&
20
+ ASTHelpers.blockIncludesIdentifier(statement));
21
+ case 'IfStatement':
22
+ return (this.declarationIncludesIdentifier(node.test) ||
23
+ this.declarationIncludesIdentifier(node.consequent) ||
24
+ this.declarationIncludesIdentifier(node.alternate));
22
25
  case 'Identifier':
23
26
  return true;
24
27
  case 'SpreadElement':
@@ -64,39 +67,6 @@ class ASTHelpers {
64
67
  return false;
65
68
  }
66
69
  }
67
- // public static declarationIncludesIdentifier(
68
- // node: TSESTree.Expression | null,
69
- // ): boolean {
70
- // if (!node) {
71
- // return false;
72
- // }
73
- // switch (node.type) {
74
- // case 'Identifier':
75
- // return true;
76
- // case 'ArrayExpression':
77
- // return node.elements.some(
78
- // (element) =>
79
- // element &&
80
- // (element.type === 'SpreadElement'
81
- // ? ASTHelpers.declarationIncludesIdentifier(element.argument)
82
- // : ASTHelpers.declarationIncludesIdentifier(element)),
83
- // );
84
- // case 'ObjectExpression':
85
- // return node.properties.some((property) => {
86
- // if (property.type === 'Property') {
87
- // return ASTHelpers.declarationIncludesIdentifier(property.key);
88
- // } else if (property.type === 'SpreadElement') {
89
- // return ASTHelpers.declarationIncludesIdentifier(property.argument);
90
- // }
91
- // return false;
92
- // });
93
- // default:
94
- // return (
95
- // ASTHelpers.declarationIncludesIdentifier((node as any).left) ||
96
- // ASTHelpers.declarationIncludesIdentifier((node as any).right)
97
- // );
98
- // }
99
- // }
100
70
  static isNode(value) {
101
71
  return typeof value === 'object' && value !== null && 'type' in value;
102
72
  }
@@ -104,14 +74,12 @@ class ASTHelpers {
104
74
  if (node.type === 'ReturnStatement') {
105
75
  return true;
106
76
  }
107
- else if (node.type === 'IfStatement') {
108
- // Check both branches of the if statement
77
+ if (node.type === 'IfStatement') {
109
78
  const consequentHasReturn = ASTHelpers.hasReturnStatement(node.consequent);
110
79
  const alternateHasReturn = !!node.alternate && ASTHelpers.hasReturnStatement(node.alternate);
111
80
  return consequentHasReturn && alternateHasReturn;
112
81
  }
113
- else if (node.type === 'BlockStatement') {
114
- // Check all statements in the block
82
+ if (node.type === 'BlockStatement') {
115
83
  for (const statement of node.body) {
116
84
  if (ASTHelpers.hasReturnStatement(statement)) {
117
85
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blumintinc/eslint-plugin-blumint",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Custom eslint rules for use at BluMint",
5
5
  "keywords": [
6
6
  "eslint",