Skip to content

Instantly share code, notes, and snippets.

@j15e
Created July 4, 2019 21:00
Show Gist options
  • Save j15e/658b6f6082f1d36cca8809a03639b69a to your computer and use it in GitHub Desktop.
Save j15e/658b6f6082f1d36cca8809a03639b69a to your computer and use it in GitHub Desktop.
Sublime Text 3 automatically add frozen string literal: true
# Add to ~/Library/Application Support/Sublime Text 3/Packages/User/
import sublime
import sublime_plugin
class RubyFileSaveListener(sublime_plugin.EventListener):
def on_pre_save(self, view):
file_name = view.file_name()
if file_name.endswith('schema.rb'):
return
if file_name.endswith('.rb'):
sublime.active_window().run_command("add_frozen_string_comment")
class AddFrozenStringCommentCommand(sublime_plugin.TextCommand):
COMMENT_STRING = "# frozen_string_literal: true"
def run(self, edit):
file_name = self.view.file_name()
if file_name.endswith('.rb'):
first_line = self.view.line(0)
line_contents = self.view.substr(first_line)
if (line_contents != self.COMMENT_STRING):
self.view.insert(edit, 0, self.COMMENT_STRING + "\n\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment