eslint-plugin-use-agnostic 1.0.0 → 1.2.0
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 +1 -1
- package/comments.config.js +10 -2
- package/jscomments/_commons/constants/bases.js +95 -0
- package/jscomments/agnostic20/constants/modules-comments.js +28 -14
- package/jscomments/directive21/constants/modules-comments.js +52 -25
- package/library/_commons/utilities/helpers.js +6 -29
- package/library/agnostic20/_commons/constants/bases.js +49 -49
- package/library/agnostic20/_commons/utilities/helpers.js +8 -8
- package/library/directive21/_commons/constants/bases.js +81 -123
- package/library/directive21/_commons/rules/import-rules.js +1 -1
- package/library/directive21/_commons/utilities/helpers.js +69 -52
- package/package.json +1 -1
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { exportNotStrategized } from "../../../_commons/constants/bases.js";
|
|
2
2
|
import {
|
|
3
|
-
USE_AGNOSTIC_LOGICS,
|
|
4
3
|
USE_AGNOSTIC_STRATEGIES,
|
|
5
4
|
commentedDirectivesArray,
|
|
6
5
|
strategiesArray,
|
|
7
6
|
commentedDirectives_extensionRules,
|
|
8
|
-
commentedDirectives_4RawImplementations,
|
|
9
7
|
commentedStrategies_commentedDirectives,
|
|
10
8
|
commentedDirectives_blockedImports,
|
|
11
9
|
} from "../constants/bases.js";
|
|
@@ -14,10 +12,11 @@ import {
|
|
|
14
12
|
isImportBlocked as commonsIsImportBlocked,
|
|
15
13
|
makeMessageFromCurrentFileResolvedDirective,
|
|
16
14
|
findSpecificViolationMessage as commonsFindSpecificViolationMessage,
|
|
17
|
-
|
|
15
|
+
getSourceCodeFromFilePath,
|
|
18
16
|
} from "../../../_commons/utilities/helpers.js";
|
|
19
17
|
|
|
20
18
|
/**
|
|
19
|
+
* @typedef {import('../../../../types/directive21/_commons/typedefs.js').SourceCode} SourceCode
|
|
21
20
|
* @typedef {import('../../../../types/directive21/_commons/typedefs.js').Context} Context
|
|
22
21
|
* @typedef {import('../../../../types/directive21/_commons/typedefs.js').CommentedDirective} CommentedDirective
|
|
23
22
|
* @typedef {import('../../../../types/directive21/_commons/typedefs.js').CommentedDirectiveWithoutUseAgnosticStrategies} CommentedDirectiveWithoutUseAgnosticStrategies
|
|
@@ -28,7 +27,7 @@ import {
|
|
|
28
27
|
* @typedef {import('../../../../types/directive21/_commons/typedefs.js').ExportDefaultDeclaration} ExportDefaultDeclaration
|
|
29
28
|
*/
|
|
30
29
|
|
|
31
|
-
/*
|
|
30
|
+
/* getCommentedDirectiveFromSourceCode */
|
|
32
31
|
|
|
33
32
|
/**
|
|
34
33
|
* Detects whether a string is single- or double-quoted.
|
|
@@ -70,7 +69,7 @@ const stripDoubleQuotes = (string) => {
|
|
|
70
69
|
};
|
|
71
70
|
|
|
72
71
|
/**
|
|
73
|
-
* Gets the commented directive of
|
|
72
|
+
* Gets the commented directive of a module from its ESLint SourceCode object.
|
|
74
73
|
*
|
|
75
74
|
* Accepted directives for the default Directive-First Architecture are (single or double quotes included):
|
|
76
75
|
* - `'use server logics'`, `"use server logics"` denoting a Server Logics Module.
|
|
@@ -79,24 +78,30 @@ const stripDoubleQuotes = (string) => {
|
|
|
79
78
|
* - `'use server components'`, `"use server components"` denoting a Server Components Module.
|
|
80
79
|
* - `'use client components'`, `"use client components"` denoting a Client Components Module.
|
|
81
80
|
* - `'use agnostic components'`, `"use agnostic components"` denoting an Agnostic Components Module.
|
|
82
|
-
* - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
|
|
83
81
|
* - `'use server functions'`, `"use server functions"` denoting a Server Functions Module.
|
|
84
82
|
* - `'use client contexts'`, `"use client contexts"` denoting a Client Contexts Module.
|
|
85
83
|
* - `'use agnostic conditions'`, `"use agnostic conditions"` denoting an Agnostic Conditions Module.
|
|
86
84
|
* - `'use agnostic strategies'`, `"use agnostic strategies"` denoting an Agnostic Strategies Module.
|
|
87
|
-
* @param {
|
|
85
|
+
* @param {SourceCode} sourceCode The ESLint SourceCode object.
|
|
88
86
|
* @returns The commented directive, or lack thereof via `null`. Given the strictness of this architecture, the lack of a directive is considered a mistake. (Though rules may provide the opportunity to declare a default, and configs with preset defaults may become provided.)
|
|
89
87
|
*/
|
|
90
|
-
export const
|
|
88
|
+
export const getCommentedDirectiveFromSourceCode = (sourceCode) => {
|
|
91
89
|
// gets the first comment from the source code
|
|
92
|
-
const
|
|
90
|
+
const rawFirstComment = sourceCode.getAllComments()[0];
|
|
91
|
+
|
|
92
|
+
const firstComment =
|
|
93
|
+
rawFirstComment.type === "Shebang"
|
|
94
|
+
? sourceCode.getAllComments()[1]
|
|
95
|
+
: rawFirstComment;
|
|
93
96
|
|
|
94
97
|
// returns null early if there is no first comment
|
|
95
98
|
if (!firstComment) return null;
|
|
96
99
|
|
|
97
|
-
// returns null early if the first comment is not on
|
|
98
|
-
if (firstComment.loc.start.line
|
|
99
|
-
|
|
100
|
+
// returns null early if the first comment is not on one of the first three lines
|
|
101
|
+
if (firstComment.loc.start.line > 3) return null;
|
|
102
|
+
|
|
103
|
+
// returns null early if the first comment is not on the first column
|
|
104
|
+
if (firstComment.loc.start.column !== 0) return null;
|
|
100
105
|
|
|
101
106
|
// gets the trimmed raw value of the first comment
|
|
102
107
|
const rawValue = firstComment.value.trim();
|
|
@@ -119,6 +124,58 @@ export const getCommentedDirectiveFromCurrentModule = (context) => {
|
|
|
119
124
|
return commentedDirective;
|
|
120
125
|
};
|
|
121
126
|
|
|
127
|
+
/* getCommentedDirectiveFromCurrentModule */
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Gets the commented directive of the current module.
|
|
131
|
+
*
|
|
132
|
+
* Accepted directives for the default Directive-First Architecture are (single or double quotes included):
|
|
133
|
+
* - `'use server logics'`, `"use server logics"` denoting a Server Logics Module.
|
|
134
|
+
* - `'use client logics'`, `"use client logics"` denoting a Client Logics Module.
|
|
135
|
+
* - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
|
|
136
|
+
* - `'use server components'`, `"use server components"` denoting a Server Components Module.
|
|
137
|
+
* - `'use client components'`, `"use client components"` denoting a Client Components Module.
|
|
138
|
+
* - `'use agnostic components'`, `"use agnostic components"` denoting an Agnostic Components Module.
|
|
139
|
+
* - `'use server functions'`, `"use server functions"` denoting a Server Functions Module.
|
|
140
|
+
* - `'use client contexts'`, `"use client contexts"` denoting a Client Contexts Module.
|
|
141
|
+
* - `'use agnostic conditions'`, `"use agnostic conditions"` denoting an Agnostic Conditions Module.
|
|
142
|
+
* - `'use agnostic strategies'`, `"use agnostic strategies"` denoting an Agnostic Strategies Module.
|
|
143
|
+
* @param {Context} context The ESLint rule's `context` object.
|
|
144
|
+
* @returns The commented directive, or lack thereof via `null`. Given the strictness of this architecture, the lack of a directive is considered a mistake. (Though rules may provide the opportunity to declare a default, and configs with preset defaults may become provided.)
|
|
145
|
+
*/
|
|
146
|
+
export const getCommentedDirectiveFromCurrentModule = (context) => {
|
|
147
|
+
const sourceCode = context.sourceCode;
|
|
148
|
+
const commentedDirective = getCommentedDirectiveFromSourceCode(sourceCode);
|
|
149
|
+
|
|
150
|
+
return commentedDirective;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/* getCommentedDirectiveFromImportedModule */
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Gets the commented directive of the imported module.
|
|
157
|
+
*
|
|
158
|
+
* Accepted directives for the default Directive-First Architecture are (single or double quotes included):
|
|
159
|
+
* - `'use server logics'`, `"use server logics"` denoting a Server Logics Module.
|
|
160
|
+
* - `'use client logics'`, `"use client logics"` denoting a Client Logics Module.
|
|
161
|
+
* - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
|
|
162
|
+
* - `'use server components'`, `"use server components"` denoting a Server Components Module.
|
|
163
|
+
* - `'use client components'`, `"use client components"` denoting a Client Components Module.
|
|
164
|
+
* - `'use agnostic components'`, `"use agnostic components"` denoting an Agnostic Components Module.
|
|
165
|
+
* - `'use server functions'`, `"use server functions"` denoting a Server Functions Module.
|
|
166
|
+
* - `'use client contexts'`, `"use client contexts"` denoting a Client Contexts Module.
|
|
167
|
+
* - `'use agnostic conditions'`, `"use agnostic conditions"` denoting an Agnostic Conditions Module.
|
|
168
|
+
* - `'use agnostic strategies'`, `"use agnostic strategies"` denoting an Agnostic Strategies Module.
|
|
169
|
+
* @param {string} resolvedPath The resolved path of the imported module.
|
|
170
|
+
* @returns The commented directive, or lack thereof via `null`. Given the strictness of this architecture, the lack of a directive is considered a mistake. (Though rules may provide the opportunity to declare a default, and configs with preset defaults may become provided.)
|
|
171
|
+
*/
|
|
172
|
+
export const getCommentedDirectiveFromImportedModule = (resolvedPath) => {
|
|
173
|
+
const sourceCode = getSourceCodeFromFilePath(resolvedPath);
|
|
174
|
+
const commentedDirective = getCommentedDirectiveFromSourceCode(sourceCode);
|
|
175
|
+
|
|
176
|
+
return commentedDirective;
|
|
177
|
+
};
|
|
178
|
+
|
|
122
179
|
/* getVerifiedCommentedDirective */
|
|
123
180
|
|
|
124
181
|
/**
|
|
@@ -148,46 +205,6 @@ export const getVerifiedCommentedDirective = (directive, extension) => {
|
|
|
148
205
|
return null; // verification failed
|
|
149
206
|
};
|
|
150
207
|
|
|
151
|
-
/* getCommentedDirectiveFromImportedModule */
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Gets the commented directive of the imported module.
|
|
155
|
-
*
|
|
156
|
-
* Accepted directives for the default Directive-First Architecture are (single or double quotes included):
|
|
157
|
-
* - `'use server logics'`, `"use server logics"` denoting a Server Logics Module.
|
|
158
|
-
* - `'use client logics'`, `"use client logics"` denoting a Client Logics Module.
|
|
159
|
-
* - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
|
|
160
|
-
* - `'use server components'`, `"use server components"` denoting a Server Components Module.
|
|
161
|
-
* - `'use client components'`, `"use client components"` denoting a Client Components Module.
|
|
162
|
-
* - `'use agnostic components'`, `"use agnostic components"` denoting an Agnostic Components Module.
|
|
163
|
-
* - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
|
|
164
|
-
* - `'use server functions'`, `"use server functions"` denoting a Server Functions Module.
|
|
165
|
-
* - `'use client contexts'`, `"use client contexts"` denoting a Client Contexts Module.
|
|
166
|
-
* - `'use agnostic conditions'`, `"use agnostic conditions"` denoting an Agnostic Conditions Module.
|
|
167
|
-
* - `'use agnostic strategies'`, `"use agnostic strategies"` denoting an Agnostic Strategies Module.
|
|
168
|
-
* @param {string} resolvedImportPath The resolved path of the import.
|
|
169
|
-
* @returns The commented directive, or lack thereof via `null`. Given the strictness of this architecture, the lack of a directive is considered a mistake. (Though rules may provide the opportunity to declare a default, and configs with preset defaults may become provided.)
|
|
170
|
-
*/
|
|
171
|
-
export const getCommentedDirectiveFromImportedModule = (resolvedImportPath) => {
|
|
172
|
-
// gets the first line of the code of the import
|
|
173
|
-
const importedFileFirstLine = getImportedFileFirstLine(resolvedImportPath);
|
|
174
|
-
|
|
175
|
-
// sees if the first line includes any of the directives and finds the directive that it includes, with USE_AGNOSTIC_LOGICS as a default
|
|
176
|
-
const includedDirective = commentedDirectivesArray.reduce((acc, curr) => {
|
|
177
|
-
if (importedFileFirstLine.includes(curr)) return curr;
|
|
178
|
-
else return acc;
|
|
179
|
-
}, USE_AGNOSTIC_LOGICS);
|
|
180
|
-
|
|
181
|
-
// sees if the first line is strictly equal to one of the four raw implementations of the commented directive and returns that directive if true or null if false
|
|
182
|
-
if (
|
|
183
|
-
commentedDirectives_4RawImplementations[includedDirective].some(
|
|
184
|
-
(raw) => raw === importedFileFirstLine
|
|
185
|
-
)
|
|
186
|
-
)
|
|
187
|
-
return includedDirective;
|
|
188
|
-
else return null;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
208
|
/* getStrategizedDirective */
|
|
192
209
|
|
|
193
210
|
/**
|