invertase / dart_custom_lint

💡 Easily write powerful Dart & Flutter lint rules for your projects or for users of your packages.
https://pub.dev/packages/custom_lint
Apache License 2.0
288 stars 65 forks source link

Failed to start plugins `Error: The specified language version is too high` #244

Closed SunlightBro closed 7 months ago

SunlightBro commented 7 months ago

Android Studio Dart analysis fails on start plugins Manually Running dart run custom_lint works and properly reports the DartLintRule.

Analyzing...                           0.0s
  lib/main.dart:3:9 • Avoid using the "bang" operator (!). • avoid_non_null_assertion • WARNING
1 issue found.

But Android Studio reports a Dart analysis issue on start up:

/Users/sunbro/.puro/shared/pub_cache/hosted/pub.dev/vm_service-14.2.0/lib/vm_service.dart:1:1: Error: The specified language version is too high. The highest supported language version is 3.2.

issue-4.md custom_lint.log

To Reproduce

I have a small lint_playground package

library lint_playground;

import 'package:custom_lint_builder/custom_lint_builder.dart';
import 'package:ffuf_lints/src/avoid_non_null_assertion.dart';

/// Entrypoint of _PlayGroundLinter
PluginBase createPlugin() => _FFUFLinter();

class _PlayGroundLinter extends PluginBase {
  @override
  List<LintRule> getLintRules(CustomLintConfigs configs) => [
        const AvoidNonNullAssertion(),
      ];

  @override
  List<Assist> getAssists() => [];
}

/// [DartLintRule] - avoid_non_null_assertion
/// WARNING
/// "Avoid using the "bang" operator (!)."
class AvoidNonNullAssertion extends DartLintRule {

  const AvoidNonNullAssertion() : super(code: _code);

  static const _code = LintCode(
    name: 'avoid_non_null_assertion',
    problemMessage: 'Avoid using the "bang" operator (!).',
    errorSeverity: ErrorSeverity.WARNING,
  );

  @override
  void run(
    CustomLintResolver resolver,
    ErrorReporter reporter,
    CustomLintContext context,
  ) {
    context.registry.addPostfixExpression((node) {
      if (node.operator.lexeme == '!') {
        reporter.reportErrorForNode(code, node);
      }
    });
  }
}

and in /example I have a small main:

void main() {
  final int? value = 0;
  print(value!.toString());
}
SunlightBro commented 7 months ago

lint_playground/pubspec.yaml

name: lint_playground
version: 2.4.1
publish_to: none

environment:
  sdk: '>=2.17.0 <4.0.0'

dependencies:
  analyzer: ^6.0.0            # -> 6.4.1
  analyzer_plugin: ^0.11.0    # -> 0.11.3
  custom_lint_builder: ^0.6.0 # -> 0.6.4

lint_playground/example/pubspec.yaml

name: example
version: 0.1.0
publish_to: none

environment:
  sdk: '>=2.12.0 <4.0.0'

dev_dependencies:
  custom_lint: any # -> 0.6.4
  ffuf_lints: any

dependency_overrides:
  ffuf_lints:
    path: ../
SunlightBro commented 7 months ago

Ok after a bit more investigation I think it's an issue with Android Studio, Today I upgraded to Android Studio Iguana | 2023.2.1 Patch 2 232.10300.40.2321.11668458 and somehow Android Studio Dart SDK path was wrong afterwards 🙈.