Enforce Styles on Save? ST3? #33

Closed
mysterycommand opened this Issue Aug 14, 2014 · 7 comments

Projects

None yet

5 participants

@mysterycommand

A few of these issues seem to indicate that this plugin should enforce a .editorconfig's rules on a file when that file is saved, but I have a JS file with 2-space indentation that I want to convert to 4-space indentation and saving, opening, etc. the file isn't doing anything. Am I misinterpreting what this plugin is supposed to do? SublimeText 3, Build 3059 on Mac OS X 10.9.4. Here's my .editorconfig:

# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.json]
indent_size = 2

[*.md]
trim_trailing_whitespace = false

… and here's my ST3 console (I don't know if this is actually useful):

startup, version: 3059 osx x64 channel: stable
executable: /Applications/Sublime Text.app/Contents/MacOS/Sublime Text
working dir: /
packages path: /Users/matthayes/Library/Application Support/Sublime Text 3/Packages
state path: /Users/matthayes/Library/Application Support/Sublime Text 3/Local
hardware concurrency: 8
zip path: /Applications/Sublime Text.app/Contents/MacOS/Packages
zip path: /Users/matthayes/Library/Application Support/Sublime Text 3/Installed Packages
found 14 files for base name Default.sublime-keymap
found 1 files for base name Default.sublime-mousemap
found 13 files for base name Main.sublime-menu
loading bindings
loading pointer bindings
found 1 files for base name Spacegray Light.sublime-theme
theme loaded
app ready
wrote startup cache, added files: 7 orphaned files: 0 total files: 158 cache hits: 151
pre session restore time: 0.279394
using gpu buffer for window
using gamma: 2 (err: 6.9282)
first paint time: 0.60469
startup time: 0.676102
using gpu buffer for window
launching: /Applications/Sublime Text.app/Contents/MacOS/plugin_host
loaded 1319 snippets
reloading plugin Default.block
reloading plugin Default.comment
reloading plugin Default.copy_path
reloading plugin Default.delete_word
reloading plugin Default.detect_indentation
reloading plugin Default.duplicate_line
reloading plugin Default.echo
reloading plugin Default.exec
reloading plugin Default.fold
reloading plugin Default.font
reloading plugin Default.goto_line
reloading plugin Default.history_list
reloading plugin Default.indentation
reloading plugin Default.kill_ring
reloading plugin Default.mark
reloading plugin Default.new_templates
reloading plugin Default.open_file_settings
reloading plugin Default.open_in_browser
reloading plugin Default.pane
reloading plugin Default.paragraph
reloading plugin Default.paste_from_history
reloading plugin Default.save_on_focus_lost
reloading plugin Default.scroll
reloading plugin Default.set_unsaved_view_name
reloading plugin Default.side_bar
reloading plugin Default.sort
reloading plugin Default.swap_line
reloading plugin Default.switch_file
reloading plugin Default.symbol
reloading plugin Default.transform
reloading plugin Default.transpose
reloading plugin Default.trim_trailing_white_space
reloading plugin CSS.css_completions
reloading plugin Diff.diff
reloading plugin HTML.encode_html_entities
reloading plugin HTML.html_completions
reloading plugin AdvancedNewFile.AdvancedNewFile
reloading plugin DocBlockr.__init__
reloading plugin DocBlockr.jsdocs
reloading plugin EditorConfig.EditorConfig
reloading plugin Emmet.emmet-plugin
reloading plugin Markdown Preview.helper
reloading plugin Markdown Preview.markdown_settings
reloading plugin Markdown Preview.markdown_wrapper
reloading plugin Markdown Preview.MarkdownPreview
reloading plugin Minifier.Minify
reloading plugin Package Control.Package Control
reloading plugin Pretty JSON.PrettyJson
[Errno 2] No such file or directory: 'jq'
reloading plugin SideBarEnhancements.Edit
reloading plugin SideBarEnhancements.SideBar
reloading plugin SideBarEnhancements.SideBarDefaultDisable
reloading plugin SideBarEnhancements.StatusBarFileSize
reloading plugin SideBarEnhancements.StatusBarModifiedTime
reloading plugin SublimeLinter-csslint.linter
SublimeLinter: csslint linter loaded 
reloading plugin SublimeLinter-jshint.linter
SublimeLinter: jshint linter loaded 
reloading plugin SublimeLinter-json.linter
SublimeLinter: json linter loaded 
reloading plugin TrailingSpaces.trailing_spaces
reloading plugin CSScomb JS.CSScomb
reloading plugin SFTP.SFTP
reloading plugin SublimeLinter.commands
reloading plugin SublimeLinter.sublimelinter
plugins loaded
SublimeLinter: debug mode: off 
found 13 files for base name Main.sublime-menu
PyV8: Creating new thread
Emmet: Creating thread
Emmet: Loading https://api.github.com/repos/emmetio/pyv8-binaries/contents
Emmet: You have the most recent PyV8 binary
Package Control: No updated packages
SublimeLinter: Using an unsupported shell: sh 
SublimeLinter: jshint activated: /usr/local/bin/jshint 
Writing file /Users/matthayes/path/to/project/gulpfile.js with encoding UTF-8 (atomic)
@sindresorhus
Owner

Yeah, that's a bug, or rather the problem is that Sublime doesn't do anything with spaces when you change the indentation size.

A fix for this plugin might be to use the file detected indentation (in this case 2 space) and convert to tab indentation, set indentation size to 4 and then convert back to spaces. That seems to be the only way in Sublime to change the indentation. I'm open to suggestions though.

@mysterycommand

Can that process be automated/handled by the package, or you mean just via the UI in the bottom right? I've done that before, but it's pretty tedious if you're trying to standardize across a project with mixed file configs … also, doesn't help in the case of mixed indentation … though I'm not sure what could be done programmatically to handle that.

Anyway, thanks for the feedback.

@sindresorhus
Owner

Can that process be automated/handled by the package

Yes, that's what I was trying to imply.

@mysterycommand

Well then that sounds awesome. 👍

@jbrooksuk

Any news on automating that process?

@margaritis

+1

@sircharleswatson

+1 on this

also, trim_trailing_whitespace = true doesnt seem to be working on ST3 either.

@kalebtrotter kalebtrotter pushed a commit to kalebtrotter/editorconfig-sublime that referenced this issue Jun 16, 2015
@ktrotter-emsi ktrotter-emsi Force whitespace pre-save
Removing the ‘spaces == True/False’ check in the apply_pre_save method
allows Sublime to enforce the tabs/spaces style throughout the
document, as requested in issue #33
3c5e359
@sindresorhus sindresorhus added a commit that referenced this issue Jul 26, 2015
@sindresorhus Revert "Close #47 PR: Force whitespace pre-save. Fixes #33"
This reverts commit 1912349.
07b8896
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment