Open Jonas-Sander opened 3 years ago
Just in case it helps anybody else - I'm using danger.systems and GitHub Actions to make this check automatically. The relevant part of my Dangerfile is:
files = git.added_files + git.modified_files
files.each do |f|
diff = git.diff_for_file(f)
# Check comment formatting
if f =~ /.*\.dart/ and diff.patch =~ /((\/\/)[^ \n\/])|((\/\/\/)[^ \n])|(\/\*)/m
File.readlines(f).each_with_index do |line, index|
if line =~ /\/\*/
warn("Don't use block comments", file: f, line: index+1)
elsif line =~ /(\/\/\/)[^ \n]/
if line =~ /\/{4}/
warn("That's probably too many slashes", file: f, line: index+1)
else
warn("Add a space between \"///\" and the actual comment", file: f, line: index+1)
end
elsif line =~ /(\/\/)[^ \n\/]/
warn("Add a space between \"//\" and the actual comment", file: f, line: index+1)
end
end
end
end
Thanks @Jonas-Sander for providing the edge cases, they helped me write and test this code :)
Describe the rule you'd like to see implemented The lint should flag comments where there is no space between the slashes (
//
or///
) and the content of the comment.This is the style used by Flutter and Dart.
Examples Bad:
Good:
Some edge cases: