eslint-plugin-use-agnostic 0.6.1 → 0.8.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 +0 -4
- package/library/_commons/constants/bases.js +12 -1
- package/library/agnostic20/{constants → _commons/constants}/bases.js +2 -2
- package/library/agnostic20/{rules/import-rules-enforcement.js → _commons/rules/import-rules.js} +1 -2
- package/library/agnostic20/{utilities → _commons/utilities}/flows.js +2 -2
- package/library/agnostic20/{utilities → _commons/utilities}/helpers.js +2 -2
- package/library/agnostic20/config.js +5 -0
- package/library/directive21/{constants → _commons/constants}/bases.js +2 -2
- package/library/directive21/{rules/import-rules-enforcement.js → _commons/rules/import-rules.js} +1 -2
- package/library/directive21/{utilities → _commons/utilities}/flows.js +15 -5
- package/library/directive21/{utilities → _commons/utilities}/helpers.js +2 -2
- package/library/directive21/config.js +5 -0
- package/library/directive21/crossingStrategies/_commons/plugins/strategies.js +23 -0
- package/library/directive21/crossingStrategies/_commons/rules/defaults.js +56 -0
- package/library/directive21/crossingStrategies/_commons/rules/namespaces.js +61 -0
- package/library/directive21/crossingStrategies/_commons/rules/specifiers.js +64 -0
- package/library/directive21/crossingStrategies/config.js +67 -0
- package/library/index.js +2 -2
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -16,7 +16,6 @@ npm install eslint@^9.0.0 eslint-plugin-use-agnostic --save-dev
|
|
|
16
16
|
// eslint.config.js
|
|
17
17
|
|
|
18
18
|
import { defineConfig, globalIgnores } from "eslint/config";
|
|
19
|
-
import tseslint from "typescript-eslint"; // for compatibility with TypeScript, not included as a devDependency
|
|
20
19
|
|
|
21
20
|
import useAgnostic, {
|
|
22
21
|
useAgnosticPluginName,
|
|
@@ -32,9 +31,6 @@ export default defineConfig([
|
|
|
32
31
|
[useAgnosticPluginName]: useAgnostic,
|
|
33
32
|
},
|
|
34
33
|
extends: [`${useAgnosticPluginName}/${agnostic20ConfigName}`],
|
|
35
|
-
languageOptions: {
|
|
36
|
-
parser: tseslint.parser, // for compatibility with .ts and .tsx
|
|
37
|
-
},
|
|
38
34
|
},
|
|
39
35
|
]);
|
|
40
36
|
```
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/* plugin names */
|
|
2
|
+
// use-agnostic
|
|
2
3
|
export const useAgnosticPluginName = "use-agnostic";
|
|
4
|
+
// crossingStrategies
|
|
5
|
+
export const strategiesPluginName = "strategies";
|
|
3
6
|
|
|
4
7
|
/* config names */
|
|
5
8
|
// agnostic20
|
|
@@ -15,6 +18,14 @@ export const enforceEffectiveDirectivesRuleName =
|
|
|
15
18
|
export const enforceCommentedDirectivesRuleName =
|
|
16
19
|
"enforce-commented-directives-import-rules";
|
|
17
20
|
|
|
21
|
+
// crossingStrategies
|
|
22
|
+
export const verifySpecifierImportRuleName =
|
|
23
|
+
"verify-specifier-import-export-same-strategy";
|
|
24
|
+
export const verifyDefaultImportRuleName =
|
|
25
|
+
"verify-default-import-export-same-strategy";
|
|
26
|
+
export const verifyNamespaceImportRuleName =
|
|
27
|
+
"verify-namespace-import-export-some-strategy";
|
|
28
|
+
|
|
18
29
|
/* messageIds */
|
|
19
30
|
export const reExportNotSameMessageId = "re-export-not-same-directive";
|
|
20
31
|
// agnostic20
|
|
@@ -13,9 +13,9 @@ import {
|
|
|
13
13
|
CLIENT_COMPONENTS_MODULE as COMMONS_CLIENT_COMPONENTS_MODULE,
|
|
14
14
|
AGNOSTIC_LOGICS_MODULE as COMMONS_AGNOSTIC_LOGICS_MODULE,
|
|
15
15
|
AGNOSTIC_COMPONENTS_MODULE as COMMONS_AGNOSTIC_COMPONENTS_MODULE,
|
|
16
|
-
} from "
|
|
16
|
+
} from "../../../_commons/constants/bases.js";
|
|
17
17
|
|
|
18
|
-
import { makeIntroForSpecificViolationMessage as commonsMakeIntroForSpecificViolationMessage } from "
|
|
18
|
+
import { makeIntroForSpecificViolationMessage as commonsMakeIntroForSpecificViolationMessage } from "../../../_commons/utilities/helpers.js";
|
|
19
19
|
|
|
20
20
|
// directives
|
|
21
21
|
export const NO_DIRECTIVE = null;
|
package/library/agnostic20/{rules/import-rules-enforcement.js → _commons/rules/import-rules.js}
RENAMED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
reExportNotSameMessageId,
|
|
3
3
|
importBreaksEffectiveImportRulesMessageId,
|
|
4
4
|
useServerJSXMessageId,
|
|
5
|
-
} from "
|
|
5
|
+
} from "../../../_commons/constants/bases.js";
|
|
6
6
|
import {
|
|
7
7
|
currentFileEffectiveDirective,
|
|
8
8
|
importedFileEffectiveDirective,
|
|
@@ -25,7 +25,6 @@ const rule = {
|
|
|
25
25
|
"Enforces import rules based on the file's effective directive. ",
|
|
26
26
|
},
|
|
27
27
|
schema: [],
|
|
28
|
-
// currentFileEffectiveDirective, importedFileEffectiveDirective, effectiveDirectiveMessage, specificViolationMessage
|
|
29
28
|
messages: {
|
|
30
29
|
[reExportNotSameMessageId]: `The effective directives of this file and this re-export are dissimilar.
|
|
31
30
|
Here, "{{ ${currentFileEffectiveDirective} }}" and "{{ ${importedFileEffectiveDirective} }}" are not the same. Please re-export only from modules that have the same effective directive as the current module. `,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
useServerJSXMessageId,
|
|
6
6
|
importBreaksEffectiveImportRulesMessageId,
|
|
7
7
|
reExportNotSameMessageId,
|
|
8
|
-
} from "
|
|
8
|
+
} from "../../../_commons/constants/bases.js";
|
|
9
9
|
import {
|
|
10
10
|
USE_SERVER_LOGICS,
|
|
11
11
|
USE_SERVER_COMPONENTS,
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
specificViolationMessage,
|
|
21
21
|
} from "../constants/bases.js";
|
|
22
22
|
|
|
23
|
-
import { resolveImportPath } from "
|
|
23
|
+
import { resolveImportPath } from "../../../_commons/utilities/helpers.js";
|
|
24
24
|
import {
|
|
25
25
|
getDirectiveFromCurrentModule,
|
|
26
26
|
getDirectiveFromImportedModule,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
JS,
|
|
9
9
|
MJS,
|
|
10
10
|
CJS,
|
|
11
|
-
} from "
|
|
11
|
+
} from "../../../_commons/constants/bases.js";
|
|
12
12
|
import {
|
|
13
13
|
NO_DIRECTIVE,
|
|
14
14
|
USE_SERVER,
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
isImportBlocked as commonsIsImportBlocked,
|
|
33
33
|
makeMessageFromResolvedDirective,
|
|
34
34
|
findSpecificViolationMessage as commonsFindSpecificViolationMessage,
|
|
35
|
-
} from "
|
|
35
|
+
} from "../../../_commons/utilities/helpers.js";
|
|
36
36
|
|
|
37
37
|
/* getDirectiveFromCurrentModule */
|
|
38
38
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineConfig } from "eslint/config";
|
|
2
|
+
import tseslint from "typescript-eslint";
|
|
2
3
|
|
|
3
4
|
import {
|
|
4
5
|
agnostic20ConfigName,
|
|
@@ -19,6 +20,10 @@ export const makeAgnostic20Config = (plugin) => ({
|
|
|
19
20
|
[`${useAgnosticPluginName}/${enforceEffectiveDirectivesRuleName}`]:
|
|
20
21
|
"warn",
|
|
21
22
|
},
|
|
23
|
+
languageOptions: {
|
|
24
|
+
// for compatibility with .ts and .tsx
|
|
25
|
+
parser: tseslint.parser,
|
|
26
|
+
},
|
|
22
27
|
},
|
|
23
28
|
]),
|
|
24
29
|
});
|
|
@@ -19,9 +19,9 @@ import {
|
|
|
19
19
|
CLIENT_CONTEXTS_MODULE as COMMONS_CLIENT_CONTEXTS_MODULE,
|
|
20
20
|
AGNOSTIC_CONDITIONS_MODULE as COMMONS_AGNOSTIC_CONDITIONS_MODULE,
|
|
21
21
|
AGNOSTIC_STRATEGIES_MODULE as COMMONS_AGNOSTIC_STRATEGIES_MODULE,
|
|
22
|
-
} from "
|
|
22
|
+
} from "../../../_commons/constants/bases.js";
|
|
23
23
|
|
|
24
|
-
import { makeIntroForSpecificViolationMessage as commonsMakeIntroForSpecificViolationMessage } from "
|
|
24
|
+
import { makeIntroForSpecificViolationMessage as commonsMakeIntroForSpecificViolationMessage } from "../../../_commons/utilities/helpers.js";
|
|
25
25
|
|
|
26
26
|
// commented directives
|
|
27
27
|
export const USE_SERVER_LOGICS = COMMONS_USE_SERVER_LOGICS;
|
package/library/directive21/{rules/import-rules-enforcement.js → _commons/rules/import-rules.js}
RENAMED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
commentedDirectiveVerificationFailed,
|
|
6
6
|
importNotStrategized,
|
|
7
7
|
exportNotStrategized,
|
|
8
|
-
} from "
|
|
8
|
+
} from "../../../_commons/constants/bases.js";
|
|
9
9
|
import {
|
|
10
10
|
currentFileCommentedDirective,
|
|
11
11
|
importedFileCommentedDirective,
|
|
@@ -29,7 +29,6 @@ const rule = {
|
|
|
29
29
|
"Enforces import rules based on the file's commented directive. ",
|
|
30
30
|
},
|
|
31
31
|
schema: [],
|
|
32
|
-
// currentFileCommentedDirective, importedFileCommentedDirective, commentedDirectiveMessage, specificViolationMessage, specificFailure
|
|
33
32
|
messages: {
|
|
34
33
|
[reExportNotSameMessageId]: `The commented directives of this file (or Strategy) and this re-export are dissimilar.
|
|
35
34
|
Here, "{{ ${currentFileCommentedDirective} }}" and "{{ ${importedFileCommentedDirective} }}" are not the same. Please re-export only from modules that have the same commented directive as the current module. `,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
commentedDirectiveVerificationFailed,
|
|
9
9
|
importNotStrategized,
|
|
10
10
|
exportNotStrategized,
|
|
11
|
-
} from "
|
|
11
|
+
} from "../../../_commons/constants/bases.js";
|
|
12
12
|
import {
|
|
13
13
|
USE_SERVER_LOGICS,
|
|
14
14
|
USE_CLIENT_LOGICS,
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
specificFailure,
|
|
29
29
|
} from "../constants/bases.js";
|
|
30
30
|
|
|
31
|
-
import { resolveImportPath } from "
|
|
31
|
+
import { resolveImportPath } from "../../../_commons/utilities/helpers.js";
|
|
32
32
|
import {
|
|
33
33
|
getCommentedDirectiveFromCurrentModule,
|
|
34
34
|
getVerifiedCommentedDirective,
|
|
@@ -139,11 +139,21 @@ const importedFileFlow = (context, node) => {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
/* GETTING THE CORRECT DIRECTIVE INTERPRETATION OF STRATEGY FOR AGNOSTIC STRATEGIES MODULES IMPORTS.
|
|
142
|
-
(The Directive-First Architecture does not check whether the export and import Strategies are the same at this time, meaning a @clientLogics strategy could be wrongly imported and interpreted as a @serverLogics strategy.
|
|
142
|
+
(The Directive-First Architecture does not check whether the export and import Strategies are the same at this time, meaning a @clientLogics strategy could be wrongly imported and interpreted as a @serverLogics strategy.
|
|
143
|
+
|
|
144
|
+
After a short attempt, this feature is currently cancelled, mainly since the amount of work it will require will not be able to be transferred in a future where commented strategies will actually be real syntax.
|
|
145
|
+
|
|
146
|
+
However, Strategy exports are planned to be linting in the future within their own Agnostic Strategies Modules to ensure they respect import rules within their own scopes. It may also become possible to check whether the export and import Strategies are the same in the future when identifiers are defined and the same, especially for components modules where a convention could be to for all non-type export to be named and PascalCase.) */
|
|
143
147
|
if (importedFileCommentedDirective === USE_AGNOSTIC_STRATEGIES) {
|
|
144
|
-
|
|
148
|
+
const importingFileCommentedDirective = getStrategizedDirective(
|
|
149
|
+
context,
|
|
150
|
+
node
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
// FOR NOW, we consider the importingFileCommentedDirective (which is strategized) and the importedFileCommentedDirective (which should be strategized on its own imported file) to be same, given the limitation highlighted above.
|
|
154
|
+
importedFileCommentedDirective = importingFileCommentedDirective;
|
|
145
155
|
|
|
146
|
-
if (
|
|
156
|
+
if (importingFileCommentedDirective === null) {
|
|
147
157
|
context.report({
|
|
148
158
|
node,
|
|
149
159
|
messageId: importNotStrategized,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
commentedDirectiveVerificationFailed,
|
|
6
6
|
importNotStrategized,
|
|
7
7
|
exportNotStrategized,
|
|
8
|
-
} from "
|
|
8
|
+
} from "../../../_commons/constants/bases.js";
|
|
9
9
|
import {
|
|
10
10
|
USE_SERVER_LOGICS,
|
|
11
11
|
USE_CLIENT_LOGICS,
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
isImportBlocked as commonsIsImportBlocked,
|
|
31
31
|
makeMessageFromResolvedDirective,
|
|
32
32
|
findSpecificViolationMessage as commonsFindSpecificViolationMessage,
|
|
33
|
-
} from "
|
|
33
|
+
} from "../../../_commons/utilities/helpers.js";
|
|
34
34
|
|
|
35
35
|
/* getCommentedDirectiveFromCurrentModule */
|
|
36
36
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineConfig } from "eslint/config";
|
|
2
|
+
import tseslint from "typescript-eslint";
|
|
2
3
|
|
|
3
4
|
import {
|
|
4
5
|
directive21ConfigName,
|
|
@@ -19,6 +20,10 @@ export const makeDirective21Config = (plugin) => ({
|
|
|
19
20
|
[`${useAgnosticPluginName}/${enforceCommentedDirectivesRuleName}`]:
|
|
20
21
|
"warn",
|
|
21
22
|
},
|
|
23
|
+
languageOptions: {
|
|
24
|
+
// for compatibility with .ts and .tsx
|
|
25
|
+
parser: tseslint.parser,
|
|
26
|
+
},
|
|
22
27
|
},
|
|
23
28
|
]),
|
|
24
29
|
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
verifySpecifierImportRuleName,
|
|
3
|
+
verifyDefaultImportRuleName,
|
|
4
|
+
verifyNamespaceImportRuleName,
|
|
5
|
+
} from "../../../../_commons/constants/bases.js";
|
|
6
|
+
|
|
7
|
+
import verifySpecifierImportExportSameStrategy from "../rules/specifiers.js";
|
|
8
|
+
import verifyDefaultImportExportSameStrategy from "../rules/defaults.js";
|
|
9
|
+
import verifyNamespaceImportExportSomeStrategy from "../rules/namespaces.js";
|
|
10
|
+
|
|
11
|
+
// The name of the plugin is `strategies`.
|
|
12
|
+
// This is the strategies plugin.
|
|
13
|
+
|
|
14
|
+
/** @type {import('eslint').ESLint.Plugin} */
|
|
15
|
+
const plugin = {
|
|
16
|
+
rules: {
|
|
17
|
+
[verifySpecifierImportRuleName]: verifySpecifierImportExportSameStrategy,
|
|
18
|
+
[verifyDefaultImportRuleName]: verifyDefaultImportExportSameStrategy,
|
|
19
|
+
[verifyNamespaceImportRuleName]: verifyNamespaceImportExportSomeStrategy,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default plugin;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
USE_SERVER_LOGICS,
|
|
3
|
+
USE_CLIENT_LOGICS,
|
|
4
|
+
USE_AGNOSTIC_LOGICS,
|
|
5
|
+
USE_SERVER_COMPONENTS,
|
|
6
|
+
USE_CLIENT_COMPONENTS,
|
|
7
|
+
USE_AGNOSTIC_COMPONENTS,
|
|
8
|
+
USE_SERVER_FUNCTIONS,
|
|
9
|
+
USE_CLIENT_CONTEXTS,
|
|
10
|
+
USE_AGNOSTIC_CONDITIONS,
|
|
11
|
+
} from "../../../_commons/constants/bases.js";
|
|
12
|
+
|
|
13
|
+
// The name of the rule is `verify-default-import-export-same-strategy`.
|
|
14
|
+
// This is the verify-default-import-export-same-strategy rule.
|
|
15
|
+
|
|
16
|
+
/** @type {import('@typescript-eslint/utils').TSESLint.RuleModule<string, []>} */ // string for now
|
|
17
|
+
const rule = {
|
|
18
|
+
meta: {
|
|
19
|
+
type: "problem",
|
|
20
|
+
docs: {
|
|
21
|
+
description:
|
|
22
|
+
"Verifies that a default import and export have the same strategy. ",
|
|
23
|
+
},
|
|
24
|
+
schema: [
|
|
25
|
+
{
|
|
26
|
+
// importingFileCommentedDirective
|
|
27
|
+
enum: [
|
|
28
|
+
USE_SERVER_LOGICS,
|
|
29
|
+
USE_CLIENT_LOGICS,
|
|
30
|
+
USE_AGNOSTIC_LOGICS,
|
|
31
|
+
USE_SERVER_COMPONENTS,
|
|
32
|
+
USE_CLIENT_COMPONENTS,
|
|
33
|
+
USE_AGNOSTIC_COMPONENTS,
|
|
34
|
+
USE_SERVER_FUNCTIONS,
|
|
35
|
+
USE_CLIENT_CONTEXTS,
|
|
36
|
+
USE_AGNOSTIC_CONDITIONS,
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
// importedName (because stemming from the same makeConfig)
|
|
41
|
+
type: "undefined",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
messages: {},
|
|
45
|
+
},
|
|
46
|
+
create: (context) => {
|
|
47
|
+
return {
|
|
48
|
+
ExportDefaultDeclaration: (node) => {
|
|
49
|
+
console.log("verify-default-import-export-same-strategy");
|
|
50
|
+
console.log(node);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default rule; // verify-default-import-export-same-strategy
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
USE_SERVER_LOGICS,
|
|
3
|
+
USE_CLIENT_LOGICS,
|
|
4
|
+
USE_AGNOSTIC_LOGICS,
|
|
5
|
+
USE_SERVER_COMPONENTS,
|
|
6
|
+
USE_CLIENT_COMPONENTS,
|
|
7
|
+
USE_AGNOSTIC_COMPONENTS,
|
|
8
|
+
USE_SERVER_FUNCTIONS,
|
|
9
|
+
USE_CLIENT_CONTEXTS,
|
|
10
|
+
USE_AGNOSTIC_CONDITIONS,
|
|
11
|
+
} from "../../../_commons/constants/bases.js";
|
|
12
|
+
|
|
13
|
+
// The name of the rule is `verify-namespace-import-export-some-strategy`.
|
|
14
|
+
// This is the verify-namespace-import-export-some-strategy rule.
|
|
15
|
+
|
|
16
|
+
/** @type {import('@typescript-eslint/utils').TSESLint.RuleModule<string, []>} */ // string for now
|
|
17
|
+
const rule = {
|
|
18
|
+
meta: {
|
|
19
|
+
type: "problem",
|
|
20
|
+
docs: {
|
|
21
|
+
description:
|
|
22
|
+
"Verifies that a specifier's import and export have the same strategy. ",
|
|
23
|
+
},
|
|
24
|
+
schema: [
|
|
25
|
+
{
|
|
26
|
+
// importingFileCommentedDirective
|
|
27
|
+
enum: [
|
|
28
|
+
USE_SERVER_LOGICS,
|
|
29
|
+
USE_CLIENT_LOGICS,
|
|
30
|
+
USE_AGNOSTIC_LOGICS,
|
|
31
|
+
USE_SERVER_COMPONENTS,
|
|
32
|
+
USE_CLIENT_COMPONENTS,
|
|
33
|
+
USE_AGNOSTIC_COMPONENTS,
|
|
34
|
+
USE_SERVER_FUNCTIONS,
|
|
35
|
+
USE_CLIENT_CONTEXTS,
|
|
36
|
+
USE_AGNOSTIC_CONDITIONS,
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
// importedName (because stemming from the same makeConfig)
|
|
41
|
+
type: "undefined",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
messages: {},
|
|
45
|
+
},
|
|
46
|
+
create: (context) => {
|
|
47
|
+
return {
|
|
48
|
+
ExportSpecifier: (node) => {
|
|
49
|
+
console.log("verify-namespace-import-export-some-strategy");
|
|
50
|
+
console.log(node);
|
|
51
|
+
},
|
|
52
|
+
ExportNamedDeclaration: (node) => {
|
|
53
|
+
console.log("verify-namespace-import-export-some-strategy");
|
|
54
|
+
console.log("ExportNamedDeclaration");
|
|
55
|
+
console.log(node);
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default rule; // verify-namespace-import-export-some-strategy
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
USE_SERVER_LOGICS,
|
|
3
|
+
USE_CLIENT_LOGICS,
|
|
4
|
+
USE_AGNOSTIC_LOGICS,
|
|
5
|
+
USE_SERVER_COMPONENTS,
|
|
6
|
+
USE_CLIENT_COMPONENTS,
|
|
7
|
+
USE_AGNOSTIC_COMPONENTS,
|
|
8
|
+
USE_SERVER_FUNCTIONS,
|
|
9
|
+
USE_CLIENT_CONTEXTS,
|
|
10
|
+
USE_AGNOSTIC_CONDITIONS,
|
|
11
|
+
} from "../../../_commons/constants/bases.js";
|
|
12
|
+
|
|
13
|
+
// The name of the rule is `verify-specifier-import-export-same-strategy`.
|
|
14
|
+
// This is the verify-specifier-import-export-same-strategy rule.
|
|
15
|
+
|
|
16
|
+
/** @type {import('@typescript-eslint/utils').TSESLint.RuleModule<string, []>} */ // string for now
|
|
17
|
+
const rule = {
|
|
18
|
+
meta: {
|
|
19
|
+
type: "problem",
|
|
20
|
+
docs: {
|
|
21
|
+
description:
|
|
22
|
+
"Verifies that a specifier's import and export have the same strategy. ",
|
|
23
|
+
},
|
|
24
|
+
schema: [
|
|
25
|
+
{
|
|
26
|
+
// importingFileCommentedDirective
|
|
27
|
+
enum: [
|
|
28
|
+
USE_SERVER_LOGICS,
|
|
29
|
+
USE_CLIENT_LOGICS,
|
|
30
|
+
USE_AGNOSTIC_LOGICS,
|
|
31
|
+
USE_SERVER_COMPONENTS,
|
|
32
|
+
USE_CLIENT_COMPONENTS,
|
|
33
|
+
USE_AGNOSTIC_COMPONENTS,
|
|
34
|
+
USE_SERVER_FUNCTIONS,
|
|
35
|
+
USE_CLIENT_CONTEXTS,
|
|
36
|
+
USE_AGNOSTIC_CONDITIONS,
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
// importedName
|
|
41
|
+
type: "string",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
messages: {},
|
|
45
|
+
},
|
|
46
|
+
create: (context) => {
|
|
47
|
+
return {
|
|
48
|
+
// for hobbyists
|
|
49
|
+
ExportSpecifier: (node) => {
|
|
50
|
+
console.log("verify-specifier-import-export-same-strategy");
|
|
51
|
+
console.log(node.exported.name);
|
|
52
|
+
console.log(node);
|
|
53
|
+
},
|
|
54
|
+
// for people who drink their coffee black and their ASTs recursive
|
|
55
|
+
ExportNamedDeclaration: (node) => {
|
|
56
|
+
console.log("verify-specifier-import-export-same-strategy");
|
|
57
|
+
console.log("ExportNamedDeclaration");
|
|
58
|
+
console.log(node);
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export default rule; // verify-specifier-import-export-same-strategy
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { defineConfig } from "eslint/config";
|
|
2
|
+
import tseslint from "typescript-eslint";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
strategiesPluginName,
|
|
6
|
+
verifySpecifierImportRuleName,
|
|
7
|
+
verifyDefaultImportRuleName,
|
|
8
|
+
verifyNamespaceImportRuleName,
|
|
9
|
+
} from "../../_commons/constants/bases.js";
|
|
10
|
+
import {
|
|
11
|
+
USE_SERVER_LOGICS,
|
|
12
|
+
USE_CLIENT_LOGICS,
|
|
13
|
+
USE_AGNOSTIC_LOGICS,
|
|
14
|
+
USE_SERVER_COMPONENTS,
|
|
15
|
+
USE_CLIENT_COMPONENTS,
|
|
16
|
+
USE_AGNOSTIC_COMPONENTS,
|
|
17
|
+
USE_SERVER_FUNCTIONS,
|
|
18
|
+
USE_CLIENT_CONTEXTS,
|
|
19
|
+
USE_AGNOSTIC_CONDITIONS,
|
|
20
|
+
} from "../_commons/constants/bases.js";
|
|
21
|
+
|
|
22
|
+
import strategies from "./_commons/plugins/strategies.js";
|
|
23
|
+
|
|
24
|
+
// The name of the config is `crossingStrategies`.
|
|
25
|
+
// This is the crossingStrategies config.
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Makes the crossingStrategies config for specifiers, defaults, and namespaces.
|
|
29
|
+
* @param {"specifiers" | "defaults" | "namespaces"} type The type of the returned config, either "specifiers", "defaults", or "namespaces".
|
|
30
|
+
* @param {USE_SERVER_LOGICS | USE_CLIENT_LOGICS | USE_AGNOSTIC_LOGICS | USE_SERVER_COMPONENTS | USE_CLIENT_COMPONENTS | USE_AGNOSTIC_COMPONENTS | USE_SERVER_FUNCTIONS | USE_CLIENT_CONTEXTS | USE_AGNOSTIC_CONDITIONS} option1 importingFileCommentedDirective as option 1. (The strategy on the importing file.)
|
|
31
|
+
* @param {string | null} option2 importedName as option2 (The specifier's name on the importing file. Undefined when unnecessary.)
|
|
32
|
+
*/
|
|
33
|
+
export const makeCrossingStrategiesConfig = (type, option1, option2) => {
|
|
34
|
+
let ruleName = "";
|
|
35
|
+
|
|
36
|
+
switch (type) {
|
|
37
|
+
case "specifiers":
|
|
38
|
+
ruleName = verifySpecifierImportRuleName;
|
|
39
|
+
break;
|
|
40
|
+
case "defaults":
|
|
41
|
+
ruleName = verifyDefaultImportRuleName;
|
|
42
|
+
break;
|
|
43
|
+
case "namespaces":
|
|
44
|
+
ruleName = verifyNamespaceImportRuleName;
|
|
45
|
+
break;
|
|
46
|
+
default:
|
|
47
|
+
console.error(
|
|
48
|
+
"Type should only be 'specifiers', 'defaults', or 'namespaces'. This error should never be printed."
|
|
49
|
+
);
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return defineConfig([
|
|
54
|
+
{
|
|
55
|
+
plugins: {
|
|
56
|
+
[strategiesPluginName]: strategies,
|
|
57
|
+
},
|
|
58
|
+
rules: {
|
|
59
|
+
[`${strategiesPluginName}/${ruleName}`]: ["warn", option1, option2],
|
|
60
|
+
},
|
|
61
|
+
languageOptions: {
|
|
62
|
+
// for compatibility with .ts and .tsx
|
|
63
|
+
parser: tseslint.parser,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
]);
|
|
67
|
+
};
|
package/library/index.js
CHANGED
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
enforceCommentedDirectivesRuleName,
|
|
6
6
|
} from "./_commons/constants/bases.js";
|
|
7
7
|
|
|
8
|
-
import enforceEffectiveDirectivesImportRules from "./agnostic20/rules/import-rules
|
|
9
|
-
import enforceCommentedDirectivesImportRules from "./directive21/rules/import-rules
|
|
8
|
+
import enforceEffectiveDirectivesImportRules from "./agnostic20/_commons/rules/import-rules.js";
|
|
9
|
+
import enforceCommentedDirectivesImportRules from "./directive21/_commons/rules/import-rules.js";
|
|
10
10
|
|
|
11
11
|
import { makeAgnostic20Config } from "./agnostic20/config.js";
|
|
12
12
|
import { makeDirective21Config } from "./directive21/config.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-use-agnostic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Highlights problematic server-client imports in projects made with the Fullstack React Architecture.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -30,12 +30,17 @@
|
|
|
30
30
|
"type": "git",
|
|
31
31
|
"url": "git+https://github.com/LutherTS/eslint-plugin-use-agnostic.git"
|
|
32
32
|
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"test": "node tests/agnostic20/import-rules.test.js"
|
|
35
|
+
},
|
|
33
36
|
"dependencies": {
|
|
34
|
-
"tsconfig-paths": "^4.2.0"
|
|
37
|
+
"tsconfig-paths": "^4.2.0",
|
|
38
|
+
"typescript-eslint": "^8.32.0"
|
|
35
39
|
},
|
|
36
40
|
"devDependencies": {
|
|
37
41
|
"@typescript-eslint/utils": "^8.31.1",
|
|
38
|
-
"eslint": ">=9.0.0"
|
|
42
|
+
"eslint": ">=9.0.0",
|
|
43
|
+
"typescript": "^5.8.3"
|
|
39
44
|
},
|
|
40
45
|
"peerDependencies": {
|
|
41
46
|
"eslint": ">=9.0.0"
|