dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.09k stars 1.56k forks source link

dart analyze command does not have --options parameter like dartanalyzer #45286

Open bitsydarel opened 3 years ago

bitsydarel commented 3 years ago

This tracker is for issues related to:

Analyzer

Dart SDK version: 2.12.0 (stable) (Thu Feb 25 19:50:53 2021 +0100) on "macos_x64" MacOSX

dart analyze does not support the command --options to specify the location of the analysis_options.yaml file which is needed to run analysis of project with code style located outside of the project directory.

a-siva commented 3 years ago

/cc @bkonyi

bwilkerson commented 3 years ago

@devoncarew

bitsydarel commented 3 years ago

Hi @devoncarew Any news on this ?

srawlins commented 2 years ago

This is applicable to both dart analyze and dart fix.

kevmoo commented 2 years ago

@mit-mit ?

a-siva commented 2 years ago

// @bwilkerson

mit-mit commented 2 years ago

It's pretty easy to add the new flag to dart analyze and pass it onto the analysis server wrapper here: https://github.com/dart-lang/sdk/blob/main/pkg/dartdev/lib/src/analysis_server.dart#L28

@@ -30,12 +30,14 @@ class AnalysisServer {
     this.packagesFile,
     this.sdkPath,
     this.analysisRoots, {
+    this.optionsFile,
     this.cacheDirectoryPath,
     required this.commandName,
     required this.argResults,
   });

   final String? cacheDirectoryPath;
+  final File? optionsFile;
 })

That then invokes an analysis driver here: https://github.com/dart-lang/sdk/blob/main/pkg/dartdev/lib/src/analysis_server.dart#L85

I tried adding an --options here, but that doesn't work:

  mit-macbookpro5:pkg1 mit$ ~/dev/dartsdk/sdk/xcodebuild/DebugX64/dart-sdk/bin/dart analyze --options=fuz/analysis_options.yaml .
Analyzing ....
Unhandled exception:
FormatException: Could not find an option named "options".
#0      Parser._validate (package:args/src/parser.dart:309:21)
#1      Parser._handleLongOption (package:args/src/parser.dart:298:7)
#2      Parser._parseLongOption (package:args/src/parser.dart:262:12)
#3      Parser.parse (package:args/src/parser.dart:86:11)
#4      ArgParser.parse (package:args/src/arg_parser.dart:334:42)
#5      Driver.start (package:analysis_server/src/server/driver.dart:144:26)
#6      main (file:///Users/mit/dev/dartsdk/sdk/pkg/analysis_server/bin/server.dart:10:11)
#7      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:32)
#8      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

Is there a way of passing the options file path to package:analysis_server/src/server/driver.dart ?

bwilkerson commented 2 years ago

Not currently, no.

The analysis server was originally designed to be a long-running process and for the set of packages being analyzed to vary over time. In that mode such an option doesn't make sense.

But it's now being used by command-line tools like dart analyze and dart fix, and in that environment the option makes more sense.

If we want / need to add such an option to dart analyze, then we'll need to add it to the server as well.