'Dart linting exclude folders under analyzer

My linting works fine if I add rules and errors but excluding something does not have any effect.

Here is my analysis_options.yaml in the project root directory.

include: package:pedantic/analysis_options.yaml

analyzer:
  exclude:
    - lib/generated/**
    - test/**

  errors:
    ...
    

linter:
  rules:
    ...


My project hierarchy is like this:

/analysis_options.yaml
/test/...
/lib/generated/...

So I would like to ignore linting on test and generated folder under lib. But somehow it does not

I followed the instructions based on the docs: https://dart.dev/guides/language/analysis-options

Dart version: 2.8.4
Flutter version: 1.17.5

In my pubspec.yaml this is under dependencies:

dependencies:
  ...
  pedantic: ^1.8.0
  ...


So how to prevent linting not to check in excluded folders?
Thank you for your time and help.



Solution 1:[1]

Since linter does not support exclude, and if you exclude your directory from analyzer you won't get any static analysis and will miss errors, what I did was adding an empty analysis_options.yaml inside my test directory. That fixed the problem.

Solution 2:[2]

I'm working on a large project, I implemented lint and I can't handle all warnings and errors once so I excluded files and directories just like this

analyzer:
  exclude:
    - lib/test/**
    - lib/provider/**
    - lib/bloc/activate_entitlement/**
    - lib/models/appconfig.dart
    - lib/bloc/favourite/**

Lint

dev_dependencies:
  lint: ^1.8.2

It's working fine for me.

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 Amir_P
Solution 2 Azhar Ali