eslint-plugin-use-agnostic 1.7.4 → 1.7.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.
@@ -57,6 +57,66 @@ import { analyzeExportsForReExports } from "./analyze-exports-re.js";
57
57
 
58
58
  /* currentFileFlow */
59
59
 
60
+ // copied from eXtra JSX (further proving that all core constants and utilities from eXtra JSX should live inside use-agnostic)
61
+
62
+ /**
63
+ * @type {readonly [".x.jsx", ".x.cjsx", ".x.mjsx", ".x.tsx", ".x.ctsx", ".x.mtsx"]}
64
+ */
65
+ export const eXtraJsxExtensions = Object.freeze([
66
+ ".x.jsx",
67
+ ".x.cjsx",
68
+ ".x.mjsx",
69
+ ".x.tsx",
70
+ ".x.ctsx",
71
+ ".x.mtsx",
72
+ ]);
73
+
74
+ /**
75
+ * @type {readonly [".x.js", ".x.cjs", ".x.mjs", ".x.ts", ".x.cts", ".x.mts"]}
76
+ */
77
+ export const eXtraJsExtensions = Object.freeze([
78
+ ".x.js",
79
+ ".x.cjs",
80
+ ".x.mjs",
81
+ ".x.ts",
82
+ ".x.cts",
83
+ ".x.mts",
84
+ ]);
85
+
86
+ /**
87
+ * @type {readonly [".x.jsx", ".x.cjsx", ".x.mjsx", ".x.tsx", ".x.ctsx", ".x.mtsx", ".x.js", ".x.cjs", ".x.mjs", ".x.ts", ".x.cts", ".x.mts"]}
88
+ */
89
+ export const extraJavaScriptExtensions = Object.freeze([
90
+ ...eXtraJsxExtensions,
91
+ ...eXtraJsExtensions,
92
+ ]);
93
+
94
+ /**
95
+ * $COMMENT#JSDOC#CORE#DEFS#FILEISANYJAVASCRIPT
96
+ * @param {string} filePath $COMMENT#JSDOC#CORE#PARAMS#FILEPATH
97
+ * @returns $COMMENT#JSDOC#CORE#RETURNS#FILEISANYJAVASCRIPT
98
+ */
99
+ export const fileIsAnyJavaScript = (filePath) =>
100
+ EXTENSIONS.some((e) => filePath.endsWith(e));
101
+
102
+ /**
103
+ * $COMMENT#JSDOC#CORE#DEFS#FILEISEXTRAJAVASCRIPT
104
+ * @param {string} filePath $COMMENT#JSDOC#CORE#PARAMS#FILEPATH
105
+ * @returns $COMMENT#JSDOC#CORE#RETURNS#FILEISEXTRAJAVASCRIPT
106
+ */
107
+ export const fileIsExtraJavaScript = (filePath) =>
108
+ extraJavaScriptExtensions.some((e) => filePath.endsWith(e));
109
+
110
+ /**
111
+ * $COMMENT#JSDOC#CORE#DEFS#FILEISREGULARJAVASCRIPT
112
+ * @param {string} filePath $COMMENT#JSDOC#CORE#PARAMS#FILEPATH
113
+ * @returns $COMMENT#JSDOC#CORE#RETURNS#FILEISREGULARJAVASCRIPT
114
+ */
115
+ export const fileIsRegularJavaScript = (filePath) =>
116
+ fileIsAnyJavaScript(filePath) && !fileIsExtraJavaScript(filePath);
117
+
118
+ //
119
+
60
120
  /**
61
121
  * The flow that begins the import rules enforcement rule, retrieving the verified commented directive of the current file before comparing it to upcoming verified commented directives of the files it imports.
62
122
  * @param {Context} context The ESLint rule's `context` object.
@@ -130,16 +190,24 @@ export const currentFileFlow = (context) => {
130
190
  return { skip: undefined, verifiedCommentedDirective }; // at this time, behaves as if the new implementation didn't exist yet
131
191
  }
132
192
 
133
- context.report({
134
- loc: highlightFirstLineOfCode(context),
135
- messageId: commentedDirectiveReactDirectiveFailedMessageId,
136
- data: {
137
- // verifiedCommentedDirective
138
- verifiedCommentedDirective,
139
- // expectedReactDirectiveAsText
140
- expectedReactDirectiveAsText,
141
- },
142
- });
193
+ // NEW
194
+ // do not report if the module is a non-Extra JavaScript Agnostic Strategies Module, in order to allow them the freedom of doing whatever they want so they can behave in any which way they need to as convention files
195
+ if (
196
+ !(
197
+ fileIsRegularJavaScript(context.filename) &&
198
+ verifiedCommentedDirective === USE_AGNOSTIC_STRATEGIES
199
+ )
200
+ )
201
+ context.report({
202
+ loc: highlightFirstLineOfCode(context),
203
+ messageId: commentedDirectiveReactDirectiveFailedMessageId,
204
+ data: {
205
+ // verifiedCommentedDirective
206
+ verifiedCommentedDirective,
207
+ // expectedReactDirectiveAsText
208
+ expectedReactDirectiveAsText,
209
+ },
210
+ });
143
211
  return skipTrue;
144
212
  }
145
213
 
package/library/index.js CHANGED
@@ -53,6 +53,8 @@ export {
53
53
  commentedDirectives_commentedModules,
54
54
  } from "./_commons/constants/bases.js";
55
55
 
56
+ export { highlightFirstLineOfCode } from "./_commons/utilities/helpers.js";
57
+
56
58
  // agnostic20
57
59
 
58
60
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-use-agnostic",
3
- "version": "1.7.4",
3
+ "version": "1.7.6",
4
4
  "description": "Highlights problematic server-client imports in projects made with the Fullstack React Architecture.",
5
5
  "keywords": [
6
6
  "eslint",
package/types/index.d.ts CHANGED
@@ -45,6 +45,24 @@ export const commentedDirectives_commentedModules: Readonly<{
45
45
  "use agnostic strategies": "Agnostic Strategies Module";
46
46
  }>;
47
47
 
48
+ /**
49
+ * Gets the coordinates for the first line of code of a file.
50
+ * @param context An ESLint rule's `context` object.
51
+ * @returns The `context.report` `loc`-compatible coordinates for the first line of code of a file.
52
+ */
53
+ export const highlightFirstLineOfCode: (
54
+ context: RuleContext<string, readonly unknown[]>
55
+ ) => {
56
+ start: {
57
+ line: number;
58
+ column: number;
59
+ };
60
+ end: {
61
+ line: number;
62
+ column: number;
63
+ };
64
+ };
65
+
48
66
  // agnostic20
49
67
 
50
68
  // directives