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

Method with throws keyword is not formatted in the ideal way #365

Closed
digorydoo opened this issue Feb 14, 2020 · 2 comments
Closed

Method with throws keyword is not formatted in the ideal way #365

digorydoo opened this issue Feb 14, 2020 · 2 comments

Comments

@digorydoo
Copy link

Prettier-Java 0.7.0

{
   "trailingComma": "es5",
   "tabWidth": 4,
   "useTabs": false,
   "printWidth": 100,
   "semi": true,
   "singleQuote": false,
   "quoteProps": "consistent",
   "jsxSingleQuote": false,
   "bracketSpacing": true,
   "jsxBracketSameLine": false,
   "arrowParens": "always",
   "endOfLine": "lf"
}

Input:

    public void parse(
        InputStream xmlInput, Vocabulary vocab, Vocabulary.Kind kind
    ) throws XmlPullParserException, IOException
    {
        XmlPullParser parser = Xml.newPullParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        // more stuff
    }

Output:

    public void parse(InputStream xmlInput, Vocabulary vocab, Vocabulary.Kind kind)
        throws XmlPullParserException, IOException {
        XmlPullParser parser = Xml.newPullParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        // more stuff
    }

Expected behavior:

Not sure what is the best way, but the above is hard to read, because the throws keyword is emitted using the same indentation as the first line of the method. One way to do this better would be to indent it like how my original input was, another would be to add a newline to the start of the body:

    public void parse(InputStream xmlInput, Vocabulary vocab, Vocabulary.Kind kind)
        throws XmlPullParserException, IOException {

        XmlPullParser parser = Xml.newPullParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        // more stuff
    }
@murdos
Copy link

murdos commented Feb 14, 2020

@digorydoo : have you seen discussion on related subject: #286 ?

@digorydoo
Copy link
Author

Ah, OK, that's a duplicate then. The proposed solution from #286 (comment) doesn't look good in my opinion, though.

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

No branches or pull requests

2 participants