comment-variables 1.1.0 → 1.1.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.
package/README.md CHANGED
@@ -12,7 +12,7 @@ npm install -g comment-variables
12
12
 
13
13
  ## Commands
14
14
 
15
- **`comment-variables` (aliases `jscomments`/`comvar`) comes with three commands in this initial release:**
15
+ **`comment-variables` (aliases `jscomments`/`comvar`) comes with four commands in this initial release:**
16
16
 
17
17
  ```
18
18
  comment-variables
@@ -20,6 +20,12 @@ comment-variables
20
20
 
21
21
  Interacts with your root `comments.config.js` file's 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 as 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. If no configuration file is found, a tutorial mode is triggered, generating a template config file for you.)
22
22
 
23
+ ```
24
+ comment-variables placeholders
25
+ ```
26
+
27
+ Creates Comment Variables placeholders right next to the single sources of truth where Comment Variables are defined. (See in config example below.)
28
+
23
29
  ```
24
30
  comment-variables compress
25
31
  ```
@@ -34,45 +40,63 @@ Scans your line and block comments for `$COMMENT#*` placeholders (like `$COMMENT
34
40
 
35
41
  _The `compress` and `resolve` commands make each other entirely reversible._
36
42
 
37
- **New command: `comment-variables placeholders`**
43
+ ## Flags
44
+
45
+ **The CLI tool comes with a single flag:**
38
46
 
39
47
  ```
40
- comment-variables placeholders
48
+ comment-variables --config <your-config.js>
41
49
  ```
42
50
 
43
- Creates Comment Variables placeholders right next to the single sources of truth where Comment Variables are defined. (See in config example below.)
51
+ Passes a different file as your config file instead of the default root `comments.config.js` file (like `comment-variables --config your-config.js`), through a path relative to the root of your project.
44
52
 
45
- ## Flags
53
+ _The --config flag can be composed with any of the commands:_
54
+
55
+ ```
56
+ comment-variables --config your-config.js
57
+ comment-variables compress --config your-config.js
58
+ comment-variables resolve --config your-config.js
59
+ comment-variables placeholders --config your-config.js
60
+ ```
46
61
 
47
- **The CLI tool also comes with three flags initially:**
62
+ ## Settings
63
+
64
+ **The config object requires the following settings:**
48
65
 
49
66
  ```
50
- comment-variables --config <your-config.js>
67
+ data:
51
68
  ```
52
69
 
53
- Passes a different file as your config file instead of the default root `comments.config.js` file (like `comment-variables --config your-config.js`), through a path relative to the root of your project.
70
+ Your dedicated object defining your Comment Variables through nested key-value pairs of string literals.
54
71
 
55
72
  ```
56
- --lint-config-imports is now part of the config at the `lintConfigImports` key
73
+ ignores:
57
74
  ```
58
75
 
59
- By default, `comment-variables` excludes your config file and all the (JavaScript/TypeScript) files it recursively imports. This config option cancels this mechanism, linting config imports. (The config file however still remains excluded from linting.)
76
+ Your dedicated array defining your files and folders to be ignored by the `compress` and `resolve` commands through strings of paths relative to the root of your project.
77
+
78
+ ## Options
79
+
80
+ **The config object supports the following options:**
60
81
 
61
82
  ```
62
- --my-ignores-only is now part of the config at the `myIgnoresOnly` key
83
+ lintConfigImports:
63
84
  ```
64
85
 
65
- By default, `comment-variables` includes a preset list of ignored folders (`"node_modules"`, `".next"`, `".react-router"`...). This config option cancels this mechanism so that you can have full control over your ignored files and folders.
86
+ By default, `comment-variables` excludes your config file and all the (JavaScript/TypeScript) files it recursively imports. Passing `true` to this config option cancels this mechanism, linting config imports. (The config file however still remains excluded from linting.)
66
87
 
67
- _The --config flag can be composed with any of the commands:_
88
+ ```
89
+ myIgnoresOnly:
90
+ ```
91
+
92
+ By default, `comment-variables` includes a preset list of ignored folders (`"node_modules"`, `".next"`, `".react-router"`...). Passing `true` to this config option cancels this mechanism so that you can have full control over your ignored files and folders.
68
93
 
69
94
  ```
70
- comment-variables --config your-config.js
71
- comment-variables compress --config your-config.js
72
- comment-variables resolve --config your-config.js
73
- comment-variables placeholders --config your-config.js
95
+ composedVariablesExclusives:
74
96
  ```
