class RuboCop::Cop::Lint::ScriptPermission
puts ‘hello, world’
# granted execute permission.
# A file which has not a shebang line as its first line is not
# good
puts ‘hello, world’
#!/usr/bin/env ruby
# granted execute permission.
# A file which has a shebang line as its first line is
# good
puts ‘hello, world’
#!/usr/bin/env ruby
# granted execute permission.
# A file which has a shebang line as its first line is not
# bad
@example
its first line is granted execute permission.
Checks if a file which has a shebang line as
def autocorrect
def autocorrect FileUtils.chmod('+x', processed_source.file_path) end
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.file_path).executable? end
def format_message_from(processed_source)
def format_message_from(processed_source) basename = File.basename(processed_source.file_path) format(MSG, file: basename) end
def on_new_investigation
def on_new_investigation return if @options.key?(:stdin) return if Platform.windows? return unless processed_source.start_with?(SHEBANG) return if executable?(processed_source) comment = processed_source.comments[0] message = format_message_from(processed_source) add_offense(comment, message: message) do autocorrect if autocorrect_requested? end end