class RuboCop::Cop::Lint::ScriptPermission
its first line is granted execute permission.
This cop checks if a file which has a shebang line as
def executable?(processed_source)
def executable?(processed_source) # Returns true if stat is executable or if the operating system # doesn't distinguish executable files from nonexecutable files. # See at: https://github.com/ruby/ruby/blob/ruby_2_4/file.c#L5362 File.stat(processed_source.buffer.name).executable? end
def format_message_from(processed_source)
def format_message_from(processed_source) basename = File.basename(processed_source.buffer.name) format(MSG, basename) end
def investigate(processed_source)
def investigate(processed_source) return if Platform.windows? return unless start_with_shebang?(processed_source) return if executable?(processed_source) comment = processed_source.comments[0] message = format_message_from(processed_source) add_offense(comment, :expression, message) end
def start_with_shebang?(processed_source)
def start_with_shebang?(processed_source) return false if processed_source[0].nil? processed_source[0].start_with?(SHEBANG) end