Skip to content

feat!: allow analyzer 7.0.0 and update dart_style to ^3.0.0 #970

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Peetee06
Copy link

@Peetee06 Peetee06 commented May 28, 2025

Allows analyzer version ^7.0.0 and update dart_style to ^3.0.0.

The update of dart_style to ^3.0.0 is a breaking change.

Related issue: #950


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

Copy link

github-actions bot commented Jun 2, 2025

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
intl_translation Breaking 0.20.1 0.21.0-wip 0.21.0 ✔️
Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

Coverage ✔️
File Coverage
pkgs/intl_translation/lib/src/messages/constant_evaluator.dart 💚 41 %
pkgs/intl_translation/lib/src/messages/main_message.dart 💚 56 %
pkgs/intl_translation/lib/src/messages/message.dart 💚 86 % ⬆️ 0 %
pkgs/intl_translation/lib/visitors/message_finding_visitor.dart 💚 84 %

This check for test coverage is informational (issues shown here will not fail the PR).

API leaks ⚠️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbols
intl_translation Message
MainMessage

This check can be disabled by tagging the PR with skip-leaking-check.

License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

@Peetee06
Copy link
Author

Peetee06 commented Jun 2, 2025

Had to also update dart_style to ^3.0.0 to support analyzer ^7.0.0. See dart_style changelogs

That should also fix this failing check

@Peetee06 Peetee06 changed the title feat: allow analyzer 7.0.0 feat!: allow analyzer 7.0.0 and update dart_style to ^3.0.0 Jun 2, 2025
@@ -2,7 +2,7 @@
// This is a library that provides messages for a fr_xyz123 locale. All the
// messages from the main program should be duplicated here with the same
// function name.

// @dart=2.12
Copy link
Member

Choose a reason for hiding this comment

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

Are these necessary?

Copy link
Author

Choose a reason for hiding this comment

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

I'm unsure about all the implications of removing this.

From the dart_style changelog I understand that this will override the language version that the DartFormatter would use. Meaning it will always format based on Dart 2.12, instead of the users' language version.

They are added via this file that I didn't touch.

I used the regenerate.sh scripts here and here to apply the updated formatting.

@Peetee06
Copy link
Author

Peetee06 commented Jun 2, 2025

@mosuem

One of the workflows fail:

info - lib/src/messages/message.dart:78:29 - 'ConstantEvaluator' is deprecated and shouldn't be used. This has no uses in package:analyzer and not exhaustive. Try replacing the use of the deprecated member with the replacement. - deprecated_member_use

It seems ConstantEvaluator was deprecated in analyzer 7.x.x.

I don't know what the replacement for that is and currently don't have the capacity to dive into this deeper.

Would you be okay with me adding an ignore and TODO comment, so this can be addressed once the analyzer dependency constraints are updated to a version where this is fully removed?

@mosuem
Copy link
Member

mosuem commented Jun 3, 2025

I looked up who would do such a stupid thing as deprecating without giving an alternative - it was me! 😆

I do think that replacing it would be the safer choice, this library is brittle enough as is...

Maybe something along the lines of what I did in that PR could also be done here?

bool _isConst(Expression expression) {
    if (expression.inConstantContext) {
      return true;
    } else if (expression is InstanceCreationExpression && expression.isConst) {
      return true;
    } else if (expression is Literal) {
      return switch (expression) {
        BooleanLiteral() => true,
        DoubleLiteral() => true,
        IntegerLiteral() => true,
        NullLiteral() => true,
        SimpleStringLiteral() => true,
        AdjacentStrings() => true,
        SymbolLiteral() => true,
        RecordLiteral() => expression.isConst,
        TypedLiteral() => expression.isConst,
        // TODO(mosum): Expand the logic to check if the individual interpolation elements are const.
        StringInterpolation() => false,
      };
    } else if (expression is Identifier) {
      var staticElement = expression.staticElement;
      if (staticElement != null) {
        if ((staticElement is VariableElement && staticElement.isConst) ||
            staticElement.nonSynthetic is ConstVariableElement) {
          return true;
        }
      }
    }
    return false;
  }

Let me check.

@mosuem
Copy link
Member

mosuem commented Jun 3, 2025

Something like the last commit in this maybe? #972

_ => null,
};

Iterable<String>? _checkChildren<T>(Iterable<StringLiteral> strings) {
Copy link
Author

Choose a reason for hiding this comment

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

@mosuem do we need the generic T here? I don't see it used anywhere.

Copy link
Member

Choose a reason for hiding this comment

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

No, that's a refactoring leftover I believe

@Peetee06
Copy link
Author

Peetee06 commented Jun 3, 2025

Thank you for the code suggestion and the timely reviews!

I cherry-picked the commit into this PR. All tests are passing locally.

Hopefully the pipeline does, too 🤞

@Peetee06
Copy link
Author

Peetee06 commented Jun 4, 2025

@mosuem there is another ConstantEvaluator in lib/visitors/message_finding_visitor.dart which needs to be replaced.

I naiively tried to replace it with evaluateConstString, but a test is still failing. Pretty sure only evaluating const strings isn't enough in this instance.

Could you give some guidance how to replace it there? :)

@mosuem
Copy link
Member

mosuem commented Jun 4, 2025

I added a fix - probably some tests would be nice to have though.

@Peetee06
Copy link
Author

Peetee06 commented Jun 4, 2025

@mosuem thanks for supporting with the fix 👍

I let AI create some test cases. They make sense to me.

Would be great if you could check if they are actually useful and if we should drop or add some cases.

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

Successfully merging this pull request may close these issues.

2 participants