sindresorhus / atom-editorconfig

Helps developers maintain consistent coding styles between different editors
https://atom.io/packages/editorconfig
MIT License
812 stars 80 forks source link

EditorConfig overrides default Atom settings on projects without .editorconfig file #181

Closed tzvetkoff closed 7 years ago

tzvetkoff commented 7 years ago

The EditorConfig plugin overrides the default editor settings in projects without .editorconfig file.

The problem resides in index.js, more specifically handling settings with value auto.

Example debug of

if (settings.tab_width === 'auto') {
  console.log('XXX: Setting `editor.tabLength` to default value of: ', atom.config.get('editor.tabLength', configOptions));
  editor.setTabLength(atom.config.get('editor.tabLength', configOptions));
} else {
  console.log('XXX: Setting `editor.tabLength` to EditorConfig value of: ', settings.tab_width);
  editor.setTabLength(settings.tab_width);
}

yields

XXX: Setting `editor.tabLength` to default value of:  2

to console, when opening a Makefile.

I'd propose doing nothing when the configured value is set to auto, otherwise it breaks general editor features.

Directory structure

.
└── Makefile

0 directories, 1 file

Makefile contents

foobar:
    $(CC)

Atom scope config

".makefile.source":
  editor:
    tabLength: 4
    tabType: "hard"

Installed packages

Built-in Atom Packages (89)
├── atom-dark-syntax@0.28.0
├── atom-dark-ui@0.53.0
├── atom-light-syntax@0.29.0
├── atom-light-ui@0.46.0
├── base16-tomorrow-dark-theme@1.4.0
├── base16-tomorrow-light-theme@1.4.0
├── one-dark-ui@1.9.1
├── one-light-ui@1.9.1
├── one-dark-syntax@1.6.0
├── one-light-syntax@1.6.0
├── solarized-dark-syntax@1.1.1
├── solarized-light-syntax@1.1.1
├── about@1.7.2
├── archive-view@0.62.2
├── autocomplete-atom-api@0.10.0
├── autocomplete-css@0.14.1
├── autocomplete-html@0.7.2
├── autocomplete-plus@2.34.2
├── autocomplete-snippets@1.11.0
├── autoflow@0.29.0
├── autosave@0.24.0
├── background-tips@0.26.1
├── bookmarks@0.43.4
├── bracket-matcher@0.85.2
├── command-palette@0.39.2
├── deprecation-cop@0.56.2
├── dev-live-reload@0.47.0
├── encoding-selector@0.22.0
├── exception-reporting@0.41.0
├── find-and-replace@0.206.3
├── fuzzy-finder@1.4.1
├── git-diff@1.2.0
├── go-to-line@0.31.2
├── grammar-selector@0.48.2
├── image-view@0.60.0
├── incompatible-packages@0.26.1
├── keybinding-resolver@0.35.0
├── line-ending-selector@0.5.1
├── link@0.31.2
├── markdown-preview@0.159.6
├── metrics@1.1.3
├── notifications@0.66.1
├── open-on-github@1.2.1
├── package-generator@1.0.2
├── settings-view@0.246.0
├── snippets@1.0.5
├── spell-check@0.70.2
├── status-bar@1.7.0
├── styleguide@0.48.0
├── symbols-view@0.114.0
├── tabs@0.104.1
├── timecop@0.33.2
├── tree-view@0.213.1
├── update-package-dependencies@0.10.0
├── welcome@0.36.0
├── whitespace@0.36.1
├── wrap-guide@0.39.0
├── language-c@0.54.1
├── language-clojure@0.22.1
├── language-coffee-script@0.48.2
├── language-csharp@0.14.0
├── language-css@0.41.0
├── language-gfm@0.88.0
├── language-git@0.19.0
├── language-go@0.43.1
├── language-html@0.47.1
├── language-hyperlink@0.16.1
├── language-java@0.25.0
├── language-javascript@0.125.1
├── language-json@0.18.3
├── language-less@0.30.0
├── language-make@0.22.3
├── language-mustache@0.13.1
├── language-objective-c@0.15.1
├── language-perl@0.37.0
├── language-php@0.37.3
├── language-property-list@0.9.0
├── language-python@0.45.1
├── language-ruby@0.70.4
├── language-ruby-on-rails@0.25.1
├── language-sass@0.57.1
├── language-shellscript@0.25.0
├── language-source@0.9.0
├── language-sql@0.25.2
├── language-text@0.7.1
├── language-todo@0.29.1
├── language-toml@0.18.1
├── language-xml@0.34.15
└── language-yaml@0.27.2

Community Packages (18) /Users/w00t/.atom/packages
├── autocomplete-clang@0.10.0
├── editorconfig@2.2.1
├── highlight-selected@0.12.0
├── language-autotools@2.0.1
├── language-roff@1.2.1
├── language-rpm-spec@0.12.0
├── language-tcl@0.1.2
├── linter@1.11.23
├── linter-clang@3.4.8
├── linter-coffeelint@1.2.1
├── linter-go@0.1.0
├── linter-sass-lint@1.7.4
├── markdown-pdf@1.5.0
├── minimap@4.26.8
├── minimap-highlight-selected@4.5.0
├── minimap-linter@1.6.0
├── minimap-selection@4.4.0
└── set-syntax@0.3.2
florianb commented 7 years ago

Hi @tzvetkoff - thank you for reporting this.

Unfortunately i am not able to reproduce your described behavior. Could you please post the content of the involved .editoroconfig-file as well as the output of the EditorConfig: Show State command?

As a first explanation: If the setting is recognized being set to auto, the default setting from the Editor get's applied as it is being done when the editor is being opened. This is currently done to explicitly reset any changes from the editorconfig. The auto-setting is fetching the predefined settings from Atom's config and it is also scope-aware.

tzvetkoff commented 7 years ago

To reproduce:

florianb commented 7 years ago

What is the output of EditorConfig: Show State for the makefile?

tzvetkoff commented 7 years ago

Here's the output from EditorConfig: Show State (I couldn't copy it whole, so I uploaded an image):

screen shot 2017-02-20 at 17 01 20
florianb commented 7 years ago

Thanks - i still can't verify that behavior.

Try disabling "language-autotools" instead.

tzvetkoff commented 7 years ago

Yak... It's language-autotools indeed. They overwrite the grammar definition for Makefile (as it's based on name, not scope - and change their scope to source.makefile2) Will write to their author to fix that.

Sorry for the incorrect report, and thanks for the quick reply!

florianb commented 7 years ago

You are welcome @tzvetkoff! Happy hacking!