75
97
 
98
+ In due time, you may end up creating Comment Variables that are exclusively meant to be used to create other Comment Variables – the latter classified as composed variables. Passing an array to this config option, comprised of the keys of these original comment variables (for example, if a Comment Variable placeholder is `$COMMENT#COMMENT` its related key is `COMMENT`), prevents these original comment variables from being affected by the `compress` and `resolve` commands.
99
+
76
100
  ## **`comments.config.js`**
77
101
 
78
102
  A root `comments.config.js` file looks like this. (This is the config file I'm using to manage my JavaScript comments in this library.)
@@ -142,11 +166,14 @@ const ignores = ["README.md", "generate.template.js", "generate.example.js"];
142
166
  const lintConfigImports = false; // can be omitted
143
167
  const myIgnoresOnly = false; // can be omitted
144
168
 
169
+ const composedVariablesExclusives = []; // can be omitted
170
+
145
171
  const config = {
146
172
  data,
147
173
  ignores,
148
174
  lintConfigImports,
149
175
  myIgnoresOnly,
176
+ composedVariablesExclusives,
150
177
  };
151
178
 
152
179
  export default config;
@@ -106,6 +106,8 @@ const data = {
106
106
  constants: Object.freeze({
107
107
  sortedReversedFlattenedConfigData:
108
108
  "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." /* $COMMENT#JSDOC#CONSTANTS#SORTEDREVERSEDFLATTENEDCONFIGDATA */,
109
+ composedVariablesExclusivesSet:
110
+ "A local Set out of composed variables exclusives for speed." /* $COMMENT#JSDOC#CONSTANTS#COMPOSEDVARIABLESEXCLUSIVESSET */,
109
111
  }),
110
112
  }),
111
113
  };
@@ -115,7 +117,6 @@ const ignores = ["README.md", "generate.template.js", "generate.example.js"];
115
117
  const lintConfigImports = false; // can be omitted
116
118
  const myIgnoresOnly = false; // can be omitted
117
119
 
118
- // NEW
119
120
  const composedVariablesExclusives = []; // can be omitted
120
121
 
121
122
  const config = {
@@ -155,6 +155,11 @@
155
155
  "value": "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.",
156
156
  "key": "JSDOC#CONSTANTS#SORTEDREVERSEDFLATTENEDCONFIGDATA",
157
157
  "placeholder": "$COMMENT#JSDOC#CONSTANTS#SORTEDREVERSEDFLATTENEDCONFIGDATA"
158
+ },
159
+ "composedVariablesExclusivesSet": {
160
+ "value": "A local Set out of composed variables exclusives for speed.",
161
+ "key": "JSDOC#CONSTANTS#COMPOSEDVARIABLESEXCLUSIVESSET",
162
+ "placeholder": "$COMMENT#JSDOC#CONSTANTS#COMPOSEDVARIABLESEXCLUSIVESSET"
158
163
  }
159
164
  }
160
165
  }
@@ -20,7 +20,6 @@ const ignores = [];
20
20
  const lintConfigImports = false; // can be omitted
21
21
  const myIgnoresOnly = false; // can be omitted
22
22
 
23
- // NEW
24
23
  const composedVariablesExclusives = []; // can be omitted
25
24
 
