Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle double-indent followed by double-outdent #89

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

fumer-fubotv
Copy link
Collaborator

@fumer-fubotv fumer-fubotv commented Apr 2, 2024

Fixes #85

Copy link
Member

@TwitchBronBron TwitchBronBron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still isn't working quite right. It's losing indentation. Check out this example:

format-bad

Here's the code for this example:

namespace tests
    class TestStuff
        function _()
            m.assertEqual(sanitize({
                key_0: { env: [], themes: ["any"] }
                key_1: { env: ["any"], themes: ["test"] }
                key_2: { env: ["prod"], themes: ["test"] }
                key_3: { env: ["prod"], themes: ["test"] }
                key_4: { env: ["prod", "qa"], themes: ["test", "test"] }
                key_5: { env: ["dev", "qa"], themes: ["test"] }
                key_6: { env: ["dev", "qa"], themes: ["test", "test"] }
                key_7: { env: ["dev", "qa"], themes: ["test"] }
                key_8: { env: [], themes: [] }
                key_9: { env: ["any"], themes: ["any"], runtimeCheck: function() as boolean
                        return true
                end function }
                key_10: { env: ["any"], themes: ["any"], runtimeCheck: function() as boolean
                        return false
                end function }
                key_11: { env: ["dev"], themes: ["any"], runtimeCheck: function() as boolean
                        return true
                end function }
                key_12: { env: ["any"], themes: ["test"], runtimeCheck: function() as boolean
                        return true
                end function }
            }, "prod", "test"), {
                enabled: ["key_1", "key_2", "key_4", "key_9"]
                available: ["key_0", "key_1", "key_10", "key_11", "key_12", "key_2", "key_3", "key_4", "key_5", "key_6", "key_7", "key_8", "key_9"]
            })
        end function
    end class
end namespace

Copy link
Member

@TwitchBronBron TwitchBronBron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's another edge case I found when running this latest version of the formatter against our codebase. It's double-indenting AA members inside a function call inside an array:

format-bad2

sub createSections(navigationAction as object)
	m.sections = [FormatJson({
		type: "test"
		components: [{
			type: "test"
			group_id: "1"
		}]
		slug: "test"
	})]
end sub

@TwitchBronBron
Copy link
Member

However, here's another test that is failing. It's incorrectly adding 1 more indent to the lower end stuff than it should:

it.only('formats properly', () => {
    expect(formatter.format(undent`
        namespace alpha
            namespace beta
                sub createSections()
                    m.sections = [
                        FormatJson({
                        })]
                end sub
            end namespace
        end namespace
    `, { formatMultiLineObjectsAndArrays: false })).to.equal(undent`
        namespace alpha
            namespace beta
                sub createSections()
                    m.sections = [
                        FormatJson({
                    })]
                end sub
            end namespace
        end namespace
    `);
});

@fumer-fubotv
Copy link
Collaborator Author

Here's another edge case I found when running this latest version of the formatter against our codebase. It's double-indenting AA members inside a function call inside an array:

format-bad2 format-bad2

sub createSections(navigationAction as object)
	m.sections = [FormatJson({
		type: "test"
		components: [{
			type: "test"
			group_id: "1"
		}]
		slug: "test"
	})]
end sub

Cannot reproduce while adding this block as a test

Copy link
Member

@TwitchBronBron TwitchBronBron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found another bug. The indent formatter gets out of sync when it encounters empty lines inside an AA. I pushed the failing test and marked it .only().

Copy link
Member

@TwitchBronBron TwitchBronBron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found another bug.

it.only('handles unique AA formatting', () => {
    formatEqual(undent`
        function _()
            aa = {
                key_12: {
                    env: ["any"], runtimeCheck: function() as boolean
                        return true
                end function }
            }
            print "hello"
        end function
    `, undefined, {
        indentStyle: 'tabs',
        formatMultiLineObjectsAndArrays: false
    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

handle double-indent followed by double-outdent
2 participants