<!--
 * Copyright (C) 2023 WYATT GROUP
 * Please see the AUTHORS file for details.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

# Wyatt Analysis

![SDK: Dart & Flutter](https://img.shields.io/badge/SDK-Dart%20%7C%20Flutter-blue?style=flat-square)

This package provides lint rules for Dart and Flutter which are used at  [Wyatt Studio](https://wyatt-studio.fr). For more information, see the complete list of options in **lib/analysis_options.2.6.1.yaml**.

**Note**: This package was heavily inspired by [pedantic](https://github.com/dart-lang/pedantic), [Very Good Analysis](https://github.com/VeryGoodOpenSource/very_good_analysis) and the official [flutter_lints](https://pub.dev/packages/flutter_lints).

## Adding Wyatt Analysis to your project

Using CLI:

```sh
dart pub add wyatt_analysis:2.6.1 --dev --hosted-url=https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub/
```

## Usage

To use the lints, add a dependency in your `pubspec.yaml` :

```yaml
wyatt_analysis:
    hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub/
    version: 2.7.0
```

Then, add an include in `analysis_options.yaml` :

```yaml
include: package:wyatt_analysis/analysis_options.yaml
```

This will ensure you always use the latest **Dart** version of the lints. To get the latest **Flutter** superset:

```yaml
include: package:wyatt_analysis/analysis_options.flutter.yaml
```

If you wish to restrict the lint version, specify a version of `analysis_options.yaml` instead:

```yaml
include: package:wyatt_analysis/analysis_options.flutter.2.6.1.yaml
```

If you just want **Dart** version:

```yaml
include: package:wyatt_analysis/analysis_options.2.6.1.yaml
```

## Suppressing Lints

There may be cases where specific lint rules are undesirable. Lint rules can be surpressed at the line, file, or project level.

An example use case for suppressing lint rules at the file level is suppressing the `prefer_const_constructors` in order to achieve 100% code coverage. This is due to the fact that const constructors are executed before the tests are run, resulting in no coverage collection.

### Line Level

To surpress a specific lint rule for a specific line of code, use an `ignore` comment directly above the line:

```dart
// ignore: public_member_api_docs
class A {}
```

### File Level

To surpress a specific lint rule of a specific file, use an `ignore_for_file` comment at the top of the file:

```dart
// ignore_for_file: public_member_api_docs

class A {}

class B {}
```

### Project Level

To surpress a specific lint rule for an entire project, modify `analysis_options.yaml` :

```yaml
include: package:wyatt_analysis/analysis_options.yaml
linter:
  rules:
    public_member_api_docs: false
```

## Badge

To indicate your project is using `wyatt_analysis` → [![style: wyatt analysis](https://img.shields.io/badge/Style-Wyatt%20Analysis-blue)](https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/wyatt_analysis)

```md
[![style: wyatt analysis](https://img.shields.io/badge/Style-Wyatt%20Analysis-blue)](https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/wyatt_analysis)
```

## Development

When you want to create a new version of the plugin. Before any modification, execute the following command to create new files:

```sh
./tool/new_version.sh <version>
```

The previous version is automatically retrieved from the `pubspec.yaml` file.

This script will create the following files:
* `lib/analysis_options.<version>.yaml`
* `lib/analysis_options.flutter.<version>.yaml`

And update the following files:
* `README.md`
* `pubspec.yaml`
* `lib/analysis_options.yaml`
* `lib/analysis_options.flutter.yaml`
* `lib/wyatt_analysis.dart`

Then, you can use the following command to retrieve latest available lints from the official linter.

```sh
./tool/check_rules.sh
```

After that, you can modify the files `lib/analysis_options.<version>.yaml` and `lib/analysis_options.flutter.<version>.yaml` to add new lints or remove some.

Then you can sort the lints with the following command:

```sh
./tool/sort_rules.sh
```

Finally, you can generate the changelog with the following command:

```sh
./tool/generate_changelog.sh <old_version>
```

The new version is automatically retrieved from the `pubspec.yaml` file. But **you have to specify** the previous version.

## Notes

You can explore every lint rules [here](https://dart.dev/tool/linter-rules).
