'How do I share an analysis_options.yaml file across multiple packages?

I am developing a Flutter Module, multiple Flutter Plugins. The relationship between them is: module depends on all plugins. All plugins are not published to pub and use git dependencies.

I now need to add analysis_options.yaml to each plugin, the configuration is the same. So I have an idea, can all plugins share the same analysis_options.yaml? I haven't found a way yet.

flutter analyze cannot specify a directory, it is executed in the current project by default, and the analysis_options.yaml rule can be applied. dart analyze can specify directories or files, but cannot apply the analysis_options.yaml rules. If I want to specify both directory or file scans, but also custom rules, how do I do that?



Solution 1:[1]

From https://dart.dev/guides/language/analysis-options:

If the analyzer can’t find an analysis options file at the package root, it walks up the directory tree, looking for one. If no file is available, the analyzer defaults to standard checks.

So if you want a analysis_options.yaml file shared among directories, you can place one in a common parent directory.

You also can make one analysis_option.yaml file include another one and then to adjust rules. For example:

include: path/to/another/analysis_options.yaml

linter:
  rules:
    avoid_as: false

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jamesdlin