Created
July 4, 2019 21:00
-
-
Save j15e/658b6f6082f1d36cca8809a03639b69a to your computer and use it in GitHub Desktop.
Sublime Text 3 automatically add frozen string literal: true
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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