comment-variables 0.0.1 → 0.0.3

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.
@@ -11,6 +11,10 @@ const config = {
11
11
  levelThreeAlso: "Also level three here.",
12
12
  levelThreeToo: "This too is level three.",
13
13
  // test: "LEVELONE#LEVELTWO#LEVELTHREE", // errors
14
+ [`level$Three#First
15
+ whitespace`]: `This is level three
16
+ with whitespaces. `,
17
+ testing: 2,
14
18
  },
15
19
  },
16
20
  };
@@ -87,6 +87,8 @@ export const resolveImportPath = (
87
87
  return null; // not found
88
88
  };
89
89
 
90
+ /* getSourceCodeFromFilePath */
91
+
90
92
  // ESLint configs language options
91
93
  const typeScriptAndJSXCompatible = {
92
94
  // for compatibility with .ts and .tsx
@@ -99,8 +101,6 @@ const typeScriptAndJSXCompatible = {
99
101
  },
100
102
  };
101
103
 
102
- /* getSourceCodeFromFilePath */
103
-
104
104
  /**
105
105
  * Gets the ESLint-generated SourceCode object of a file from its resolved path.
106
106
  * @param {string} resolvedPath The resolved path of the file.
@@ -228,4 +228,5 @@ So here I want to make
228
228
 
229
229
  js-comments is taken on npm.
230
230
  JSComments, jscomments is free.
231
+ comment-variables in the end.
231
232
  */
package/index.js CHANGED
@@ -233,17 +233,6 @@ const makeReverseJsCommentsRule = (reversedFlattenedConfig) => {
233
233
  resolvedValue,
234
234
  commentKey,
235
235
  ] of sortedReversedFlattenedConfig) {
236
- // if (fixedText.includes(resolvedValue)) {
237
- // fixedText = fixedText.replaceAll(
238
- // resolvedValue,
239
- // `$COMMENT#${commentKey}`
240
- // );
241
- // modified = true;
242
- // }
243
- // }
244
-
245
- // if (modified) {
246
-
247
236
  const pattern = new RegExp(
248
237
  `(?<=\\s|^)${escapeRegex(resolvedValue)}(?=\\s|$)`,
249
238
  "g"
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "comment-variables",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "",
5
5
  "bin": {
6
- "jscomments": "./index.js"
6
+ "jscomments": "./index.js",
7
+ "comment-variables": "./index.js"
7
8
  },
8
9
  "main": "index.js",
9
10
  "repository": {
@@ -15,7 +15,7 @@ function flattenConfig(
15
15
  normalizedPath = currentPath
16
16
  .map((k) => k.toUpperCase())
17
17
  .join("#")
18
- .replaceAll(" ", "_"); // spaces are replaced by underscores
18
+ .replace(/\s/g, "_"); // whitespaces are replaced by underscores
19
19
 
20
20
  if (typeof value === "string") {
21
21
  if (map[normalizedPath]) {
@@ -59,13 +59,7 @@ function flattenConfig(
59
59
  return { flattenedConfig, reversedFlattenedConfig };
60
60
  }
61
61
 
62
- export async function runWithConfig(rawConfigPath) {
63
- // const __filename = fileURLToPath(import.meta.url);
64
- // const __dirname = dirname(__filename);
65
-
66
- // const configPath = join(__dirname, rawConfigPath);
67
- const configPath = rawConfigPath;
68
-
62
+ export async function runWithConfig(configPath) {
69
63
  // Step 1: Check if config file exists
70
64
  if (!existsSync(configPath)) {
71
65
  console.warn("No config file found. Exiting gracefully.");
@@ -82,13 +76,59 @@ export async function runWithConfig(rawConfigPath) {
82
76
  return null;
83
77
  }
84
78
 
85
- const RecursiveObject = z.lazy(() =>
86
- z.record(z.union([z.string(), RecursiveObject]))
87
- );
79
+ const RecursiveObject = z
80
+ .lazy(() =>
81
+ z.record(
82
+ z.any().superRefine((val, ctx) => {
83
+ if (typeof val === "string") {
84
+ return;
85
+ }
86
+
87
+ if (typeof val === "object" && val !== null && !Array.isArray(val)) {
88
+ const parsed = RecursiveObject.safeParse(val);
89
+ if (!parsed.success) {
90
+ for (const issue of parsed.error.issues) {
91
+ ctx.addIssue({
92
+ ...issue,
93
+ path: [...ctx.path, ...issue.path], // proper path propagation
94
+ });
95
+ }
96
+ }
97
+ return;
98
+ }
99
+
100
+ ctx.addIssue({
101
+ code: z.ZodIssueCode.custom,
102
+ message: `Value \`${val}\` of type "${typeof val}" should be a string or a nested object.`,
103
+ path: ctx.path,
104
+ });
105
+ })
106
+ )
107
+ )
108
+ .superRefine((obj, ctx) => {
109
+ for (const key of Object.keys(obj)) {
110
+ if (key.includes("$")) {
111
+ ctx.addIssue({
112
+ code: z.ZodIssueCode.custom,
113
+ message: `Key "${key}" should not include the "$" character.`,
114
+ path: [key],
115
+ });
116
+ }
117
+ if (key.includes("#")) {
118
+ ctx.addIssue({
119
+ code: z.ZodIssueCode.custom,
120
+ message: `Key "${key}" should not include the "#" character.`,
121
+ path: [key],
122
+ });
123
+ }
124
+ }
125
+ });
126
+
88
127
  const result = RecursiveObject.safeParse(config);
89
128
 
90
129
  if (!result.success) {
91
130
  console.warn("Config could not pass validation from zod.");
131
+ result.error.errors.map((e) => console.log(e.message));
92
132
  return null;
93
133
  }
94
134