comment-variables 0.12.0 → 0.12.1

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 CHANGED
@@ -6,13 +6,13 @@ npm install -g comment-variables
6
6
 
7
7
  ## Commands
8
8
 
9
- **`comment-variables` comes with three commands in this initial release:**
9
+ **`comment-variables` (alias `jscomments`) comes with three commands in this initial release:**
10
10
 
11
11
  ```
12
12
  comment-variables
13
13
  ```
14
14
 
15
- Interacts with your `comments.config.js` default exported object to print all the parameters you need to be aware of before running `compress` or `resolve`. Also acts as a dry run validation check. If no error is printed, it means you can run `compress` or `resolve` safely, as long the printed parameters correspond to what you've expected from your defined config.
15
+ Interacts with your `comments.config.js` default exported object to print all the parameters you need to be aware of before running `compress` or `resolve`. Also acts as a dry run validation check. If no error is printed, it means you can run `compress` or `resolve` safely, as long the printed parameters correspond to what you've expected from your defined config. (Additionally creates a resolved version of your config data as a JSON file.)
16
16
 
17
17
  ```
18
18
  comment-variables compress
@@ -75,7 +75,7 @@ const data = {
75
75
  jsDoc: Object.freeze({
76
76
  definitions: Object.freeze({
77
77
  exitDueToFailure:
78
- "Terminates the whole process with a 'failure' code (1)." /* $COMMENT#JSDOC#DEFINITIONS#EXITDUETOFAILURE */,
78
+ "Terminates the whole process with a 'failure' code (`1`)." /* $COMMENT#JSDOC#DEFINITIONS#EXITDUETOFAILURE */,
79
79
  makeRuleResolve:
80
80
  "The utility that creates the resolve rule based on the flattened config data, used to transform `$COMMENT` placeholders into actual comments." /* $COMMENT#JSDOC#DEFINITIONS#MAKERULERESOLVE */,
81
81
  makeRuleCompress:
@@ -2,7 +2,7 @@ const data = {
2
2
  // for testing
3
3
  levelOne: {
4
4
  levelTwo: {
5
- levelThree: "Level three." /* $COMMENT#LEVELONE#LEVELTWO#LEVELTHREE */, // New placeholder structure. Not as sexy, but first and foremost guaranteed to be functional appended right at the end of the value as a Block comment, and last but not least also guaranteed to not modify Value Locations in the process. So `comment variables placeholders` it is, and this justifies enforcing strings only for values even outside of the use of the VS Code extension.
5
+ levelThree: "Level three." /* $COMMENT#LEVELONE#LEVELTWO#LEVELTHREE */, // New placeholder structure. Not as sexy, but first and foremost guaranteed to be functional appended right at the end of the value as a Block comment, and last but not least also guaranteed to not modify Value Locations in the process. So `comment-variables placeholders` it is, and this justifies enforcing strings only for values even outside of the use of the VS Code extension.
6
6
  levelThreeEscape:
7
7
  "Level three. \
8
8
  fdff\
@@ -12,12 +12,20 @@ const data = {
12
12
  otherLevelThree:
13
13
  "LEVELONE#LEVELTWO#LEVELTHREE" /* $COMMENT#LEVELONE#LEVELTWO#OTHERLEVELTHREE */, // also an alias
14
14
  composedVariable:
15
- "$COMMENT#LEVELONE#LEVELTWO#LEVELTHREE $COMMENT#LEVELONE#LEVELTWO#STILLLEVELTHREE" /* $COMMENT#LEVELONE#LEVELTWO#COMPOSEDVARIABLE */, // This is a composed variable. What's the beauty in this? It allows for each comment variable to be its own single source of truth that can be reused still within the Comment Variables ecosystem. All while preventing the use of comment variables placeholders as values in the config. AND as a matter of fact, it even works... with aliases.
15
+ "$COMMENT#LEVELONE#LEVELTWO#LEVELTHREE $COMMENT#LEVELONE#LEVELTWO#STILLLEVELTHREE" /* $COMMENT#LEVELONE#LEVELTWO#COMPOSEDVARIABLE */, // This is a composed variable. What's the beauty in this? It allows for each comment variable to be its own single source of truth that can be reused still within the Comment Variables ecosystem. All while preventing the use of Comment Variables placeholders as values in the config. AND as a matter of fact, it even works... with aliases.
16
16
  composedVariableAlias:
17
17
  "LEVELONE#LEVELTWO#COMPOSEDVARIABLE" /* $COMMENT#LEVELONE#LEVELTWO#COMPOSEDVARIABLEALIAS */, // The alias of a composed variable. SO just like composed variables can incorporate aliases, aliases can be aliases for composed variables.
18
18
 
19
19
  // otherLevelThreeAlias:
20
20
  // "LEVELONE#LEVELTWO#OTHERLEVELTHREE" /* $COMMENT#LEVELONE#LEVELTWO#LEVELTHREE */, // errors, can't be the alias of another alias
21
+
22
+ // composedOfAlias:
23
+ // "$COMMENT#LEVELONE#LEVELTWO#LEVELTHREE $COMMENT#LEVELONE#LEVELTWO#ALIASOFCOMPOSED" /* $COMMENT#LEVELONE#LEVELTWO#COMPOSEDOFALIAS */, // 1/2 already errored // ERROR. A potential composed variable cannot be used as the comment variable of another composed variable.
24
+ // aliasOfComposed:
25
+ // "LEVELONE#LEVELTWO#COMPOSEDOFALIAS" /* $COMMENT#LEVELONE#LEVELTWO#ALIASOFCOMPOSED */, // 2/2 What if an alias variable was a segment to a composed variable made of itself? // ERROR. The alias "LEVELONE#LEVELTWO#ALIASOFCOMPOSED" links to composed variable "$COMMENT#LEVELONE#LEVELTWO#LEVELTHREE $COMMENT#LEVELONE#LEVELTWO#ALIASOFCOMPOSED" that includes LEVELONE#LEVELTWO#ALIASOFCOMPOSED's placeholder as a segment.
26
+
27
+ // aliasInComposed:
28
+ // "$COMMENT#LEVELONE#LEVELTWO#LEVELTHREE $COMMENT#LEVELONE#LEVELTWO#ALIASINCOMPOSED", // What if a composed variable had its own value has one of its segments? Composed variables already cannot compose other composed variables. // errors, "ERROR. A potential composed variable cannot be used as the comment variable of another composed variable."
21
29
  // wrongComposedVariable:
22
30
  // "$COMMENT#LEVELONE#LEVELTWO#COMPOSEDVARIABLE $COMMENT#LEVELONE#LEVELTWO#STILLLEVELTHREE", // errors, can't make composed variables with composed variables
23
31
  // wrongComposedVariableToo:
@@ -28,7 +36,7 @@ const data = {
28
36
  // tooLevelThree: 2, // errors, value is invalid
29
37
  // $levelThree: "Dollar sign", // errors, key as "$" character
30
38
  // "#levelThree": "Hashtag", // errors, key as "#" character
31
- // ".levelThree": "Punctuation", // errors, key is invalid
39
+ // ".levelThree": "Punctuation", // errors, key is invalid due to punctuation
32
40
  // unrecognized: `Unrecognized value.`, // errors, is not a string literal
33
41
  // emptyString: "", // errors, string is empty
34
42
  // "": "emptyKey", // errors, key is empty caught by the regex
@@ -39,7 +47,7 @@ const data = {
39
47
  jsDoc: Object.freeze({
40
48
  definitions: Object.freeze({
41
49
  exitDueToFailure:
42
- "Terminates the whole process with a 'failure' code (1)." /* $COMMENT#JSDOC#DEFINITIONS#EXITDUETOFAILURE */,
50
+ "Terminates the whole process with a 'failure' code (`1`)." /* $COMMENT#JSDOC#DEFINITIONS#EXITDUETOFAILURE */,
43
51
  makeRuleResolve:
44
52
  "The utility that creates the resolve rule based on the flattened config data, used to transform `$COMMENT` placeholders into actual comments." /* $COMMENT#JSDOC#DEFINITIONS#MAKERULERESOLVE */,
45
53
  makeRuleCompress:
@@ -0,0 +1,42 @@
1
+ {
2
+ "levelOne": {
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."
10
+ }
11
+ },
12
+ "jsDoc": {
13
+ "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\"`.)"
22
+ },
23
+ "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."
35
+ },
36
+ "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."
40
+ }
41
+ }
42
+ }
@@ -5,12 +5,12 @@ import {
5
5
  } from "comment-variables-resolve-config";