26
25
  const config = {
@@ -3,11 +3,6 @@ import path from "path";
3
3
 
4
4
  import { cwd } from "comment-variables-resolve-config";
5
5
 
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
-
11
6
  // to prevent accidental changes
12
7
  export const hasPackageJson = fs.existsSync(path.join(cwd, "package.json"));
13
8
  // to prevent irreversible changes
@@ -16,7 +16,7 @@ const makeRule = (reversedFlattenedConfigData, composedVariablesExclusives) => {
16
16
  reversedFlattenedConfigData
17
17
  ).sort(([a], [b]) => b.length - a.length);
18
18
 
19
- // makes a set out of composed variables exclusives
19
+ /** A local Set out of composed variables exclusives for speed. */
20
20
  const composedVariablesExclusivesSet = new Set(composedVariablesExclusives);
21
21
 
22
22
  /** @type {import('@typescript-eslint/utils').TSESLint.RuleModule<typeof placeholderMessageId, []>} */
@@ -49,7 +49,6 @@ const makeRule = (reversedFlattenedConfigData, composedVariablesExclusives) => {
49
49
  commentKey,
50
50
  ] of sortedReversedFlattenedConfigData) {
51
51
  // NEW
52
- // if (composedVariablesExclusives.some((e) => commentKey === e))
53
52
  if (composedVariablesExclusivesSet.has(commentKey)) continue;
54
53
 
55
54
  const pattern = makeIsolatedStringRegex(resolvedValue);
@@ -15,7 +15,7 @@ const makeRule = (
15
15
  composedVariablesExclusives,
16
16
  aliases_flattenedKeys
17
17
  ) => {
18
- // makes a set out of composed variables exclusives
18
+ /** A local Set out of composed variables exclusives for speed. */
19
19
  const composedVariablesExclusivesSet = new Set(composedVariablesExclusives);
20
20
 
21
21
  /** @type {import('@typescript-eslint/utils').TSESLint.RuleModule<typeof placeholderMessageId, []>} */
@@ -58,11 +58,8 @@ const makeRule = (
58
58
  const replacement = flattenedConfigData[key];
59
59
 
60
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))
61
+ // The issue is that having patterns instead of the exact keys is way too powerful, effectively slow, 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.
62
+ // Also, focusing exclusively on comment variables and barring aliases (and composed) solves many issues at once, notably by covering aliases in one go.
66
63
  if (replacement && composedVariablesExclusivesSet.has(key)) continue;
67
64
 
68
65
  if (replacement) {
@@ -33,6 +33,7 @@ const coreCommentsFlow = async (
33
33
  ruleName,
34
34
  ignores,
35
35
  flattenedConfigData,
36
+ // NEW
36
37
  composedVariablesExclusives,
37
38
  aliases_flattenedKeys
38
39
  ) => {
@@ -50,6 +51,7 @@ const coreCommentsFlow = async (
50
51
  rules: {
51
52
  [ruleName]: ruleNames_makeRules[ruleName](
52
53
  flattenedConfigData,
54
+ // NEW
53
55
  composedVariablesExclusives,
54
56
  aliases_flattenedKeys
55
57
  ),
@@ -115,6 +117,7 @@ const coreCommentsFlow = async (
115
117
  export const resolveCommentsFlow = async (
116
118
  ignores,
117
119
  flattenedConfigData,
120
+ // NEW
118
121
  composedVariablesExclusives,
119
122
  aliases_flattenedKeys
120
123
  ) =>
@@ -122,6 +125,7 @@ export const resolveCommentsFlow = async (
122
125
  resolveRuleName,
123
126
  ignores,
124
127
  flattenedConfigData,
128
+ // NEW
125
129
  composedVariablesExclusives,
126
130
  aliases_flattenedKeys
127
131
  );
@@ -138,12 +142,14 @@ export const resolveCommentsFlow = async (
138
142
  export const compressCommentsFlow = async (
139
143
  ignores,
140
144
  reversedFlattenedConfigData,
145
+ // NEW
141
146
  composedVariablesExclusives
142
147
  ) =>
143
148
  coreCommentsFlow(
144
149
  compressRuleName,
145
150
  ignores,
146
151
  reversedFlattenedConfigData,
152
+ // NEW
147
153
  composedVariablesExclusives
148
154
  );
149
155
 
package/library/index.js CHANGED
@@ -142,7 +142,10 @@ skipDetails || console.log("lintConfigImports is:", lintConfigImports);
142
142
  skipDetails || console.log("myIgnoresOnly are:", myIgnoresOnly);
143
143
  // NEW
144
144
  skipDetails ||
145
- console.log("composedVariablesExclusives are:", composedVariablesExclusives);
145
+ console.log(
146
+ "Composed variables exclusives are:",
147
+ composedVariablesExclusives
148
+ );
146
149
 
147
150
  // ADDRESSES THE --lint-config-imports FLAG (lintConfigImports, no longer a flag), GIVEN THAT THE FILES IMPORTED BY THE CONFIG ARE IGNORED BY DEFAULT.
148
151
 
@@ -195,6 +198,7 @@ switch (coreCommand) {
195
198
  await resolveCommentsFlow(
196
199
  ignores,
197
200
  flattenedConfigData,
201
+ // NEW
198
202
  composedVariablesExclusives,
199
203
  aliases_flattenedKeys
200
204
  );
@@ -204,6 +208,7 @@ switch (coreCommand) {
204
208
  await compressCommentsFlow(
205
209
  ignores,
206
210
  reversedFlattenedConfigData,
211
+ // NEW
207
212
  composedVariablesExclusives
208
213
  );
209
214
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comment-variables",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
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",