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

Allow omitting parentheses for Expression.asA(Expression other) #436

Open
Robbendebiene opened this issue Nov 8, 2023 · 2 comments
Open

Comments

@Robbendebiene
Copy link

Expression.asA(Expression other) always wraps the code into parentheses. While this is a good default it is not always necessary. The problem for me is that the generated code triggers the linter rule unnecessary_parenthesis in our CI. Unfortunately dart_style auto fixes does not support the removal of unnecessary parenthesis.

My suggestion would be to have an optional parameter.
the following:

Expression asA(Expression other) =>
ParenthesizedExpression._(BinaryExpression._(
expression,
other,
'as',
));

becomes

  Expression asA(Expression other, { bool parenthesized = true }) {
     final exp = BinaryExpression._( expression, other,  'as'));
     return parenthesized
        ? ParenthesizedExpression._(exp)
        : exp
  }
@natebosch
Copy link
Member

natebosch commented Nov 9, 2023

We typically recommend avoiding that type of style lint for generated code. As mentioned in #213 readability is not a goal for the generated output from this package. This is a relatively easy change though, and most of the complexity stays in the calling code deciding what value to pass.

@srawlins do you have any opinions on adding this option?

@srawlins
Copy link
Member

srawlins commented Nov 9, 2023

Yeah I think that supporting a parenthesized parameter everywhere (it's not just asA right?) would add a fair amount of complexity.

I recommend using // ignore_for_file: type=lint for generated files. See https://dart.dev/tools/analysis#suppressing-rules-for-a-file.

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

3 participants