Skip to content
This repository has been archived by the owner on Apr 10, 2021. It is now read-only.

Apply EditorConfig formatting only when saving a file #80

Closed
bennycode opened this issue Jun 18, 2015 · 19 comments
Closed

Apply EditorConfig formatting only when saving a file #80

bennycode opened this issue Jun 18, 2015 · 19 comments

Comments

@bennycode
Copy link
Member

As per user request (#74, #77), we will only reformat files / apply EditorConfig rules when a file is explicitly changed from the NetBeans editor window.

@johnny-bit
Copy link

+1 👍 So - format on save + format on click "format source" in conext menu? i'd rather only have format on click ;)

@pniederlag
Copy link

+1 for format via menu "source/format" or click on context "format"
-1 for format on save

@FinBoWa
Copy link

FinBoWa commented Jun 21, 2015

👍 on formatting when requesting a format anywhere (don't forget that you can call format for a directory structure also :)
👍 on formatting on save IF its something that can be disabled/enabled per project or globally

I'm not sure whats the take on other plugins that how they work relating formatting on save.

Case example where automatic on save formatting is bad:
you amend a old file add a minor fix or enhancement for it > you end up with a diff with loads of unnecessary changes

@FinBoWa
Copy link

FinBoWa commented Jun 21, 2015

then we get to the question: if the "format on save" is a toggle-able thing should it be on by default or off.

@bennycode
Copy link
Member Author

Format on save should be always on because the EditorConfig will only format files which match the patterns that have been declared in the .editorconfig file. If you don't want to apply EditorConfig rules to legacy files then you should adjust the globs used in your .editorconfig file our you could add another .editorconfig file for this particular folder which overwrites the default EditorConfig style.

@jscssphtml
Copy link

+1 for format via menu "source/format" or click on context "format"
+1 for toggle-able on-save

@galeksandrp
Copy link
Contributor

👍

@kepi
Copy link

kepi commented Sep 2, 2015

👍

We can't use this plugin at all without this. I believe that editor's task is to edit opened file, not doing magic on all files in project.

@martin-kolar
Copy link

👍

1 similar comment
@michalgritzbach
Copy link

👍

@jyrkij
Copy link

jyrkij commented Sep 4, 2015

👍 for format via menu "source/format" or click on context "format"
👍 for toggle-able on-save

(shamelessly copy pasting from @jscssphtml)

@fboes
Copy link

fboes commented Sep 9, 2015

+1 & 👍 on this one; other editors only change files on save. They do not scan pro-actively for files to change.

Is there any quick fix for this problem, because one of our coders can't convince his NetBeans to leave legacy code alone, and has a major problem working with our Sublime text guys.

@FinBoWa
Copy link

FinBoWa commented Sep 9, 2015

@fboes only fix that we have found to be solid is to remove the extension out of netbeans for the time being and set NB:s own formatting as close as possible per file type and just call format on NB manually.

Atleast for the indentations and just ignore possible differences on ending spaces and whatnots :).

Of course if most of the legacy code is in a subfolder then you could prevent formatting like @bennyn suggests:

"If you don't want to apply EditorConfig rules to legacy files then you should adjust the globs used in your .editorconfig file our you could add another .editorconfig file for this particular folder which overwrites the default EditorConfig style."

That should prevent the autoformatting atleast for now when opening the project on netbeans.

@fboes
Copy link

fboes commented Sep 9, 2015

@FinBoWa Thx, @bennyn is completely right. And we just found out more about .editorconfig's capabilities by targeting specific folders. I paste our small demo snippet here in case someone wants to follow our footsteps (this may be even smarter than providing an .editorconfig you do not want your team to use anyhow ;)):

  [*]
  charset = utf-8

  [htdocs/sites/all/{modules/custom/**/*,themes/**/*}]
  indent_style = tab
  insert_final_newline = true
  trim_trailing_whitespace = true
  end_of_line = lf
  tab_width = 4

@Yserz Yserz self-assigned this Sep 12, 2015
@Yserz
Copy link
Member

Yserz commented Sep 12, 2015

Finally I had some time :) Hang on for pre-release 0.8 📦

@bennycode bennycode added this to the v0.0.8 milestone Sep 12, 2015
@bennycode
Copy link
Member Author

Thanks for the great feedback from everyone here!

Your +1's helped us to make an easy descision on what goes next into the plugin. A big "Thank you" also goes out to @Yserz for implementing the requested change.

Please download v0.0.8 and give us feedback if everything works now like expected.

@FinBoWa
Copy link

FinBoWa commented Sep 16, 2015

One bug so far.. Or is it actually.

Open a file in get it to fire a save for the file > format happens > close the file in NB > reset the file changes with git for example (you don't just want to commit anything) > wait for a while > editorconfig related changes return back.

Same thing happens even without going the previous steps. Just open netbeans and call "touch README.md" for example.

@Yserz
Copy link
Member

Yserz commented Sep 17, 2015

Jeah, we are listening for changes for every file which is covered by the editorconfig. This does not only effect NetBeans changes. If you change it with another editor and save it while the project is still opened in NetBeans, it will apply the editorconfig rules automatically. The same applies when the git plugin saves the revert. Could be considered as feature too :) Dunno right now if we can change the way we detect file changes or differentiate the tool which saves the changes.

@FinBoWa
Copy link

FinBoWa commented Sep 18, 2015

Tru dat :) . I have used that behaviour to fire up stuff on netbeans. NB it doesn't allow you to fire up a save without changing the contents so mostly I end up calling touch from the filesystem.

@Yserz Yserz closed this as completed Sep 20, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests