devsplain 1.5.5 → 1.5.6

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.
Files changed (2) hide show
  1. package/bin/cli.js +10 -10
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -10,7 +10,7 @@ const { execSync } = require('child_process');
10
10
  let rl;
11
11
  let askQuestion;
12
12
 
13
- /** Checks if the current Git repository has uncommitted changes */
13
+ /** Checks if the current Git repository is dirty by inspecting status. */
14
14
  function isGitDirty() {
15
15
  try {
16
16
  const gitDir = execSync('git rev-parse --is-inside-work-tree', { stdio: ['ignore', 'pipe', 'ignore'], encoding: 'utf8' }).trim();
@@ -23,7 +23,7 @@ function isGitDirty() {
23
23
  return false;
24
24
  }
25
25
 
26
- /** Determines if a line is within a string literal in the source code */
26
+ /** Determines if a specific line index is within a string literal (handling quotes/backticks). */
27
27
  function isLineInsideString(lines, targetLineIndex, ext = '') {
28
28
  const isPython = ext.toLowerCase() === '.py';
29
29
  let inBacktick = false;
@@ -97,7 +97,7 @@ function isLineInsideString(lines, targetLineIndex, ext = '') {
97
97
  return inBacktick || inTripleDouble || inTripleSingle || inSingle || inDouble;
98
98
  }
99
99
 
100
- /** Analyzes source code to identify comments and code blocks */
100
+ /** Parses a file to identify pure comments and block structures. */
101
101
  function analyzeComments(lines, ext = '') {
102
102
  const isPython = ext.toLowerCase() === '.py';
103
103
  const isHTML = ['.html', '.vue', '.svelte'].includes(ext.toLowerCase());
@@ -248,7 +248,7 @@ function analyzeComments(lines, ext = '') {
248
248
  return analysis;
249
249
  }
250
250
 
251
- /** Applies or removes comments from source data based on a specified mode */
251
+ /** Splices comments into code or cleans existing ones, with safety checks. */
252
252
  function spliceComments(data, comments, mode = 'default', ext = '') {
253
253
  const hasCRLF = data.includes('\r\n');
254
254
  const lineEnding = hasCRLF ? '\r\n' : '\n';
@@ -264,6 +264,9 @@ function spliceComments(data, comments, mode = 'default', ext = '') {
264
264
  const finalDeletions = new Set();
265
265
  for (let i = 0; i < originalLines.length; i++) {
266
266
  const lineNum = i + 1;
267
+ if (originalLines[i].trim().startsWith('#!')) {
268
+ continue;
269
+ }
267
270
  if (analysis[i].isPureComment) {
268
271
  finalDeletions.add(lineNum);
269
272
  } else if (analysis[i].commentStartIndex !== -1) {
@@ -373,7 +376,7 @@ function spliceComments(data, comments, mode = 'default', ext = '') {
373
376
  return annotated.map(line => line.text).join(lineEnding);
374
377
  }
375
378
 
376
- /** Main CLI execution logic */
379
+ /** Main entry point for the CLI tool. */
377
380
  async function runCLI() {
378
381
  rl = readline.createInterface({ input: process.stdin, output: process.stdout });
379
382
  askQuestion = (query) => new Promise((resolve) => rl.question(query, resolve));
@@ -426,7 +429,6 @@ Options:
426
429
  return;
427
430
  }
428
431
 
429
- // Helper to retrieve specific CLI argument values
430
432
  const getArgValue = (flag) => {
431
433
  const index = args.indexOf(flag);
432
434
  if (index !== -1 && index + 1 < args.length) {
@@ -491,7 +493,7 @@ Options:
491
493
  let successCount = 0;
492
494
  let failCount = 0;
493
495
 
494
- /** Recursively processes files or directories to apply comments */
496
+ /** Recursively processes files or directories to apply AI-generated comments. */
495
497
  async function processPath(targetPath) {
496
498
  const stats = fs.statSync(targetPath);
497
499
 
@@ -504,7 +506,6 @@ Options:
504
506
  '.vscode', '.idea', 'coverage'
505
507
  ];
506
508
 
507
- // Skip common dependency and configuration folders
508
509
  if (ignoredFolders.includes(folderName)) {
509
510
  return;
510
511
  }
@@ -539,7 +540,6 @@ Options:
539
540
  try {
540
541
  let comments = [];
541
542
  let commentedCode;
542
- // Perform comment processing: Clean existing, then inject new comments via LLM
543
543
  if (mode !== 'clean') {
544
544
  const cleanData = spliceComments(data, [], 'clean', ext);
545
545
  comments = await getComments(cleanData, filename, config, mode);
@@ -590,7 +590,7 @@ Options:
590
590
  rl.close();
591
591
  }
592
592
 
593
- // Initialize the CLI application if executed as a script
593
+ // Check if the script is run directly vs required as a module
594
594
  if (require.main === module) {
595
595
  runCLI().catch(err => {
596
596
  console.error(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devsplain",
3
- "version": "1.5.5",
3
+ "version": "1.5.6",
4
4
  "description": "An agent-agnostic CLI tool that automatically adds JSDoc and inline comments to your code using free LLMs.",
5
5
  "author": "mwahaj36",
6
6
  "license": "MIT",