├── .gitignore ├── Context.sublime-menu ├── Default (Linux).sublime-keymap ├── Default (OSX).sublime-keymap ├── Default (Windows).sublime-keymap ├── ESLint-Formatter.py ├── ESLint-Formatter.sublime-commands ├── ESLint-Formatter.sublime-settings ├── LICENSE ├── Main.sublime-menu ├── README.md ├── messages.json └── messages ├── 1.0.0.txt ├── 1.0.1.txt ├── 2.0.0.txt ├── 2.0.1.txt ├── 2.1.0.txt ├── 2.1.1.txt ├── 2.2.0.txt ├── 2.2.1.txt ├── 2.3.0.txt ├── 2.3.1.txt ├── 2.4.0.txt ├── 2.4.1.txt ├── 2.4.2.txt ├── 2.4.3.txt ├── 2.4.4.txt └── 2.4.5.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /Context.sublime-menu: -------------------------------------------------------------------------------- 1 | [{ 2 | "caption": "ESLint Formatter", 3 | "children": [{ 4 | "caption": "Format This File", 5 | "command": "format_eslint" 6 | }] 7 | }] 8 | -------------------------------------------------------------------------------- /Default (Linux).sublime-keymap: -------------------------------------------------------------------------------- 1 | [{ 2 | "keys": ["ctrl+shift+h"], 3 | "command": "format_eslint" 4 | }] 5 | -------------------------------------------------------------------------------- /Default (OSX).sublime-keymap: -------------------------------------------------------------------------------- 1 | [{ 2 | "keys": ["super+shift+h"], 3 | "command": "format_eslint" 4 | }] 5 | -------------------------------------------------------------------------------- /Default (Windows).sublime-keymap: -------------------------------------------------------------------------------- 1 | [{ 2 | "keys": ["ctrl+shift+h"], 3 | "command": "format_eslint" 4 | }] 5 | -------------------------------------------------------------------------------- /ESLint-Formatter.py: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | import sublime, sublime_plugin 6 | import platform 7 | import glob 8 | import os, sys, subprocess, codecs, webbrowser 9 | from subprocess import Popen, PIPE 10 | 11 | try: 12 | import commands 13 | except ImportError: 14 | pass 15 | 16 | PROJECT_NAME = "ESLint-Formatter" 17 | SETTINGS_FILE = PROJECT_NAME + ".sublime-settings" 18 | KEYMAP_FILE = "Default ($PLATFORM).sublime-keymap" 19 | 20 | IS_WINDOWS = platform.system() == 'Windows' 21 | 22 | class FormatEslintCommand(sublime_plugin.TextCommand): 23 | def run(self, edit): 24 | # Save the current viewport position to scroll to it after formatting. 25 | previous_selection = list(self.view.sel()) # Copy. 26 | previous_position = self.view.viewport_position() 27 | 28 | # Save the already folded code to refold it after formatting. 29 | # Backup of folded code is taken instead of regions because the start and end pos 30 | # of folded regions will change once formatted. 31 | folded_regions_content = [self.view.substr(r) for r in self.view.folded_regions()] 32 | 33 | # Get the current text in the buffer and save it in a temporary file. 34 | # This allows for scratch buffers and dirty files to be linted as well. 35 | entire_buffer_region = sublime.Region(0, self.view.size()) 36 | 37 | buffer_text = self.get_buffer_text(entire_buffer_region) 38 | 39 | output = self.run_script_on_file(filename=self.view.file_name(), content=buffer_text) 40 | 41 | # log output in debug mode 42 | if PluginUtils.get_pref("debug"): 43 | print(output) 44 | 45 | # Supported by eslint_d 46 | # https://github.com/mantoni/eslint_d.js#automatic-fixing 47 | if not PluginUtils.get_pref('fix_to_stdout'): 48 | # eslint currently does not print the fixed file to stdout, it just modifies the file. 49 | return 50 | 51 | # If the prettified text length is nil, the current syntax isn't supported. 52 | if output == None or len(output) < 1: 53 | return 54 | 55 | # Replace the text only if it's different. 56 | if output != buffer_text: 57 | self.view.replace(edit, entire_buffer_region, output) 58 | 59 | self.refold_folded_regions(folded_regions_content, output) 60 | self.view.set_viewport_position((0, 0), False) 61 | self.view.set_viewport_position(previous_position, False) 62 | self.view.sel().clear() 63 | 64 | # Restore the previous selection if formatting wasn't performed only for it. 65 | # if not is_formatting_selection_only: 66 | for region in previous_selection: 67 | self.view.sel().add(region) 68 | 69 | def get_buffer_text(self, region): 70 | buffer_text = self.view.substr(region) 71 | return buffer_text 72 | 73 | def walk_up_for_config(self, cdir, configFile): 74 | if (cdir is None or configFile is None): 75 | return 76 | 77 | files = [file for file in os.listdir(cdir) if os.path.isfile(os.path.join(cdir, file))] 78 | if configFile in files: 79 | return cdir 80 | 81 | parent = os.path.dirname(cdir) 82 | if (parent is cdir): 83 | return parent 84 | 85 | return self.walk_up_for_config(parent, configFile) 86 | 87 | def get_lint_directory(self, filename): 88 | project_path = PluginUtils.project_path(None) 89 | if project_path is not None: 90 | return PluginUtils.normalize_path(project_path) 91 | 92 | if filename is not None: 93 | cdir = os.path.dirname(filename) 94 | configFile = PluginUtils.get_pref('config_file') 95 | if (configFile): 96 | foundCwd = self.walk_up_for_config(cdir, configFile) 97 | if foundCwd: 98 | return foundCwd 99 | if os.path.exists(cdir): return cdir 100 | return os.getcwd() 101 | 102 | def run_script_on_file(self, filename=None, content=None): 103 | try: 104 | dirname = filename and os.path.dirname(filename) 105 | node_path = PluginUtils.get_node_path() 106 | eslint_path = PluginUtils.get_eslint_path(dirname) 107 | 108 | if eslint_path == False: 109 | sublime.error_message('ESLint could not be found on your path') 110 | return 111 | 112 | use_stdio = PluginUtils.get_pref('fix_to_stdout') 113 | if not use_stdio and filename is None: 114 | sublime.error_message('Cannot lint unsaved file') 115 | 116 | # Better support globally-available eslint binaries that don't need to be invoked with node. 117 | node_cmd = [node_path] if node_path else [] 118 | fix_params = ['--stdin', '--fix-to-stdout'] if use_stdio else ['--fix', filename] 119 | if use_stdio and filename is not None: fix_params += ['--stdin-filename', filename] 120 | cmd = node_cmd + [eslint_path] + fix_params 121 | 122 | project_path = PluginUtils.project_path() 123 | extra_args = PluginUtils.get_pref("extra_args") 124 | if extra_args: 125 | cmd += [arg.replace('$project_path', project_path) for arg in extra_args] 126 | 127 | if PluginUtils.get_pref("debug"): 128 | print('eslint command line', cmd) 129 | 130 | config_path = PluginUtils.get_pref("config_path") 131 | 132 | if os.path.isfile(config_path): 133 | # If config file path exists, use as is 134 | full_config_path = config_path 135 | else: 136 | # Find config gile relative to project path 137 | full_config_path = os.path.join(project_path, config_path) 138 | 139 | if os.path.isfile(full_config_path): 140 | print("Using configuration from {0}".format(full_config_path)) 141 | cmd.extend(["--config", full_config_path]) 142 | 143 | cdir = self.get_lint_directory(filename) 144 | 145 | if type(content) == str: content = content.encode('utf-8') 146 | 147 | output = PluginUtils.get_output(cmd, cdir, content if use_stdio else None) 148 | 149 | return output 150 | 151 | except: 152 | # Something bad happened. 153 | msg = str(sys.exc_info()[1]) 154 | print("Unexpected error({0}): {1}".format(sys.exc_info()[0], msg)) 155 | sublime.error_message(msg) 156 | 157 | def refold_folded_regions(self, folded_regions_content, entire_file_contents): 158 | self.view.unfold(sublime.Region(0, len(entire_file_contents))) 159 | region_end = 0 160 | 161 | for content in folded_regions_content: 162 | region_start = entire_file_contents.index(content, region_end) 163 | if region_start > -1: 164 | region_end = region_start + len(content) 165 | self.view.fold(sublime.Region(region_start, region_end)) 166 | 167 | class ESLintFormatterEventListeners(sublime_plugin.EventListener): 168 | @staticmethod 169 | def should_run_command(view, pre_phase): 170 | if not PluginUtils.get_pref("format_on_save"): return False 171 | if bool(PluginUtils.get_pref("fix_to_stdout")) != pre_phase: return False 172 | 173 | extensions = PluginUtils.get_pref("format_on_save_extensions") 174 | extension = os.path.splitext(view.file_name())[1][1:] 175 | 176 | # Default to using filename if no extension 177 | if not extension: 178 | extension = os.path.basename(view.file_name()) 179 | 180 | # Skip if extension is not listed 181 | return not extensions or extension in extensions 182 | 183 | @staticmethod 184 | def on_pre_save(view): 185 | if ESLintFormatterEventListeners.should_run_command(view, True): 186 | view.run_command("format_eslint") 187 | 188 | @staticmethod 189 | def on_post_save(view): 190 | if ESLintFormatterEventListeners.should_run_command(view, False): 191 | view.run_command("format_eslint") 192 | 193 | class PluginUtils: 194 | @staticmethod 195 | # Fetches root path of open project 196 | def project_path(fallback=os.getcwd()): 197 | project_data = sublime.active_window().project_data() 198 | 199 | # if cannot find project data, use cwd 200 | if project_data is None: 201 | return fallback 202 | 203 | folders = project_data['folders'] 204 | folder_path = folders[0]['path'] 205 | return folder_path 206 | 207 | @staticmethod 208 | def get_pref(key): 209 | global_settings = sublime.load_settings(SETTINGS_FILE) 210 | value = global_settings.get(key) 211 | 212 | # Load active project settings 213 | project_settings = sublime.active_window().active_view().settings() 214 | 215 | # Overwrite global config value if it's defined 216 | if project_settings.has(PROJECT_NAME): 217 | value = project_settings.get(PROJECT_NAME).get(key, value) 218 | 219 | return value 220 | 221 | @staticmethod 222 | def get_node_path(): 223 | platform = sublime.platform() 224 | node = PluginUtils.get_pref("node_path").get(platform) 225 | if type(node) == str: 226 | print("Using node.js path on '" + platform + "': " + node) 227 | else: 228 | print("Not using explicit node.js path") 229 | return node 230 | 231 | # Convert path that possibly contains a user tilde and/or is a relative path into an absolute path. 232 | def normalize_path(path, realpath=False): 233 | if realpath: 234 | return os.path.realpath(os.path.expanduser(path)) 235 | else: 236 | project_dir = sublime.active_window().project_file_name() 237 | if project_dir: 238 | cwd = os.path.dirname(project_dir) 239 | else: 240 | cwd = os.getcwd() 241 | return os.path.normpath(os.path.join(cwd, os.path.expanduser(path))) 242 | 243 | # Yield path and every directory above path. 244 | @staticmethod 245 | def walk_up(path): 246 | curr_path = path 247 | while 1: 248 | yield curr_path 249 | curr_path, tail = os.path.split(curr_path) 250 | if not tail: 251 | break 252 | 253 | # Find the first path matching a given pattern within dirname or the nearest ancestor of dirname. 254 | @staticmethod 255 | def findup(pattern, dirname=None): 256 | if dirname is None: 257 | project_path = PluginUtils.project_path() 258 | normdn = PluginUtils.normalize_path(project_path) 259 | else: 260 | normdn = PluginUtils.normalize_path(dirname) 261 | 262 | for d in PluginUtils.walk_up(normdn): 263 | matches = glob.glob(os.path.join(d, pattern)) 264 | if matches: 265 | return matches[0] 266 | 267 | return None 268 | 269 | @staticmethod 270 | def get_local_eslint(dirname): 271 | pkg = PluginUtils.findup('node_modules/eslint', dirname) 272 | if pkg == None: 273 | return None 274 | else: 275 | path = PluginUtils.get_pref("local_eslint_path").get(sublime.platform()) 276 | if not path: return None 277 | d = os.path.dirname(os.path.dirname(pkg)) 278 | esl = os.path.join(d, path) 279 | 280 | if os.path.isfile(esl): 281 | return esl 282 | else: 283 | return None 284 | 285 | @staticmethod 286 | def get_eslint_path(dirname): 287 | platform = sublime.platform() 288 | eslint = dirname and PluginUtils.get_local_eslint(dirname) 289 | 290 | # if local eslint not available, then using the settings config 291 | if eslint == None: 292 | eslint = PluginUtils.get_pref("eslint_path").get(platform) 293 | 294 | print("Using eslint path on '" + platform + "': " + eslint) 295 | return eslint 296 | 297 | @staticmethod 298 | def get_output(cmd, cdir, data): 299 | try: 300 | p = Popen(cmd, 301 | stdout=PIPE, stdin=PIPE, stderr=PIPE, 302 | cwd=cdir, shell=IS_WINDOWS) 303 | except OSError: 304 | raise Exception('Couldn\'t find Node.js. Make sure it\'s in your $PATH by running `node -v` in your command-line.') 305 | stdout, stderr = p.communicate(input=data) 306 | stdout = stdout.decode('utf-8') 307 | stderr = stderr.decode('utf-8') 308 | 309 | if p.returncode == 127: 310 | raise Exception('Error: %s' % (stderr or stdout)) 311 | elif stderr and p.returncode != 0: 312 | raise Exception('Error: %s' % stderr) 313 | else: 314 | return stdout 315 | -------------------------------------------------------------------------------- /ESLint-Formatter.sublime-commands: -------------------------------------------------------------------------------- 1 | [{ 2 | "caption": "ESLint Formatter: Format this file", 3 | "command": "format_eslint" 4 | }] 5 | -------------------------------------------------------------------------------- /ESLint-Formatter.sublime-settings: -------------------------------------------------------------------------------- 1 | { 2 | // Simply using `node` without specifying a path sometimes doesn't work :( 3 | // If these are false, we'll invoke the eslint binary directly. 4 | // https://github.com/victorporof/Sublime-HTMLPrettify#oh-noez-command-not-found 5 | // http://nodejs.org/#download 6 | "node_path": { 7 | "windows": "node.exe", 8 | "linux": "/usr/bin/nodejs", 9 | "osx": "/usr/local/bin/node" 10 | }, 11 | 12 | // The location to search for a locally installed eslint package. 13 | // These are all relative paths to a project's directory. 14 | // If this is not found or are false, it will try to fallback to a global package 15 | // (see 'eslint_path' below) 16 | "local_eslint_path": { 17 | "windows": "node_modules/eslint/bin/eslint.js", 18 | "linux": "node_modules/.bin/eslint", 19 | "osx": "node_modules/.bin/eslint" 20 | }, 21 | 22 | // The location of the globally installed eslint package to use as a fallback 23 | "eslint_path": { 24 | "windows": "%APPDATA%/npm/node_modules/eslint/bin/eslint", 25 | "linux": "/usr/bin/eslint", 26 | "osx": "/usr/local/bin/eslint" 27 | }, 28 | 29 | // Specify this path to an eslint config file to override the default behavior. 30 | // Passed to eslint as --config. Read more here: 31 | // http://eslint.org/docs/user-guide/command-line-interface#c---config 32 | // If an absolute path is provided, it will use as is. 33 | // Else, it will look for the file in the root of the project directory. 34 | // Failing either, it will skip the config file 35 | "config_path": "", 36 | 37 | // Pass additional arguments to eslint. 38 | // 39 | // Each command should be a string where it supports the following replacements: 40 | // $project_path - The path to the projects root folder 41 | // 42 | // Example: 43 | // ["--parser-options={\"tsconfigRootDir\": \"$project_path\"}"] 44 | "extra_args": [], 45 | 46 | // Automatically format when a file is saved. 47 | "format_on_save": false, 48 | 49 | // Use --fix-to-stdout, --stdin, and --stdin-filename to update the file if using eslint_d. 50 | // See https://github.com/mantoni/eslint_d.js#automatic-fixing 51 | "fix_to_stdout": false, 52 | 53 | // Only attempt to format files with whitelisted extensions on save. 54 | // Leave empty to disable the check 55 | "format_on_save_extensions": [ 56 | "js", 57 | "jsx", 58 | "es", 59 | "es6", 60 | "babel" 61 | ], 62 | 63 | // logs eslint output messages to console when set to true 64 | "debug": false 65 | } 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Paul Irish, Jim Fleming, Eli White 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Main.sublime-menu: -------------------------------------------------------------------------------- 1 | [{ 2 | "id": "tools", 3 | "children": [{ 4 | "id": "eslintformatter_tools", 5 | "caption": "ESLint Formatter", 6 | "children": [{ 7 | "caption": "Format This File", 8 | "command": "format_eslint" 9 | }] 10 | }] 11 | }, { 12 | "id": "preferences", 13 | "children": [{ 14 | "id": "package-settings", 15 | "children": [ 16 | { 17 | "caption": "ESLint Formatter", 18 | "children": [ 19 | { 20 | "caption": "Settings", 21 | "command": "edit_settings", 22 | "args": { 23 | "base_file": "${packages}/ESLint-Formatter/ESLint-Formatter.sublime-settings", 24 | "default": "// Settings in here override those in \"ESLint-Formatter/ESLint-Formatter.sublime-settings\",\n\n{\n\t$0\n}\n" 25 | } 26 | }, 27 | { 28 | "caption": "-" 29 | }, 30 | { 31 | "command": "open_file", 32 | "args": { 33 | "file": "${packages}/ESLint-Formatter/Default (OSX).sublime-keymap", 34 | "platform": "OSX" 35 | }, 36 | "caption": "Key Bindings – Default" 37 | }, 38 | { 39 | "command": "open_file", 40 | "args": { 41 | "file": "${packages}/ESLint-Formatter/Default (Linux).sublime-keymap", 42 | "platform": "Linux" 43 | }, 44 | "caption": "Key Bindings – Default" 45 | }, 46 | { 47 | "command": "open_file", 48 | "args": { 49 | "file": "${packages}/ESLint-Formatter/Default (Windows).sublime-keymap", 50 | "platform": "Windows" 51 | }, 52 | "caption": "Key Bindings – Default" 53 | }, 54 | { 55 | "command": "open_file", 56 | "args": { 57 | "file": "${packages}/User/Default (OSX).sublime-keymap", 58 | "platform": "OSX" 59 | }, 60 | "caption": "Key Bindings – User" 61 | }, 62 | { 63 | "command": "open_file", 64 | "args": { 65 | "file": "${packages}/User/Default (Linux).sublime-keymap", 66 | "platform": "Linux" 67 | }, 68 | "caption": "Key Bindings – User" 69 | }, 70 | { 71 | "command": "open_file", 72 | "args": { 73 | "file": "${packages}/User/Default (Windows).sublime-keymap", 74 | "platform": "Windows" 75 | }, 76 | "caption": "Key Bindings – User" 77 | }, 78 | { 79 | "caption": "-" 80 | }] 81 | }] 82 | }] 83 | }] 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [ESLint-Formatter](https://github.com/TheSavior/ESLint-Formatter) for Sublime Text 3 2 | ================= 3 | 4 | Sublime Text 3 Plugin to autoformat your javascript code according to the ESLint configuration files you already have. 5 | 6 | This plugin formats but does not lint your code. To also enable linting, use this plugin in conjuction with [SublimeLinter-eslint](https://github.com/roadhump/SublimeLinter-eslint). 7 | 8 | 9 | ## Installation 10 | 11 | ### Linter installation 12 | This Sublime Text Plugin depends on a valid installation of eslint version 3 or higher. To install `eslint`, follow the getting started guide: http://eslint.org/docs/user-guide/getting-started. 13 | 14 | ### Plugin installation 15 | 16 | Please use [Package Control](https://sublime.wbond.net/installation) to install the linter plugin. This will ensure that the plugin will be updated when new versions are available. If you want to install from source so you can modify the source code, you probably know what you are doing so we won’t cover that here. 17 | 18 | To install via Package Control, do the following: 19 | 20 | 1. Within Sublime Text, bring up the [Command Palette](http://docs.sublimetext.info/en/sublime-text-3/extensibility/command_palette.html) and type `install`. Among the commands you should see `Package Control: Install Package`. If that command is not highlighted, use the keyboard or mouse to select it. There will be a pause of a few seconds while Package Control fetches the list of available plugins. 21 | 22 | 1. When the plugin list appears, type `eslint format`. Among the entries you should see `ESLint-Formatter`. If that entry is not highlighted, use the keyboard or mouse to select it. 23 | 24 | 25 | ## Commands 26 | **Command palette:** 27 | 28 | - ESLintFormatter: Format this file 29 | 30 | **Shortcut key:** 31 | 32 | * Linux/Windows: [Ctrl + Shift + H] 33 | * Mac: [Cmd + Shift + H] 34 | 35 | ## Behavior 36 | 37 | The formatting will be applied to the last saved state of a file, not the current buffer. 38 | If not using the `format_on_save: true` option, you have to save your file first and then run the command. 39 | 40 | ## Settings 41 | 42 | By default, ESLintFormatter will supply the following settings: 43 | 44 | ```jsonc 45 | { 46 | // The Nodejs installation path 47 | // If these are false, we'll invoke the eslint binary directly. 48 | "node_path": { 49 | "windows": "node.exe", 50 | "linux": "/usr/bin/nodejs", 51 | "osx": "/usr/local/bin/node" 52 | }, 53 | 54 | // The location to search for a locally installed eslint package. 55 | // These are all relative paths to a project's directory. 56 | // If this is not found or are false, it will try to fallback to a global package 57 | // (see 'eslint_path' below) 58 | "local_eslint_path": { 59 | "windows": "node_modules/eslint/bin/eslint.js", 60 | "linux": "node_modules/.bin/eslint", 61 | "osx": "node_modules/.bin/eslint" 62 | }, 63 | 64 | // The location of the globally installed eslint package to use as a fallback 65 | "eslint_path": { 66 | "windows": "%APPDATA%/npm/node_modules/eslint/bin/eslint", 67 | "linux": "/usr/bin/eslint", 68 | "osx": "/usr/local/bin/eslint" 69 | }, 70 | 71 | // Specify this path to an eslint config file to override the default behavior. 72 | // Passed to eslint as --config. Read more here: 73 | // http://eslint.org/docs/user-guide/command-line-interface#c---config 74 | // If an absolute path is provided, it will use as is. 75 | // Else, it will look for the file in the root of the project directory. 76 | // Failing either, it will skip the config file 77 | "config_path": "", 78 | 79 | // Specify the name of a config file, which determines the root of your 80 | // project. This is a pattern such as ".eslintrc.json" or "package.json" 81 | // and will be searched for upwards, to determine the working directory 82 | // for linting. This is different to config_path and is only used for 83 | // resolving the working directory. 84 | "config_file": "", 85 | 86 | // Pass additional arguments to eslint. 87 | // 88 | // Each command should be a string where it supports the following replacements: 89 | // $project_path - The path to the projects root folder 90 | // 91 | // Example: 92 | // ["--parser-options={\"tsconfigRootDir\": \"$project_path\"}"] 93 | "extra_args": [], 94 | 95 | // Automatically format when a file is saved. 96 | "format_on_save": false, 97 | 98 | // Use --fix-to-stdout, --stdin, and --stdin-filename to update the file if using eslint_d. 99 | // See https://github.com/mantoni/eslint_d.js#automatic-fixing 100 | "fix_to_stdout": false, 101 | 102 | // Only attempt to format files with whitelisted extensions on save. 103 | // Leave empty to disable the check 104 | "format_on_save_extensions": [ 105 | "js", 106 | "jsx", 107 | "es", 108 | "es6", 109 | "babel" 110 | ] 111 | } 112 | ``` 113 | 114 | * Modify any settings within the `Preferences -> Package Settings -> ESLint-Formatter -> Settings - User` file. 115 | 116 | **Project-specific settings override** 117 | 118 | To override global plugin configuration for a specific project, add a settings object with a `ESLint-Formatter` key in your `.sublime-project`. This file is accessible via `Project -> Edit Project`. 119 | 120 | For example: 121 | 122 | ``` 123 | { 124 | "folders": [ 125 | { 126 | "path": "." 127 | } 128 | ], 129 | "settings": { 130 | "ESLint-Formatter": { 131 | "format_on_save": true 132 | } 133 | } 134 | } 135 | ``` 136 | 137 | ## Performance 138 | 139 | If you experience performance issues, it may be worth taking a look at [`eslint_d`](https://github.com/mantoni/eslint_d.js). You can modify the settings to point to the `eslint_d` binary instead of `eslint`. 140 | 141 | For example: 142 | 143 | ```javascript 144 | { 145 | "local_eslint_path": { 146 | "osx": "node_modules/.bin/eslint_d" 147 | } 148 | } 149 | ``` 150 | 151 | ## Contributing 152 | 153 | If you find any bugs feel free to report them [here](https://github.com/TheSavior/ESLint-Formatter/issues). 154 | 155 | Pull requests are also encouraged. 156 | -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "1.0.0": "messages/1.0.0.txt", 3 | "1.0.1": "messages/1.0.1.txt", 4 | "2.0.0": "messages/2.0.0.txt", 5 | "2.0.1": "messages/2.0.1.txt", 6 | "2.1.0": "messages/2.1.0.txt", 7 | "2.1.1": "messages/2.1.1.txt", 8 | "2.2.0": "messages/2.2.0.txt", 9 | "2.2.1": "messages/2.2.1.txt", 10 | "2.3.0": "messages/2.3.0.txt", 11 | "2.3.1": "messages/2.3.1.txt", 12 | "2.4.0": "messages/2.4.0.txt", 13 | "2.4.1": "messages/2.4.1.txt", 14 | "2.4.2": "messages/2.4.2.txt", 15 | "2.4.3": "messages/2.4.3.txt", 16 | "2.4.4": "messages/2.4.4.txt", 17 | "2.4.5": "messages/2.4.5.txt" 18 | } 19 | -------------------------------------------------------------------------------- /messages/1.0.0.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 1.0.0 changelog 2 | 3 | Thanks for installing the ESLint-Formatter! 4 | -------------------------------------------------------------------------------- /messages/1.0.1.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 1.0.1 changelog 2 | 3 | [Fix]: Fix compatibility to run alongside the JSCS-Formatter plugin 4 | -------------------------------------------------------------------------------- /messages/2.0.0.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 2.0.0 changelog 2 | 3 | [Breaking] format_on_save will now only format specific, configurable extensions. 4 | Defaults to: "js", "jsx", "es", "es6", "babel" 5 | -------------------------------------------------------------------------------- /messages/2.0.1.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 2.0.1 changelog 2 | 3 | [Fix] Fixing format on save. Now formats on save. https://github.com/TheSavior/ESLint-Formatter/pull/14 4 | -------------------------------------------------------------------------------- /messages/2.1.0.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 2.1.0 changelog 2 | 3 | [Feature] Try to use local eslint before falling back to eslint_path (https://github.com/TheSavior/ESLint-Formatter/pull/13) 4 | -------------------------------------------------------------------------------- /messages/2.1.1.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 2.1.1 changelog 2 | 3 | [Fix] Fixing broken reference to glob 4 | -------------------------------------------------------------------------------- /messages/2.2.0.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 2.2.0 changelog 2 | 3 | [Feat] Try to find ESLint by looking at the sublime project's path 4 | and finding up to the root for node_modules/.bin/eslint 5 | -------------------------------------------------------------------------------- /messages/2.2.1.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 2.2.1 changelog 2 | 3 | [Fix] Improve running a local copy eslint on Windows 4 | [Fix] Improve finding the local eslint based on the project path 5 | -------------------------------------------------------------------------------- /messages/2.3.0.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 2.3.0 changelog 2 | 3 | [Feat] Look for local eslint based on file path, not just at root 4 | [Feat] Make it easier to open settings by opening default and user settings 5 | -------------------------------------------------------------------------------- /messages/2.3.1.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 2.3.1 changelog 2 | 3 | [Fix] Look up file tree for node_modules/eslint vs the nearest package.json 4 | -------------------------------------------------------------------------------- /messages/2.4.0.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 2.4.0 changelog 2 | 3 | [Feat] Support invoking eslint from path, without explicit node (opt-in via config) 4 | [Feat] Support `extra_args` config to pass additional arguments to eslint 5 | [Feat] Support invoking `eslint_d` using stdio and updating the view in the on_pre_save hook 6 | -------------------------------------------------------------------------------- /messages/2.4.1.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 2.4.1 changelog 2 | 3 | [Fix] Fix `Global name 'data' is not defined` 4 | -------------------------------------------------------------------------------- /messages/2.4.2.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 2.4.2 changelog 2 | 3 | [Fix] Remove unwanted error dialogs 4 | -------------------------------------------------------------------------------- /messages/2.4.3.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 2.4.3 changelog 2 | 3 | [Fix] Added new `config_file` option to allow better working directory resolution 4 | -------------------------------------------------------------------------------- /messages/2.4.4.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 2.4.4 changelog 2 | 3 | [Fix] Throwing exception only if eslint returns non-zero exit code, suprassing warnings thrown by eslint reported here https://github.com/elicwhite/ESLint-Formatter/issues/94. 4 | -------------------------------------------------------------------------------- /messages/2.4.5.txt: -------------------------------------------------------------------------------- 1 | ESLint-Formatter 2.4.5 changelog 2 | 3 | [Fix] Presenting error dialog on any unfixable ESLint error, Bug reported here https://github.com/elicwhite/ESLint-Formatter/issues/97. 4 | --------------------------------------------------------------------------------