comment-variables 0.12.1 → 0.12.2

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.
@@ -41,6 +41,9 @@ const data = {
41
41
  // emptyString: "", // errors, string is empty
42
42
  // "": "emptyKey", // errors, key is empty caught by the regex
43
43
  // ownAliasKey: "LEVELONE#LEVELTWO#OWNALIASKEY", // errors, is its own key/alias
44
+ // key: "key not allowed", // errors, "key", "value" and "placeholder" not allowed
45
+ // value: "value not allowed", // errors, "key", "value" and "placeholder" not allowed
46
+ // placeholder: "placeholder not allowed", // errors, "key", "value" and "placeholder" not allowed
44
47
  },
45
48
  },
46
49
  // for deving
@@ -1,42 +1,154 @@
1
1
  {
2
2
  "levelOne": {
3
3
  "levelTwo": {
4
- "levelThree": "Level three.",
5
- "levelThreeEscape": "Level three. fdff",
6
- "stillLevelThree": "Level three.",
7
- "otherLevelThree": "Level three.",
8
- "composedVariable": "Level three. Level three.",
9
- "composedVariableAlias": "Level three. Level three."
4
+ "levelThree": {
5
+ "value": "Level three.",
6
+ "key": "LEVELONE#LEVELTWO#LEVELTHREE",
7
+ "placeholder": "$COMMENT#LEVELONE#LEVELTWO#LEVELTHREE"
8
+ },
9
+ "levelThreeEscape": {
10
+ "value": "Level three. fdff",
11
+ "key": "LEVELONE#LEVELTWO#LEVELTHREEESCAPE",
12
+ "placeholder": "$COMMENT#LEVELONE#LEVELTWO#LEVELTHREEESCAPE"
13
+ },
14
+ "stillLevelThree": {
15
+ "value": "Level three.",
16
+ "key": "LEVELONE#LEVELTWO#STILLLEVELTHREE",
17
+ "placeholder": "$COMMENT#LEVELONE#LEVELTWO#STILLLEVELTHREE"
18
+ },
19
+ "otherLevelThree": {
20
+ "value": "Level three.",
21
+ "key": "LEVELONE#LEVELTWO#OTHERLEVELTHREE",
22
+ "placeholder": "$COMMENT#LEVELONE#LEVELTWO#OTHERLEVELTHREE"
23
+ },
24
+ "composedVariable": {
25
+ "value": "Level three. Level three.",
26
+ "key": "LEVELONE#LEVELTWO#COMPOSEDVARIABLE",
27
+ "placeholder": "$COMMENT#LEVELONE#LEVELTWO#COMPOSEDVARIABLE"
28
+ },
29
+ "composedVariableAlias": {
30
+ "value": "Level three. Level three.",
31
+ "key": "LEVELONE#LEVELTWO#COMPOSEDVARIABLEALIAS",
32
+ "placeholder": "$COMMENT#LEVELONE#LEVELTWO#COMPOSEDVARIABLEALIAS"
33
+ }
10
34
  }
11
35
  },
12
36
  "jsDoc": {
13
37
  "definitions": {
14
- "exitDueToFailure": "Terminates the whole process with a 'failure' code (`1`).",
15
- "makeRuleResolve": "The utility that creates the resolve rule based on the flattened config data, used to transform `$COMMENT` placeholders into actual comments.",
16
- "makeRuleCompress": "The utility that creates the compress rule based on the reversed flattened config data, used to transform actual comments into `$COMMENT` placeholders.",
17
- "coreCommentsFlow": "The core flow at the heart of resolving and compressing comments.",
18
- "resolveCommentsFlow": "The flow that resolves `$COMMENT` placeholders into actual comments.",
19
- "compressCommentsFlow": "The flow that compresses actual comments into `$COMMENT` placeholders.",
20
- "placeholdersCommentsFlow": "The flow that creates `$COMMENT` placeholders right next to where they're defined.",
21
- "logError": "Logs an error to the console depending on its type. (`\"error\"` or `\"warning\"`.)"
38
+ "exitDueToFailure": {
39
+ "value": "Terminates the whole process with a 'failure' code (`1`).",
40
+ "key": "JSDOC#DEFINITIONS#EXITDUETOFAILURE",
41
+ "placeholder": "$COMMENT#JSDOC#DEFINITIONS#EXITDUETOFAILURE"
42
+ },
43
+ "makeRuleResolve": {
44
+ "value": "The utility that creates the resolve rule based on the flattened config data, used to transform `$COMMENT` placeholders into actual comments.",
45
+ "key": "JSDOC#DEFINITIONS#MAKERULERESOLVE",
46
+ "placeholder": "$COMMENT#JSDOC#DEFINITIONS#MAKERULERESOLVE"
47
+ },
48
+ "makeRuleCompress": {
49
+ "value": "The utility that creates the compress rule based on the reversed flattened config data, used to transform actual comments into `$COMMENT` placeholders.",
50
+ "key": "JSDOC#DEFINITIONS#MAKERULECOMPRESS",
51
+ "placeholder": "$COMMENT#JSDOC#DEFINITIONS#MAKERULECOMPRESS"
52
+ },
53
+ "coreCommentsFlow": {
54
+ "value": "The core flow at the heart of resolving and compressing comments.",
55
+ "key": "JSDOC#DEFINITIONS#CORECOMMENTSFLOW",
56
+ "placeholder": "$COMMENT#JSDOC#DEFINITIONS#CORECOMMENTSFLOW"
57
+ },
58
+ "resolveCommentsFlow": {
59
+ "value": "The flow that resolves `$COMMENT` placeholders into actual comments.",
60
+ "key": "JSDOC#DEFINITIONS#RESOLVECOMMENTSFLOW",
61
+ "placeholder": "$COMMENT#JSDOC#DEFINITIONS#RESOLVECOMMENTSFLOW"
62
+ },
63
+ "compressCommentsFlow": {
64
+ "value": "The flow that compresses actual comments into `$COMMENT` placeholders.",
65
+ "key": "JSDOC#DEFINITIONS#COMPRESSCOMMENTSFLOW",
66
+ "placeholder": "$COMMENT#JSDOC#DEFINITIONS#COMPRESSCOMMENTSFLOW"
67
+ },
68
+ "placeholdersCommentsFlow": {
69
+ "value": "The flow that creates `$COMMENT` placeholders right next to where they're defined.",
70
+ "key": "JSDOC#DEFINITIONS#PLACEHOLDERSCOMMENTSFLOW",
71
+ "placeholder": "$COMMENT#JSDOC#DEFINITIONS#PLACEHOLDERSCOMMENTSFLOW"
72
+ },
73
+ "logError": {
74
+ "value": "Logs an error to the console depending on its type. (`\"error\"` or `\"warning\"`.)",
75
+ "key": "JSDOC#DEFINITIONS#LOGERROR",
76
+ "placeholder": "$COMMENT#JSDOC#DEFINITIONS#LOGERROR"
77
+ }
22
78
  },
23
79
  "params": {
24
- "flattenedConfigData": "The flattened config data, with `$COMMENT` placeholders as keys and actual comments as values.",
25
- "reversedFlattenedConfigData": "The reversed flattened config data, with actual comments as keys and `$COMMENT` placeholders as values.",
26
- "aliases_flattenedKeys": "The dictionary that connects aliases to their original flattened keys in case an encountered placeholder is actually an alias.",
27
- "ruleName": "The name of the rule currently used. (Either `\"resolve\"` or `\"compress\"`.)",
28
- "ignores": "The array of paths and globs for the flow's ESLint instance to ignore.",
29
- "eitherFlattenedConfigData": "Either the flattened config data or the reversed flattened config data, since they share the same structure.",
30
- "error": "The error object being handle for the logging.",
31
- "options": "The additional options as follows:",
32
- "settings": "The required settings as follows:",
33
- "configPathIgnores": "The array of paths linked to the config file, (named \"ignores\" given it is ignored by the \"compress\" and \"resolve\" commands).",
34
- "originalFlattenedConfigData": "The original flattened config data, before changes to Aliases Variables and Composed Variables are applied."
80
+ "flattenedConfigData": {
81
+ "value": "The flattened config data, with `$COMMENT` placeholders as keys and actual comments as values.",
82
+ "key": "JSDOC#PARAMS#FLATTENEDCONFIGDATA",
83
+ "placeholder": "$COMMENT#JSDOC#PARAMS#FLATTENEDCONFIGDATA"
84
+ },
85
+ "reversedFlattenedConfigData": {
86
+ "value": "The reversed flattened config data, with actual comments as keys and `$COMMENT` placeholders as values.",
87
+ "key": "JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA",
88
+ "placeholder": "$COMMENT#JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA"
89
+ },
90
+ "aliases_flattenedKeys": {
91
+ "value": "The dictionary that connects aliases to their original flattened keys in case an encountered placeholder is actually an alias.",
92
+ "key": "JSDOC#PARAMS#ALIASES_FLATTENEDKEYS",
93
+ "placeholder": "$COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS"
94
+ },
95
+ "ruleName": {
96
+ "value": "The name of the rule currently used. (Either `\"resolve\"` or `\"compress\"`.)",
97
+ "key": "JSDOC#PARAMS#RULENAME",
98
+ "placeholder": "$COMMENT#JSDOC#PARAMS#RULENAME"
99
+ },
100
+ "ignores": {
101
+ "value": "The array of paths and globs for the flow's ESLint instance to ignore.",
102
+ "key": "JSDOC#PARAMS#IGNORES",
103
+ "placeholder": "$COMMENT#JSDOC#PARAMS#IGNORES"
104
+ },
105
+ "eitherFlattenedConfigData": {
106
+ "value": "Either the flattened config data or the reversed flattened config data, since they share the same structure.",
107
+ "key": "JSDOC#PARAMS#EITHERFLATTENEDCONFIGDATA",
108
+ "placeholder": "$COMMENT#JSDOC#PARAMS#EITHERFLATTENEDCONFIGDATA"
109
+ },
110
+ "error": {
111
+ "value": "The error object being handle for the logging.",
112
+ "key": "JSDOC#PARAMS#ERROR",
113
+ "placeholder": "$COMMENT#JSDOC#PARAMS#ERROR"
114
+ },
115
+ "options": {
116
+ "value": "The additional options as follows:",
117
+ "key": "JSDOC#PARAMS#OPTIONS",
118
+ "placeholder": "$COMMENT#JSDOC#PARAMS#OPTIONS"
119
+ },
120
+ "settings": {
121
+ "value": "The required settings as follows:",
122
+ "key": "JSDOC#PARAMS#SETTINGS",
123
+ "placeholder": "$COMMENT#JSDOC#PARAMS#SETTINGS"
124
+ },
125
+ "configPathIgnores": {
126
+ "value": "The array of paths linked to the config file, (named \"ignores\" given it is ignored by the \"compress\" and \"resolve\" commands).",
127
+ "key": "JSDOC#PARAMS#CONFIGPATHIGNORES",
128
+ "placeholder": "$COMMENT#JSDOC#PARAMS#CONFIGPATHIGNORES"
129
+ },
130
+ "originalFlattenedConfigData": {
131
+ "value": "The original flattened config data, before changes to Aliases Variables and Composed Variables are applied.",
132
+ "key": "JSDOC#PARAMS#ORIGINALFLATTENEDCONFIGDATA",
133
+ "placeholder": "$COMMENT#JSDOC#PARAMS#ORIGINALFLATTENEDCONFIGDATA"
134
+ }
35
135
  },
36
136
  "returns": {
37
- "exitDueToFailure": "Never. (Somehow typing needs to be explicit for unreachable code inference.)",
38
- "makeRuleResolve": "The resolve rule based on the flattened config data.",
39
- "makeRuleCompress": "The compress rule based on the reversed flattened config data."
137
+ "exitDueToFailure": {
138
+ "value": "Never. (Somehow typing needs to be explicit for unreachable code inference.)",
139
+ "key": "JSDOC#RETURNS#EXITDUETOFAILURE",
140
+ "placeholder": "$COMMENT#JSDOC#RETURNS#EXITDUETOFAILURE"
141
+ },
142
+ "makeRuleResolve": {
143
+ "value": "The resolve rule based on the flattened config data.",
144
+ "key": "JSDOC#RETURNS#MAKERULERESOLVE",
145
+ "placeholder": "$COMMENT#JSDOC#RETURNS#MAKERULERESOLVE"
146
+ },
147
+ "makeRuleCompress": {
148
+ "value": "The compress rule based on the reversed flattened config data.",
149
+ "key": "JSDOC#RETURNS#MAKERULECOMPRESS",
150
+ "placeholder": "$COMMENT#JSDOC#RETURNS#MAKERULECOMPRESS"
151
+ }
40
152
  }
41
153
  }
42
154
  }
