comment-variables 1.0.0 → 1.1.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/comments.config.js +6 -2
- package/comments.config.json +5 -0
- package/generate.template.js +4 -0
- package/library/_commons/constants/bases.js +4 -4
- package/library/_commons/constants/rules.js +4 -1
- package/library/_commons/rules/compress.js +9 -1
- package/library/_commons/rules/resolve.js +23 -5
- package/library/_commons/utilities/flows.js +18 -4
- package/library/index.js +14 -9
- package/package.json +2 -2
package/comments.config.js
CHANGED
|
@@ -74,6 +74,8 @@ const data = {
|
|
|
74
74
|
"The flattened config data, with `$COMMENT` placeholders as keys and actual comments as values." /* $COMMENT#JSDOC#PARAMS#FLATTENEDCONFIGDATA */,
|
|
75
75
|
reversedFlattenedConfigData:
|
|
76
76
|
"The reversed flattened config data, with actual comments as keys and `$COMMENT` placeholders as values." /* $COMMENT#JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA */,
|
|
77
|
+
composedVariablesExclusives:
|
|
78
|
+
"The array of comment variables keys (implying their aliases as well) exclusively used to craft composed variables, that should be ignored by both the `resolve` and the `compress` commands." /* $COMMENT#JSDOC#PARAMS#COMPOSEDVARIABLESEXCLUSIVES */,
|
|
77
79
|
aliases_flattenedKeys:
|
|
78
80
|
"The dictionary that connects aliases to their original flattened keys in case an encountered placeholder is actually an alias." /* $COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS */,
|
|
79
81
|
ruleName:
|
|
@@ -110,16 +112,18 @@ const data = {
|
|
|
110
112
|
|
|
111
113
|
const ignores = ["README.md", "generate.template.js", "generate.example.js"];
|
|
112
114
|
|
|
113
|
-
// FORMER CLI FLAGS NOW TO BE INCLUDED INSIDE THE CONFIG ITSELF
|
|
114
|
-
|
|
115
115
|
const lintConfigImports = false; // can be omitted
|
|
116
116
|
const myIgnoresOnly = false; // can be omitted
|
|
117
117
|
|
|
118
|
+
// NEW
|
|
119
|
+
const composedVariablesExclusives = []; // can be omitted
|
|
120
|
+
|
|
118
121
|
const config = {
|
|
119
122
|
data,
|
|
120
123
|
ignores,
|
|
121
124
|
lintConfigImports,
|
|
122
125
|
myIgnoresOnly,
|
|
126
|
+
composedVariablesExclusives,
|
|
123
127
|
};
|
|
124
128
|
|
|
125
129
|
export default config;
|
package/comments.config.json
CHANGED
|
@@ -82,6 +82,11 @@
|
|
|
82
82
|
"key": "JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA",
|
|
83
83
|
"placeholder": "$COMMENT#JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA"
|
|
84
84
|
},
|
|
85
|
+
"composedVariablesExclusives": {
|
|
86
|
+
"value": "The array of comment variables keys (implying their aliases as well) exclusively used to craft composed variables, that should be ignored by both the `resolve` and the `compress` commands.",
|
|
87
|
+
"key": "JSDOC#PARAMS#COMPOSEDVARIABLESEXCLUSIVES",
|
|
88
|
+
"placeholder": "$COMMENT#JSDOC#PARAMS#COMPOSEDVARIABLESEXCLUSIVES"
|
|
89
|
+
},
|
|
85
90
|
"aliases_flattenedKeys": {
|
|
86
91
|
"value": "The dictionary that connects aliases to their original flattened keys in case an encountered placeholder is actually an alias.",
|
|
87
92
|
"key": "JSDOC#PARAMS#ALIASES_FLATTENEDKEYS",
|
package/generate.template.js
CHANGED
|
@@ -20,11 +20,15 @@ const ignores = [];
|
|
|
20
20
|
const lintConfigImports = false; // can be omitted
|
|
21
21
|
const myIgnoresOnly = false; // can be omitted
|
|
22
22
|
|
|
23
|
+
// NEW
|
|
24
|
+
const composedVariablesExclusives = []; // can be omitted
|
|
25
|
+
|
|
23
26
|
const config = {
|
|
24
27
|
data,
|
|
25
28
|
ignores,
|
|
26
29
|
lintConfigImports,
|
|
27
30
|
myIgnoresOnly,
|
|
31
|
+
composedVariablesExclusives,
|
|
28
32
|
};
|
|
29
33
|
|
|
30
34
|
export default config;
|
|
@@ -3,10 +3,10 @@ import path from "path";
|
|
|
3
3
|
|
|
4
4
|
import { cwd } from "comment-variables-resolve-config";
|
|
5
5
|
|
|
6
|
-
// rule names
|
|
7
|
-
export const resolveRuleName = "resolve";
|
|
8
|
-
export const compressRuleName = "compress";
|
|
9
|
-
export const placeholdersRuleName = "placeholders"; // rule?
|
|
6
|
+
// rule names (now inside "comment-variables-resolve-config")
|
|
7
|
+
// export const resolveRuleName = "resolve";
|
|
8
|
+
// export const compressRuleName = "compress";
|
|
9
|
+
// export const placeholdersRuleName = "placeholders"; // rule?
|
|
10
10
|
|
|
11
11
|
// to prevent accidental changes
|
|
12
12
|
export const hasPackageJson = fs.existsSync(path.join(cwd, "package.json"));
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
resolveRuleName,
|
|
3
|
+
compressRuleName,
|
|
4
|
+
} from "comment-variables-resolve-config";
|
|
2
5
|
|
|
3
6
|
import makeResolveRule from "../rules/resolve.js";
|
|
4
7
|
import makeCompressRule from "../rules/compress.js";
|
|
@@ -7,14 +7,18 @@ import {
|
|
|
7
7
|
/**
|
|
8
8
|
* The utility that creates the compress rule based on the reversed flattened config data, used to transform actual comments into `$COMMENT` placeholders.
|
|
9
9
|
* @param {{[key: string]: string}} reversedFlattenedConfigData The reversed flattened config data, with actual comments as keys and `$COMMENT` placeholders as values.
|
|
10
|
+
* @param {string[]} composedVariablesExclusives The array of comment variables keys (implying their aliases as well) exclusively used to craft composed variables, that should be ignored by both the `resolve` and the `compress` commands.
|
|
10
11
|
* @returns The compress rule based on the reversed flattened config data.
|
|
11
12
|
*/
|
|
12
|
-
const makeRule = (reversedFlattenedConfigData) => {
|
|
13
|
+
const makeRule = (reversedFlattenedConfigData, composedVariablesExclusives) => {
|
|
13
14
|
/** The whole `reversedFlattenedConfigData` turned from an object to an array of key-value arrays sorted by the descending length of each key to prevent partial replacements. */
|
|
14
15
|
const sortedReversedFlattenedConfigData = Object.entries(
|
|
15
16
|
reversedFlattenedConfigData
|
|
16
17
|
).sort(([a], [b]) => b.length - a.length);
|
|
17
18
|
|
|
19
|
+
// makes a set out of composed variables exclusives
|
|
20
|
+
const composedVariablesExclusivesSet = new Set(composedVariablesExclusives);
|
|
21
|
+
|
|
18
22
|
/** @type {import('@typescript-eslint/utils').TSESLint.RuleModule<typeof placeholderMessageId, []>} */
|
|
19
23
|
const rule = {
|
|
20
24
|
meta: {
|
|
@@ -44,6 +48,10 @@ const makeRule = (reversedFlattenedConfigData) => {
|
|
|
44
48
|
resolvedValue,
|
|
45
49
|
commentKey,
|
|
46
50
|
] of sortedReversedFlattenedConfigData) {
|
|
51
|
+
// NEW
|
|
52
|
+
// if (composedVariablesExclusives.some((e) => commentKey === e))
|
|
53
|
+
if (composedVariablesExclusivesSet.has(commentKey)) continue;
|
|
54
|
+
|
|
47
55
|
const pattern = makeIsolatedStringRegex(resolvedValue);
|
|
48
56
|
|
|
49
57
|
fixedText = fixedText.replace(pattern, () => {
|
|
@@ -6,10 +6,18 @@ import {
|
|
|
6
6
|
/**
|
|
7
7
|
* The utility that creates the resolve rule based on the flattened config data, used to transform `$COMMENT` placeholders into actual comments.
|
|
8
8
|
* @param {{[key: string]: string}} flattenedConfigData The flattened config data, with `$COMMENT` placeholders as keys and actual comments as values.
|
|
9
|
+
* @param {string[]} composedVariablesExclusives The array of comment variables keys (implying their aliases as well) exclusively used to craft composed variables, that should be ignored by both the `resolve` and the `compress` commands.
|
|
9
10
|
* @param {{[key: string]: string}} aliases_flattenedKeys The dictionary that connects aliases to their original flattened keys in case an encountered placeholder is actually an alias.
|
|
10
11
|
* @returns The resolve rule based on the flattened config data.
|
|
11
12
|
*/
|
|
12
|
-
const makeRule = (
|
|
13
|
+
const makeRule = (
|
|
14
|
+
flattenedConfigData,
|
|
15
|
+
composedVariablesExclusives,
|
|
16
|
+
aliases_flattenedKeys
|
|
17
|
+
) => {
|
|
18
|
+
// makes a set out of composed variables exclusives
|
|
19
|
+
const composedVariablesExclusivesSet = new Set(composedVariablesExclusives);
|
|
20
|
+
|
|
13
21
|
/** @type {import('@typescript-eslint/utils').TSESLint.RuleModule<typeof placeholderMessageId, []>} */
|
|
14
22
|
const rule = {
|
|
15
23
|
meta: {
|
|
@@ -43,10 +51,20 @@ const makeRule = (flattenedConfigData, aliases_flattenedKeys) => {
|
|
|
43
51
|
|
|
44
52
|
for (const match of matches) {
|
|
45
53
|
const fullMatch = match[0]; // e.g. $COMMENT#LEVELONE#LEVELTWO
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
const rawKey = match[1]; // e.g. LEVELONE#LEVELTWO
|
|
55
|
+
const key =
|
|
56
|
+
aliases_flattenedKeys?.[rawKey] || // alias
|
|
57
|
+
rawKey; // original
|
|
58
|
+
const replacement = flattenedConfigData[key];
|
|
59
|
+
|
|
60
|
+
// NEW
|
|
61
|
+
// The idea is that only comment variables... Okay.
|
|
62
|
+
// The issue is that having a pattern is way too powerful, and can lead to unplanned inconsistencies. It is true that doing it instance by instance, comment variable by comment variable, is painstaking. But it's the more secure in order to fix an issue that is essentially purely cosmetic.
|
|
63
|
+
// Also, focusing exclusively on comment variables and barring aliases (and composed) solves many issues at once and can be checked within resolveConfig. // Done.
|
|
64
|
+
|
|
65
|
+
// if (replacement && composedVariablesExclusives.some((e) => key === e))
|
|
66
|
+
if (replacement && composedVariablesExclusivesSet.has(key)) continue;
|
|
67
|
+
|
|
50
68
|
if (replacement) {
|
|
51
69
|
fixedText = fixedText.replace(fullMatch, () => replacement);
|
|
52
70
|
hasValidFix = true;
|
|
@@ -5,13 +5,13 @@ import {
|
|
|
5
5
|
$COMMENT,
|
|
6
6
|
commentVariablesPluginName,
|
|
7
7
|
extractRuleName,
|
|
8
|
+
resolveRuleName,
|
|
9
|
+
compressRuleName,
|
|
8
10
|
typeScriptAndJSXCompatible,
|
|
9
11
|
extractObjectStringLiteralValues,
|
|
10
12
|
} from "comment-variables-resolve-config";
|
|
11
13
|
|
|
12
14
|
import {
|
|
13
|
-
resolveRuleName,
|
|
14
|
-
compressRuleName,
|
|
15
15
|
allJSTSFileGlobs,
|
|
16
16
|
allMDFileGlobs,
|
|
17
17
|
allMDVirtualJSTSFileGlobs,
|
|
@@ -25,6 +25,7 @@ import { ruleNames_makeRules } from "../constants/rules.js";
|
|
|
25
25
|
* @param {typeof resolveRuleName | typeof compressRuleName} ruleName The name of the rule currently used. (Either `"resolve"` or `"compress"`.)
|
|
26
26
|
* @param {string[]} ignores The array of paths and globs for the flow's ESLint instance to ignore.
|
|
27
27
|
* @param {{[key: string]: string}} flattenedConfigData Either the flattened config data or the reversed flattened config data, since they share the same structure.
|
|
28
|
+
* @param {string[]} composedVariablesExclusives The array of comment variables keys (implying their aliases as well) exclusively used to craft composed variables, that should be ignored by both the `resolve` and the `compress` commands.
|
|
28
29
|
* @param {Record<string, string> | undefined} aliases_flattenedKeys The dictionary that connects aliases to their original flattened keys in case an encountered placeholder is actually an alias.
|
|
29
30
|
* @returns
|
|
30
31
|
*/
|
|
@@ -32,6 +33,7 @@ const coreCommentsFlow = async (
|
|
|
32
33
|
ruleName,
|
|
33
34
|
ignores,
|
|
34
35
|
flattenedConfigData,
|
|
36
|
+
composedVariablesExclusives,
|
|
35
37
|
aliases_flattenedKeys
|
|
36
38
|
) => {
|
|
37
39
|
const eslint = new ESLint({
|
|
@@ -48,6 +50,7 @@ const coreCommentsFlow = async (
|
|
|
48
50
|
rules: {
|
|
49
51
|
[ruleName]: ruleNames_makeRules[ruleName](
|
|
50
52
|
flattenedConfigData,
|
|
53
|
+
composedVariablesExclusives,
|
|
51
54
|
aliases_flattenedKeys
|
|
52
55
|
),
|
|
53
56
|
},
|
|
@@ -105,18 +108,21 @@ const coreCommentsFlow = async (
|
|
|
105
108
|
* The flow that resolves `$COMMENT` placeholders into actual comments.
|
|
106
109
|
* @param {string[]} ignores The array of paths and globs for the flow's ESLint instance to ignore.
|
|
107
110
|
* @param {Record<string, string>} flattenedConfigData The flattened config data, with `$COMMENT` placeholders as keys and actual comments as values.
|
|
111
|
+
* @param {string[]} composedVariablesExclusives The array of comment variables keys (implying their aliases as well) exclusively used to craft composed variables, that should be ignored by both the `resolve` and the `compress` commands.
|
|
108
112
|
* @param {Record<string, string>} aliases_flattenedKeys The dictionary that connects aliases to their original flattened keys in case an encountered placeholder is actually an alias.
|
|
109
113
|
* @returns
|
|
110
114
|
*/
|
|
111
115
|
export const resolveCommentsFlow = async (
|
|
112
116
|
ignores,
|
|
113
117
|
flattenedConfigData,
|
|
118
|
+
composedVariablesExclusives,
|
|
114
119
|
aliases_flattenedKeys
|
|
115
120
|
) =>
|
|
116
121
|
coreCommentsFlow(
|
|
117
122
|
resolveRuleName,
|
|
118
123
|
ignores,
|
|
119
124
|
flattenedConfigData,
|
|
125
|
+
composedVariablesExclusives,
|
|
120
126
|
aliases_flattenedKeys
|
|
121
127
|
);
|
|
122
128
|
|
|
@@ -126,12 +132,20 @@ export const resolveCommentsFlow = async (
|
|
|
126
132
|
* The flow that compresses actual comments into `$COMMENT` placeholders.
|
|
127
133
|
* @param {string[]} ignores The array of paths and globs for the flow's ESLint instance to ignore.
|
|
128
134
|
* @param {{[key: string]: string}} reversedFlattenedConfigData The reversed flattened config data, with actual comments as keys and `$COMMENT` placeholders as values.
|
|
135
|
+
* @param {string[]} composedVariablesExclusives The array of comment variables keys (implying their aliases as well) exclusively used to craft composed variables, that should be ignored by both the `resolve` and the `compress` commands.
|
|
129
136
|
* @returns
|
|
130
137
|
*/
|
|
131
138
|
export const compressCommentsFlow = async (
|
|
132
139
|
ignores,
|
|
133
|
-
reversedFlattenedConfigData
|
|
134
|
-
|
|
140
|
+
reversedFlattenedConfigData,
|
|
141
|
+
composedVariablesExclusives
|
|
142
|
+
) =>
|
|
143
|
+
coreCommentsFlow(
|
|
144
|
+
compressRuleName,
|
|
145
|
+
ignores,
|
|
146
|
+
reversedFlattenedConfigData,
|
|
147
|
+
composedVariablesExclusives
|
|
148
|
+
);
|
|
135
149
|
|
|
136
150
|
/* placeholdersCommentsFlow */
|
|
137
151
|
|
package/library/index.js
CHANGED
|
@@ -9,19 +9,16 @@ import resolveConfig, {
|
|
|
9
9
|
defaultConfigFileName,
|
|
10
10
|
templateFileName,
|
|
11
11
|
exampleFileName,
|
|
12
|
+
resolveRuleName,
|
|
13
|
+
compressRuleName,
|
|
14
|
+
placeholdersRuleName,
|
|
12
15
|
configFlag,
|
|
13
16
|
cwd,
|
|
14
17
|
knownIgnores,
|
|
15
18
|
makeResolvedConfigData,
|
|
16
19
|
} from "comment-variables-resolve-config";
|
|
17
20
|
|
|
18
|
-
import {
|
|
19
|
-
hasPackageJson,
|
|
20
|
-
hasGitFolder,
|
|
21
|
-
resolveRuleName,
|
|
22
|
-
compressRuleName,
|
|
23
|
-
placeholdersRuleName,
|
|
24
|
-
} from "./_commons/constants/bases.js";
|
|
21
|
+
import { hasPackageJson, hasGitFolder } from "./_commons/constants/bases.js";
|
|
25
22
|
|
|
26
23
|
import { exitDueToFailure, logError } from "./_commons/utilities/helpers.js";
|
|
27
24
|
import {
|
|
@@ -128,6 +125,7 @@ const {
|
|
|
128
125
|
rawConfigAndImportPaths,
|
|
129
126
|
lintConfigImports,
|
|
130
127
|
myIgnoresOnly,
|
|
128
|
+
composedVariablesExclusives,
|
|
131
129
|
} = resolveConfigResults;
|
|
132
130
|
|
|
133
131
|
skipDetails || console.log("Running with config:", config);
|
|
@@ -140,9 +138,11 @@ skipDetails ||
|
|
|
140
138
|
skipDetails || console.log("Aliases are:", aliases_flattenedKeys);
|
|
141
139
|
skipDetails || console.log("Config path is:", configPath);
|
|
142
140
|
skipDetails || console.log("Passed ignores are:", passedIgnores);
|
|
143
|
-
// NEW
|
|
144
141
|
skipDetails || console.log("lintConfigImports is:", lintConfigImports);
|
|
145
142
|
skipDetails || console.log("myIgnoresOnly are:", myIgnoresOnly);
|
|
143
|
+
// NEW
|
|
144
|
+
skipDetails ||
|
|
145
|
+
console.log("composedVariablesExclusives are:", composedVariablesExclusives);
|
|
146
146
|
|
|
147
147
|
// ADDRESSES THE --lint-config-imports FLAG (lintConfigImports, no longer a flag), GIVEN THAT THE FILES IMPORTED BY THE CONFIG ARE IGNORED BY DEFAULT.
|
|
148
148
|
|
|
@@ -195,12 +195,17 @@ switch (coreCommand) {
|
|
|
195
195
|
await resolveCommentsFlow(
|
|
196
196
|
ignores,
|
|
197
197
|
flattenedConfigData,
|
|
198
|
+
composedVariablesExclusives,
|
|
198
199
|
aliases_flattenedKeys
|
|
199
200
|
);
|
|
200
201
|
break;
|
|
201
202
|
case compressRuleName:
|
|
202
203
|
console.log(`Running ${compressRuleName}...`);
|
|
203
|
-
await compressCommentsFlow(
|
|
204
|
+
await compressCommentsFlow(
|
|
205
|
+
ignores,
|
|
206
|
+
reversedFlattenedConfigData,
|
|
207
|
+
composedVariablesExclusives
|
|
208
|
+
);
|
|
204
209
|
break;
|
|
205
210
|
case placeholdersRuleName:
|
|
206
211
|
console.log(`Running ${placeholdersRuleName}...`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comment-variables",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A CLI tool for configuring, managing and maintaining JavaScript comments as JavaScript variables.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"comment-variables": "./library/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"type": "module",
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@eslint/markdown": "^6.5.0",
|
|
33
|
-
"comment-variables-resolve-config": "^1.
|
|
33
|
+
"comment-variables-resolve-config": "^1.14.1",
|
|
34
34
|
"eslint": "^9.29.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|