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.
This cop checks if a file which has a shebang line as
def autocorrect(node)
def autocorrect(node) lambda do |_corrector| FileUtils.chmod('+x', node.loc.expression.source_buffer.name) end 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 investigate(processed_source)
def investigate(processed_source) 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) end