@@ -5,9 +5,9 @@ import {
5
5
  } from "comment-variables-resolve-config";
6
6
 
7
7
  /**
8
- * The utility that creates the compress rule based on the reversed flattened config data, used to transform actual comments into `$COMMENT` placeholders.
9
- * @param {{[key: string]: string}} reversedFlattenedConfigData The reversed flattened config data, with actual comments as keys and `$COMMENT` placeholders as values.
10
- * @returns The compress rule based on the reversed flattened config data.
8
+ * $COMMENT#JSDOC#DEFINITIONS#MAKERULECOMPRESS
9
+ * @param {{[key: string]: string}} reversedFlattenedConfigData $COMMENT#JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA
10
+ * @returns $COMMENT#JSDOC#RETURNS#MAKERULECOMPRESS
11
11
  */
12
12
  const makeRule = (reversedFlattenedConfigData) => {
13
13
  /** 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. */
@@ -4,10 +4,10 @@ import {
4
4
  } from "comment-variables-resolve-config";
5
5
 
6
6
  /**
7
- * The utility that creates the resolve rule based on the flattened config data, used to transform `$COMMENT` placeholders into actual comments.
8
- * @param {{[key: string]: string}} flattenedConfigData The flattened config data, with `$COMMENT` placeholders as keys and actual comments as values.
9
- * @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
- * @returns The resolve rule based on the flattened config data.
7
+ * $COMMENT#JSDOC#DEFINITIONS#MAKERULERESOLVE
8
+ * @param {{[key: string]: string}} flattenedConfigData $COMMENT#JSDOC#PARAMS#FLATTENEDCONFIGDATA
9
+ * @param {{[key: string]: string}} aliases_flattenedKeys $COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS
10
+ * @returns $COMMENT#JSDOC#RETURNS#MAKERULERESOLVE
11
11
  */
12
12
  const makeRule = (flattenedConfigData, aliases_flattenedKeys) => {
13
13
  /** @type {import('@typescript-eslint/utils').TSESLint.RuleModule<typeof placeholderMessageId, []>} */
@@ -47,9 +47,8 @@ const makeRule = (flattenedConfigData, aliases_flattenedKeys) => {
47
47
  const replacement =
48
48
  flattenedConfigData[key] || // original
49
49
  flattenedConfigData[aliases_flattenedKeys?.[key]]; // alias
50
-
51
50
  if (replacement) {
52
- fixedText = fixedText.replace(fullMatch, replacement);
51
+ fixedText = fixedText.replace(fullMatch, () => replacement);
53
52
  hasValidFix = true;
54
53
  }
55
54
  }
@@ -21,11 +21,11 @@ import { ruleNames_makeRules } from "../constants/rules.js";
21
21
  /* coreCommentsFlow */
22
22
 
23
23
  /**
24
- * The core flow at the heart of resolving and compressing comments.
25
- * @param {typeof resolveRuleName | typeof compressRuleName} ruleName The name of the rule currently used. (Either `"resolve"` or `"compress"`.)
26
- * @param {string[]} ignores The array of paths and globs for the flow's ESLint instance to ignore.
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 {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.
24
+ * $COMMENT#JSDOC#DEFINITIONS#CORECOMMENTSFLOW
25
+ * @param {typeof resolveRuleName | typeof compressRuleName} ruleName $COMMENT#JSDOC#PARAMS#RULENAME
26
+ * @param {string[]} ignores $COMMENT#JSDOC#PARAMS#IGNORES
27
+ * @param {{[key: string]: string}} flattenedConfigData $COMMENT#JSDOC#PARAMS#EITHERFLATTENEDCONFIGDATA
28
+ * @param {Record<string, string> | undefined} aliases_flattenedKeys $COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS
29
29
  * @returns
30
30
  */
31
31
  const coreCommentsFlow = async (
@@ -104,10 +104,10 @@ const coreCommentsFlow = async (
104
104
  /* resolveCommentsFlow */
105
105
 
106
106
  /**
107
- * The flow that resolves `$COMMENT` placeholders into actual comments.
108
- * @param {string[]} ignores The array of paths and globs for the flow's ESLint instance to ignore.
109
- * @param {Record<string, string>} flattenedConfigData The flattened config data, with `$COMMENT` placeholders as keys and actual comments as values.
110
- * @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.
107
+ * $COMMENT#JSDOC#DEFINITIONS#RESOLVECOMMENTSFLOW
108
+ * @param {string[]} ignores $COMMENT#JSDOC#PARAMS#IGNORES
109
+ * @param {Record<string, string>} flattenedConfigData $COMMENT#JSDOC#PARAMS#FLATTENEDCONFIGDATA
110
+ * @param {Record<string, string>} aliases_flattenedKeys $COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS
111
111
  * @returns
112
112
  */
113
113
  export const resolveCommentsFlow = async (
@@ -125,9 +125,9 @@ export const resolveCommentsFlow = async (
125
125
  /* compressCommentsFlow */
126
126
 
127
127
  /**
128
- * The flow that compresses actual comments into `$COMMENT` placeholders.
129
- * @param {string[]} ignores The array of paths and globs for the flow's ESLint instance to ignore.
130
- * @param {{[key: string]: string}} reversedFlattenedConfigData The reversed flattened config data, with actual comments as keys and `$COMMENT` placeholders as values.
128
+ * $COMMENT#JSDOC#DEFINITIONS#COMPRESSCOMMENTSFLOW
129
+ * @param {string[]} ignores $COMMENT#JSDOC#PARAMS#IGNORES
130
+ * @param {{[key: string]: string}} reversedFlattenedConfigData $COMMENT#JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA
131
131
  * @returns
132
132
  */
133
133
  export const compressCommentsFlow = async (
@@ -138,10 +138,10 @@ export const compressCommentsFlow = async (
138
138
  /* placeholdersCommentsFlow */
139
139
 
140
140
  /**
141
- * The flow that creates `$COMMENT` placeholders right next to where they're defined.
142
- * @param {string[]} configPathIgnores The array of paths linked to the config file, (named "ignores" given it is ignored by the "compress" and "resolve" commands).
143
- * @param {{[k: string]: string;}} originalFlattenedConfigData The original flattened config data, before changes to Aliases Variables and Composed Variables are applied.
144
- * @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.
141
+ * $COMMENT#JSDOC#DEFINITIONS#PLACEHOLDERSCOMMENTSFLOW
142
+ * @param {string[]} configPathIgnores $COMMENT#JSDOC#PARAMS#CONFIGPATHIGNORES
143
+ * @param {{[k: string]: string;}} originalFlattenedConfigData $COMMENT#JSDOC#PARAMS#ORIGINALFLATTENEDCONFIGDATA
144
+ * @param {Record<string, string>} aliases_flattenedKeys $COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS
145
145
  * @returns
146
146
  */
147
147
  export const placeholdersCommentsFlow = async (
@@ -1,16 +1,16 @@
1
1
  /* exitDueToFailure */
2
2
 
3
3
  /**
4
- * Terminates the whole process with a 'failure' code (`1`).
5
- * @returns {never} Never. (Somehow typing needs to be explicit for unreachable code inference.)
4
+ * $COMMENT#JSDOC#DEFINITIONS#EXITDUETOFAILURE
5
+ * @returns {never} $COMMENT#JSDOC#RETURNS#EXITDUETOFAILURE
6
6
  */
7
7
  export const exitDueToFailure = () => process.exit(1);
8
8
 
9
9
  /* logError */
10
10
 
11
11
  /**
12
- * Logs an error to the console depending on its type. (`"error"` or `"warning"`.)
13
- * @param {{type: "error" | "warning"; message: string}} error The error object being handle for the logging.
12
+ * $COMMENT#JSDOC#DEFINITIONS#LOGERROR
13
+ * @param {{type: "error" | "warning"; message: string}} error $COMMENT#JSDOC#PARAMS#ERROR
14
14
  * @returns
15
15
  */
16
16
  export const logError = (error) => {
package/library/index.js CHANGED
@@ -136,7 +136,10 @@ if (!makeResolvedConfigDataResults.success) {
136
136
  }
137
137
 
138
138
  const resolvedConfigData = makeResolvedConfigDataResults.resolvedConfigData;
139
- const jsonPath = resolveConfigResults.configPath.replace(/\.js$/, ".json");
139
+ const jsonPath = resolveConfigResults.configPath.replace(
140
+ /\.js$/,
141
+ () => ".json"
142
+ );
140
143
  const jsonData = JSON.stringify(resolvedConfigData, null, 2);
141
144
  fs.writeFileSync(jsonPath, jsonData, "utf8");
142
145
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comment-variables",
3
- "version": "0.12.1",
3
+ "version": "0.12.2",
4
4
  "description": "A CLI tool for configuring, managing and maintaining JavaScript comments as JavaScript variables.",
5
5
  "bin": {
6
6
  "jscomments": "./library/index.js",
@@ -27,7 +27,7 @@
27
27
  "type": "module",
28
28
  "dependencies": {
29
29
  "@eslint/markdown": "^6.5.0",
30
- "comment-variables-resolve-config": "^1.9.4",
30
+ "comment-variables-resolve-config": "^1.10.1",
31
31
  "eslint": "^9.29.0"
32
32
  },
33
33
  "devDependencies": {