mark-wiemer-org/ahkpp

Formatter incorrectly indents object literals

Closed this issue · 1 comments

This may be a very niche situation / edge case due to a way that I have found you can create object literals in a relatively compact but easily readable form (coming from a javascript/JSON background, comma-placement notwithstanding), in which case feel free to wontfix. But I'll describe it anyway...

On Format Document, the formatter indents the first object correctly (one tab), but after that goes wild with the tabs and double-indents the second object (3 tabs), triple indents the third object (4 tabs). It also pulls the last line of the object back in by one tab, so it's in line with its definition. From the end of the function as exampled below to the end of the file the formatter keeps the 4-tabs as the new left margin! And the one super-indented line "useToast" isn't a typo, it does get pushed in one more tab.

Unformatted code

[... AUTORUN SECTION etc]
global __Settings := {}
populateGlobalVars()
return

populateGlobalVars(){
	__Settings.app := {0:0
		, name: "[...]"
		, author: { name: "[...]", email: "[...]", company: "[...]" }
		, build: { version: "[...]", date: "[...]", repo: "[...]" } }

	__Settings.app.tray := {0:0
		, title: __Settings.app.name
		, traytip: "[=" . __Settings.app.name . "]"
		, icon: { location: (A_IsCompiled ? A_ScriptName : "icons\cog-wheel-3.ico"), index: -0 }
		, useToast: getIniVal("Tray\useToast", true)
		, msgTimeout: 2000 }

	__Settings.app.environment := {0:0
		, company: getIniVal("Environment\company", __Settings.app.author.company)
		, computerName: A_ComputerName
		, user: A_UserName
		, domain: getAppEnvironmentDomain() }

	__Settings.app.debugging := {0:0
		, enabledOnInit: getIniVal("AppDebugging\enabled", !A_IsCompiled)
		, activeOnInit: getIniVal("AppDebugging\active", !A_IsCompiled)
		, notifyUser: getIniVal("AppDebugging\notify", true)
		, menuLabel: "Debugging mode" }
	__Settings.app.debugging.enabled := (__Settings.app.debugging.activeOnInit ? true : __Settings.app.debugging.enabledOnInit)
	__Settings.app.debugging.active := (__Settings.app.debugging.enabled && __Settings.app.debugging.activeOnInit)
}

Expected formatted output

(Same as above)

Actual formatted output

populateGlobalVars(){
	__Settings.app := {0:0
		, name: "[...]"
		, author: { name: "[...]", email: "[...]", company: "[...]" }
		, build: { version: "[...]", date: "[...]", repo: "[...]" } }

			__Settings.app.tray := {0:0
				, title: __Settings.app.name
				, traytip: "[=" . __Settings.app.name . "]"
				, icon: { location: (A_IsCompiled ? A_ScriptName : "icons\cog-wheel-3.ico"), index: -0 }
					, useToast: getIniVal("Tray\useToast", true)
				, msgTimeout: 2000 }

				__Settings.app.environment := {0:0
					, company: getIniVal("Environment\company", __Settings.app.author.company)
					, computerName: A_ComputerName
					, user: A_UserName
				, domain: getAppEnvironmentDomain() }

				__Settings.app.debugging := {0:0
					, enabledOnInit: getIniVal("AppDebugging\enabled", !A_IsCompiled)
					, activeOnInit: getIniVal("AppDebugging\active", !A_IsCompiled)
					, notifyUser: getIniVal("AppDebugging\notify", true)
				, menuLabel: "Debugging mode" }
				__Settings.app.debugging.enabled := (__Settings.app.debugging.activeOnInit ? true : __Settings.app.debugging.enabledOnInit)
				__Settings.app.debugging.active := (__Settings.app.debugging.enabled && __Settings.app.debugging.activeOnInit)
				}

Hey @Cirieno , thanks for opening this bug. Are you able to provide a slightly smaller object with values like foo and bar so that we can more easily debug the problem? It's pretty clear, but a short 5-10 line snippet would work wonders to make sure we're all on the same page :)