eslint-plugin-crisp 1.0.72 → 1.0.74

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/README.md CHANGED
@@ -83,6 +83,7 @@ Each item has emojis denoting:
83
83
  | [no-restricted-syntax](https://eslint.org/docs/latest/rules/no-restricted-syntax) | Enforces `switch` `case`'s content to be enclosed in braces | | 🟢 |
84
84
  | [no-tabs](https://eslint.org/docs/latest/rules/no-tabs) | Disallows tabs | 🟠 | 🟢 |
85
85
  | [no-trailing-spaces](https://eslint.org/docs/latest/rules/no-trailing-spaces) | Disallows trailing whitespace at the end of lines | 🟠 | 🟢 |
86
+ | [no-undef](https://eslint.org/docs/latest/rules/no-undef) | Disallows use of undeclared variables | 🟠 | 🟢 |
86
87
  | [no-unused-vars](https://eslint.org/docs/latest/rules/no-unused-vars) | Disallows unused variables | 🟠 | 🟢 |
87
88
  | [no-unsafe-optional-chaining](https://eslint.org/docs/latest/rules/no-unsafe-optional-chaining) | Disallows use of optional chaining in contexts where the `undefined` value is not allowed | 🟠 | 🟢 |
88
89
  | [object-curly-newline](https://eslint.org/docs/latest/rules/object-curly-newline) | Requires line breaks after opening and before closing braces | 🟠 | 🟢 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-crisp",
3
- "version": "1.0.72",
3
+ "version": "1.0.74",
4
4
  "description": "Custom ESLint Rules for Crisp",
5
5
  "author": "Crisp IM SAS",
6
6
  "main": "index.js",
@@ -94,6 +94,7 @@ module.exports = {
94
94
  ],
95
95
  "no-tabs": "error",
96
96
  "no-trailing-spaces": "error",
97
+ "no-undef": "error",
97
98
  "no-unused-vars": "warn",
98
99
  "no-unsafe-optional-chaining": "error",
99
100
  "object-curly-newline": [
package/recommended.js CHANGED
@@ -95,6 +95,7 @@ module.exports = {
95
95
  "no-mixed-spaces-and-tabs": "error",
96
96
  "no-tabs": "error",
97
97
  "no-trailing-spaces": "error",
98
+ "no-undef": "error",
98
99
  "no-unused-vars": "warn",
99
100
  "no-unsafe-optional-chaining": "error",
100
101
  "object-curly-newline": [
@@ -19,12 +19,11 @@ module.exports = {
19
19
  "PROJECT: HELPERS",
20
20
  "PROJECT: PLATFORMS",
21
21
  "PROJECT: LIBRARIES",
22
- // Add any other known groups here
22
+ // Add any other groups here
23
23
  ];
24
24
 
25
- let lastKnownGroupIndex = -1;
25
+ let lastGroupIndex = -1;
26
26
  const existingGroups = new Set();
27
- const sourceCode = context.getSourceCode();
28
27
 
29
28
  function findGroupIndex(comment) {
30
29
  const group = comment.value.trim().toUpperCase();
@@ -32,6 +31,7 @@ module.exports = {
32
31
  }
33
32
 
34
33
  function getRelativePositionMessage(currentGroupIndex, groupName) {
34
+ // Search for the nearest group that is present in the file
35
35
  for (let i = currentGroupIndex - 1; i >= 0; i--) {
36
36
  if (existingGroups.has(groupOrder[i])) {
37
37
  return `should be after '${groupOrder[i]}' group`;
@@ -45,56 +45,15 @@ module.exports = {
45
45
  return "is out of order";
46
46
  }
47
47
 
48
- function hasKnownGroupAfter(node) {
49
- let followingNode = node;
50
- while (followingNode = sourceCode.getTokenAfter(followingNode, { includeComments: true })) {
51
- if (followingNode.type === 'Line') {
52
- if (isGroupComment(followingNode)) {
53
- const groupIndex = findGroupIndex(followingNode);
54
-
55
- if (groupIndex !== -1) {
56
- return true;
57
- }
58
- }
59
- }
60
-
61
- if (followingNode.type === 'ImportDeclaration') {
62
- const commentsBefore = sourceCode.getCommentsBefore(followingNode);
63
- for (let i = commentsBefore.length - 1; i >= 0; i--) {
64
- const comment = commentsBefore[i];
65
- if (isGroupComment(comment)) {
66
- const groupIndex = findGroupIndex(comment);
67
- if (groupIndex !== -1) {
68
- return true;
69
- }
70
- break;
71
- }
72
- }
73
- }
74
- }
75
- return false;
76
- }
77
-
78
48
  function checkGroupOrder(node, currentGroupIndex, groupName) {
79
- if (currentGroupIndex === -1) { // Unknown group
80
- if (hasKnownGroupAfter(node)) {
81
- context.report({
82
- node,
83
- message: `Unknown import group '${groupName}' should be after all known groups.`,
84
- });
85
- }
86
- } else if (currentGroupIndex < lastKnownGroupIndex) {
49
+ if (currentGroupIndex < lastGroupIndex) {
87
50
  const positionMessage = getRelativePositionMessage(currentGroupIndex, groupName);
88
51
  context.report({
89
52
  node,
90
53
  message: `Import group '${groupName}' ${positionMessage}.`,
91
54
  });
92
55
  }
93
-
94
- if (currentGroupIndex !== -1) {
95
- lastKnownGroupIndex = Math.max(lastKnownGroupIndex, currentGroupIndex);
96
- }
97
-
56
+ lastGroupIndex = Math.max(lastGroupIndex, currentGroupIndex);
98
57
  existingGroups.add(groupName);
99
58
  }
100
59
 
@@ -110,16 +69,14 @@ module.exports = {
110
69
 
111
70
  function updateAndCheckGroup(node) {
112
71
  const comments = context.getSourceCode().getCommentsBefore(node);
113
-
114
72
  for (let i = comments.length - 1; i >= 0; i--) {
115
73
  const comment = comments[i];
116
-
117
74
  if (isGroupComment(comment)) {
118
75
  const groupName = comment.value.trim().toUpperCase();
119
76
  const groupIndex = findGroupIndex(comment);
120
-
121
- checkGroupOrder(node, groupIndex, groupName);
122
-
77
+ if (groupIndex !== -1) {
78
+ checkGroupOrder(node, groupIndex, groupName);
79
+ }
123
80
  break;
124
81
  }
125
82
  }