6
6
 
7
7
  /**
8
- * $COMMENT#JSDOC#DEFINITIONS#MAKERULECOMPRESS
9
- * @param {{[key: string]: string}} reversedFlattenedConfigData $COMMENT#JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA
10
- * @returns $COMMENT#JSDOC#RETURNS#MAKERULECOMPRESS
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.
11
11
  */
12
12
  const makeRule = (reversedFlattenedConfigData) => {
13
- // Turns the whole reversedFlattenedConfig from an object to an array of key-value arrays sorted by the descending length of each key to prevent partial replacements.
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. */
14
14
  const sortedReversedFlattenedConfigData = Object.entries(
15
15
  reversedFlattenedConfigData
16
16
  ).sort(([a], [b]) => b.length - a.length);
@@ -4,10 +4,10 @@ import {
4
4
  } from "comment-variables-resolve-config";
5
5
 
6
6
  /**
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
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.
11
11
  */
12
12
  const makeRule = (flattenedConfigData, aliases_flattenedKeys) => {
13
13
  /** @type {import('@typescript-eslint/utils').TSESLint.RuleModule<typeof placeholderMessageId, []>} */
@@ -21,11 +21,11 @@ import { ruleNames_makeRules } from "../constants/rules.js";
21
21
  /* coreCommentsFlow */
22
22
 
23
23
  /**
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
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.
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
- * $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
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.
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
- * $COMMENT#JSDOC#DEFINITIONS#COMPRESSCOMMENTSFLOW
129
- * @param {string[]} ignores $COMMENT#JSDOC#PARAMS#IGNORES
130
- * @param {{[key: string]: string}} reversedFlattenedConfigData $COMMENT#JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA
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.
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
- * $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
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.
145
145
  * @returns
146
146
  */
147
147
  export const placeholdersCommentsFlow = async (
@@ -158,12 +158,12 @@ export const placeholdersCommentsFlow = async (
158
158
 
159
159
  for (const [key, value] of Object.entries(originalFlattenedConfigData)) {
160
160
  if (value.includes(`${$COMMENT}#`))
161
- // composed Comment Variables
161
+ // composed variables
162
162
  composedValues_originalKeys[value] = key;
163
163
  else if (originalFlattenedConfigData[value])
164
- // alias Comment Variables
164
+ // alias variables
165
165
  aliasValues_originalKeys[value] = aliases_flattenedKeys[key];
166
- // regular Comment Variables
166
+ // comment variables
167
167
  else regularValuesOnly_originalKeys[value] = key;
168
168
  } // no need for continues, potential collisions are caught in resolveConfig run prior
169
169
 
@@ -216,7 +216,3 @@ export const placeholdersCommentsFlow = async (
216
216
  `✅ Made placeholders on ${total} file${total === 1 ? "" : "s"}.`
217
217
  );
218
218
  };
219
-
220
- // export const variablesCommentsFlow = () => {
221
-
222
- // }
@@ -1,16 +1,16 @@
1
1
  /* exitDueToFailure */
2
2
 
3
3
  /**
4
- * $COMMENT#JSDOC#DEFINITIONS#EXITDUETOFAILURE
5
- * @returns {never} $COMMENT#JSDOC#RETURNS#EXITDUETOFAILURE
4
+ * Terminates the whole process with a 'failure' code (`1`).
5
+ * @returns {never} Never. (Somehow typing needs to be explicit for unreachable code inference.)
6
6
  */
7
7
  export const exitDueToFailure = () => process.exit(1);
8
8
 
9
9
  /* logError */
10
10
 
11
11
  /**
12
- * $COMMENT#JSDOC#DEFINITIONS#LOGERROR
13
- * @param {{type: "error" | "warning"; message: string}} error $COMMENT#JSDOC#PARAMS#ERROR
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.
14
14
  * @returns
15
15
  */
16
16
  export const logError = (error) => {
package/library/index.js CHANGED
@@ -142,7 +142,7 @@ fs.writeFileSync(jsonPath, jsonData, "utf8");
142
142
 
143
143
  console.log(`JSON resolved config data written to: \n${jsonPath}`);
144
144
 
145
- // ADDRESSES THE CORE COMMANDS "resolve" AND "compress".
145
+ // ADDRESSES THE CORE COMMANDS "resolve", "compress", AND "placeholders".
146
146
 
147
147
  switch (coreCommand) {
148
148
  case resolveRuleName:
@@ -168,11 +168,11 @@ switch (coreCommand) {
168
168
  default:
169
169
  if (coreCommand && !coreCommand.startsWith("--"))
170
170
  console.error(
171
- `ERROR. Core command not recognized. Choose between "resolve" and "compress" or "placeholders".`
171
+ `ERROR. Core command not recognized. Choose between "${resolveRuleName}" and "${compressRuleName}" or "${placeholdersRuleName}".`
172
172
  );
173
173
  else
174
174
  console.log(
175
- `If these settings are correct with you, feel free to initiate the command "resolve" to resolve comments, or "compress" to compress them back to their $COMMENT forms. You can also generate the placeholders with the command "placeholders".${
175
+ `If these settings are correct with you, feel free to initiate the command "${resolveRuleName}" to resolve comments, or "${compressRuleName}" to compress them back to their $COMMENT forms. You can also generate the placeholders at their definitions locations with the command "${placeholdersRuleName}".${
176
176
  passedConfigPath || lintConfigImports || myIgnoresOnly
177
177
  ? " (And DON'T FORGET YOUR FLAGS!)"
178
178
  : ""
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comment-variables",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
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",
@@ -9,7 +9,8 @@
9
9
  "main": "library/index.js",
10
10
  "files": [
11
11
  "library",
12
- "comments.config.js"
12
+ "comments.config.js",
13
+ "comments.config.json"
13
14
  ],
14
15
  "repository": {
15
16
  "type": "git",
@@ -26,7 +27,7 @@
26
27
  "type": "module",
27
28
  "dependencies": {
28
29
  "@eslint/markdown": "^6.5.0",
29
- "comment-variables-resolve-config": "^1.9.1",
30
+ "comment-variables-resolve-config": "^1.9.4",
30
31
  "eslint": "^9.29.0"
31
32
  },
32
33
  "devDependencies": {