问题描述
在设置>中代码风格JavaScript 我已经将 Tab size
和 Indent
设置为 4.为什么 WebStorm 仍然忽略这些设置,正如您在预览窗口中看到的:
In Settings > Code Style > JavaScript
I've set Tab size
and Indent
to 4. Why is WebStorm still ignoring these settings, as you can see in the preview window:
哪些设置可以覆盖这些?
What settings could override these?
推荐答案
如果您启用了 EditorConfig 插件(默认情况下应该是这样)并且在您的项目中有 .editorconfig
文件(或者甚至更高)项目根目录)然后那里的设置将覆盖您的代码样式(这是预期的,因为这是此类插件的全部内容).
If you have EditorConfig plugin enabled (which should be by default) and have .editorconfig
files in your project (or maybe even above the project root) then settings from there will override your Code Style (which is expected as this is the whole point of such plugin).
为什么会有这种行为?可以做什么?
Why such behaviour? What can be done?
- 请检查
.editorconfig
文件的用途——它们是独立于编辑器的.这意味着覆盖您的内部设置以在使用的不同 IDE/编辑器之间提供一致性,而无需仅为该项目/文件夹配置您的 IDE/编辑器 - 您正在编辑代码样式设置,而不是实际的 EditorConfig 设置
- 使用
.editorconfig
,您可以执行代码样式当前无法实现的操作(例如,针对不同文件类型的不同右边距/尾随空白处理,即使代码样式不支持它们) - 代码样式适用于整个项目(所有文件),而
.editorconfig
可以针对每个子文件夹进行不同的配置,甚至可以排除. - IDE 应该向您显示通知(使用浅色 GUI 主题,它会是编辑器窗口顶部的绿色条),它会告诉您editorconfig 文件覆盖您的代码样式设置"——我只是不确定是否它在 WebStorm v11 中可用..或者是仅从 v12 开始.
- 如果您在设置中上一级(只是
Code Style
而不是Code Style > JavaScript
如您的屏幕截图),您会看到这一刻被提及为好吧 - 您可以在 JetBrains 的 问题跟踪器.
- Please check what
.editorconfig
files are for -- they meant to be editor-independent. It meant to override your internal settings to provide consistency across different IDEs/editors used without the need to configure your IDE/editor just for this project/folder - You are editing Code Style settings and not actual EditorConfig settings
- With
.editorconfig
you can do things that are not currently possible with Code Style (e.g. different right margins / trailing white space handling per different file types, even if they are not supported by Code Style) - Code Style is applied to the whole project (all files) while
.editorconfig
can be configured differently for each sub-folder and even have exclusions. - IDE should be showing you the notice (using light GUI theme it would be green bar on top of the editor window) where it would tell that "editorconfig file overriding your Code Style settings" -- I'm just not sure if it's available in WebStorm v11 . .or is it since v12 only.
- If you go one level up in your settings (just
Code Style
and notCode Style > JavaScript
as on your screenshot) you will see mention of this moment as well - You may file Feature Request ticket for such "update .editorconfig file while editing Code Style" idea at JetBrains' Issue Tracker.
这篇关于JetBrains WebStorm 忽略缩进设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!