Class: SasLinter::Rules::UnterminatedComment
- Inherits:
-
SasLinter::Rule
- Object
- SasLinter::Rule
- SasLinter::Rules::UnterminatedComment
- Defined in:
- lib/sas_linter/rules/unterminated_comment.rb
Overview
Flag a ‘** … **` comment line whose missing `;` causes the SAS lexer to extend the comment statement into the following line(s) of real code, silently swallowing it.
SAS ‘*` / `**` comment statements are terminated by the next `;` — the closing `**` is just prose. So
** SOME COMMENT **
y = x + 1;
lexes as a single comment token covering both lines, and the ‘y = x + 1;` assignment never executes.
Detection: a COMMENT-channel ‘PREDICTED_COMMENT_STAT` token whose `start_line != end_line` AND whose first source line, rstripped, ends with `**`. That shape is the boxed-comment closer the user clearly intended — they only forgot the `;`. Legitimate multi-line `*…;` prose ends its first line with plain text, not `**`, so it’s left alone.
Autofix: append ‘;` to the end of each flagged first line.
Constant Summary collapse
- TT =
SasLexer::Lexer::TokenType
- COMMENT_CHANNEL =
SasLexer::Lexer::TokenChannel::COMMENT
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from SasLinter::Rule
all, #autofix?, description, fetch, from_config, inherited, #initialize, register, registry, rule_id, severity
Constructor Details
This class inherits a constructor from SasLinter::Rule
Class Method Details
.supports_autofix? ⇒ Boolean
37 38 39 |
# File 'lib/sas_linter/rules/unterminated_comment.rb', line 37 def self.supports_autofix? true end |
Instance Method Details
#autofix(source) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sas_linter/rules/unterminated_comment.rb', line 50 def autofix(source) return source if source.nil? || source.empty? lines = source.split("\n", -1) bad = unterminated_comment_lines(tokenize(source), lines) return source if bad.empty? bad.each do |i| lines[i] = "#{lines[i].rstrip};" end lines.join("\n") end |
#check(_tokens, path:, all_tokens: nil, source: nil) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/sas_linter/rules/unterminated_comment.rb', line 41 def check(_tokens, path:, all_tokens: nil, source: nil) return [] unless all_tokens && source lines = source.split("\n", -1) unterminated_comment_lines(all_tokens, lines).map do |i| finding_for_line(lines[i], i, path) end end |