sasjs / lint

Linting and formatting for SAS® code

Home Page:https://sasjs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

linting feature request: no single star comments

Carus11 opened this issue · comments

Could I request a rule to ensure there are none of those single star comments, basically

* This is what my code does 

Fails, and:

/* This is what my code does */

Passes

Hey Carus! I've been thinking about this. Here are the initial test cases I came up with - can you think of any more?

/**
 * Examples of *message; format that SHOULD be caught
 */

/* 1. regular comment */
* some text;

/* 2. multiline comment */
*
multiline
text;

/* multiple asterisks - should start on first */
   *---------------------------------------*
   |  This uses one comment statement      |
   |           to draw a box.              |
   *---------------------------------------*;
   

/* 3. comment at end of statement */
libname x (work); * some text;


/* 4. comment in middle of statement */
run; *walk
; run;

/* 5. comment at start of statement */
*; run;

/* 6.  comment within a comment */
* /* ignored also */ ;

/* 7. In a macro */
%macro x; * %mend;


/**
 * Examples of *message; format that should NOT be caught
 * (this was the first)
 */

/* 2. In a string literal */
data _null_;
  string='no*no;no';
  string="not*this;either";
run;

/* 3. In a %str() block */
%let x=%str(afraid *not; sir);

/* 4. In an nrstr() block */
%let y=%nrstr(try*again;please);

/* 5. In a %put statement */
%put not * today;;

/* 6. As a macro comment */
%* this one is totally normal; 

/* 7. in a LUA proc */
proc lua;
submit;
 -- hi *mum;
endsubmit;
run;

/* 8. in a data step */
data;
  a * b;
  b ** a;
run;

/* 9. sql / fedsql */
proc sql;
  select * from sashelp.cars;
  select /* */ * from sashelp.class;
  select a.*, b.* from a,b;

/* 10. in a macro but wrapped in brackets */
%macro x;(*)%mend;%x;

Link to docs: https://documentation.sas.com/doc/en/pgmsascdc/v_015/lestmtsglobal/n1v51exifva71an1cvfn2z6j26lo.htm?homeOnFail

Oh wow thanks Allan,
I'll have some of our devs have a look at your cases. I just realized now my example was wrong because I didnt terminate the comment with a semicolon. I am going to leave it that way as that is the very mistake I find sneaks into our code base time and time again when we comment using the single asterisk method.

I'm wondering if we will need to build a tokenizer to make this work!

Hello @Carus11 @allanbowe Thanks for the idea and your input. 🙌🏽
I'll take an initial crack at implementing this at some point next week.