@blumintinc/eslint-plugin-blumint 0.1.4-s → 0.1.6

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
@@ -13,7 +13,7 @@ const prefer_type_over_interface_1 = require("./rules/prefer-type-over-interface
13
13
  module.exports = {
14
14
  meta: {
15
15
  name: '@blumintinc/eslint-plugin-blumint',
16
- version: '0.1.4',
16
+ version: '0.1.5',
17
17
  },
18
18
  parseOptions: {
19
19
  ecmaVersion: 2020,
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.exportIfInDoubt = void 0;
4
+ /* eslint-disable @blumintinc/blumint/extract-global-constants */
5
+ // import { ASTHelpers } from '../utils/ASTHelpers';
4
6
  const createRule_1 = require("../utils/createRule");
5
7
  exports.exportIfInDoubt = (0, createRule_1.createRule)({
6
- name: 'always-export',
8
+ name: 'export-if-in-doubt',
7
9
  meta: {
8
10
  type: 'suggestion',
9
11
  docs: {
@@ -17,18 +19,50 @@ exports.exportIfInDoubt = (0, createRule_1.createRule)({
17
19
  },
18
20
  defaultOptions: [],
19
21
  create(context) {
22
+ // List of top-level declarations
23
+ // List of exported identifiers
24
+ const topLevelDeclarations = [];
25
+ const exportedIdentifiers = [];
20
26
  return {
21
27
  'Program > VariableDeclaration > VariableDeclarator, Program > FunctionDeclaration, Program > TSTypeAliasDeclaration'(node) {
22
- if ((node.parent && node.parent.type !== 'ExportNamedDeclaration') ||
23
- (node.parent &&
24
- node.parent.parent &&
25
- node.parent.parent.type !== 'ExportNamedDeclaration')) {
26
- context.report({
27
- node,
28
- messageId: 'exportIfInDoubt',
28
+ topLevelDeclarations.push(node);
29
+ },
30
+ ExportNamedDeclaration: (node) => {
31
+ if (node.specifiers) {
32
+ node.specifiers.forEach((specifier) => {
33
+ if (specifier.type === 'ExportSpecifier') {
34
+ // Handle both normal and default export
35
+ const exportedName = specifier.exported.name;
36
+ if (!exportedIdentifiers.includes(exportedName)) {
37
+ exportedIdentifiers.push(exportedName);
38
+ }
39
+ // If the specifier is a default export
40
+ if (specifier.local.name !== exportedName) {
41
+ const localName = specifier.local.name;
42
+ if (!exportedIdentifiers.includes(localName)) {
43
+ exportedIdentifiers.push(localName);
44
+ }
45
+ }
46
+ }
29
47
  });
30
48
  }
31
49
  },
50
+ 'Program:exit': () => {
51
+ topLevelDeclarations.forEach((node) => {
52
+ if ('id' in node &&
53
+ node.id &&
54
+ (node.type === 'VariableDeclarator' ||
55
+ node.type === 'FunctionDeclaration' ||
56
+ node.type === 'TSTypeAliasDeclaration') &&
57
+ node.id.type === 'Identifier' &&
58
+ !exportedIdentifiers.includes(node.id.name)) {
59
+ context.report({
60
+ node,
61
+ messageId: 'exportIfInDoubt',
62
+ });
63
+ }
64
+ });
65
+ },
32
66
  };
33
67
  },
34
68
  });
@@ -99,6 +99,26 @@ class ASTHelpers {
99
99
  }
100
100
  return false;
101
101
  }
102
+ static isNodeExported(node) {
103
+ // Checking if the node is exported as a named export.
104
+ if (node.parent && node.parent.type === 'ExportNamedDeclaration') {
105
+ return true;
106
+ }
107
+ // Checking if the node is exported as default.
108
+ if (node.parent &&
109
+ node.parent.parent &&
110
+ node.parent.parent.type === 'ExportDefaultDeclaration') {
111
+ return true;
112
+ }
113
+ // Checking if the node is exported in a list of exports.
114
+ if (node.parent &&
115
+ node.parent.parent &&
116
+ node.parent.parent.type === 'ExportSpecifier' &&
117
+ node.parent.parent.exported.name === node.name) {
118
+ return true;
119
+ }
120
+ return false;
121
+ }
102
122
  }
103
123
  exports.ASTHelpers = ASTHelpers;
104
124
  //# sourceMappingURL=ASTHelpers.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blumintinc/eslint-plugin-blumint",
3
- "version": "0.1.4s",
3
+ "version": "0.1.6",
4
4
  "description": "Custom eslint rules for use at BluMint",
5
5
  "keywords": [
6
6
  "eslint",