Skip to content

Commit

Permalink
Merge pull request #578 from dart-lang/merge-lints-package
Browse files Browse the repository at this point in the history
Merge `package:lints`
  • Loading branch information
mosuem authored Dec 20, 2024
2 parents 7f9f597 + bcff5ce commit 0ca0d5c
Show file tree
Hide file tree
Showing 22 changed files with 2,084 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/lints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: "package:lints"
about: "Create a bug or file a feature request against package:lints."
labels: "package:lints"
---
9 changes: 9 additions & 0 deletions pkgs/lints/.github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
blank_issues_enabled: true
contact_links:
- name: Propose a new lint
url: https://github.com/dart-lang/linter/issues/new?assignees=&labels=enhancement%2C+lint+request&template=lint-request.md&title=
about: Request a new lint rule.
- name: Report an issue with a lint
url: https://github.com/dart-lang/linter/issues/new?assignees=&labels=&template=issue-report.md&title=
about: Create an issue report for an existing lint.

14 changes: 14 additions & 0 deletions pkgs/lints/.github/ISSUE_TEMPLATE/lint-propoposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: Add an existing lint to the `core` or `recommended` rule set
about: Propose adding an existing lint rule to the `core` or `recommended` rule set.
title: ''
labels: type-lint
assignees: ''

---

**Describe the rule you'd like to see added and to what rule set**
Include as much detail as you can.

**Additional context**
Add any other considerations or context here.
10 changes: 10 additions & 0 deletions pkgs/lints/.github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Dependabot configuration file.
version: 2

updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
labels:
- autosubmit
14 changes: 14 additions & 0 deletions pkgs/lints/.github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# A CI configuration to auto-publish pub packages.

name: Publish

on:
pull_request:
branches: [ main ]
push:
tags: [ 'v[0-9]+.[0-9]+.[0-9]+*' ]

jobs:
publish:
if: ${{ github.repository_owner == 'dart-lang' }}
uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main
32 changes: 32 additions & 0 deletions pkgs/lints/.github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: validate

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Run weekly
schedule:
- cron: "0 0 * * 0"

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [beta] # todo: re-add stable

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: ${{ matrix.sdk }}

- run: dart pub get
- run: dart format --output=none --set-exit-if-changed .
- run: dart analyze --fatal-infos
- run: dart tool/validate_lib.dart
- run: dart tool/gen_docs.dart --verify
10 changes: 10 additions & 0 deletions pkgs/lints/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Files and directories created by pub
.dart_tool/
.packages

# Omit commiting pubspec.lock for library packages:
# https://dart.dev/guides/libraries/private-files#pubspeclock
pubspec.lock

# Directory created by dartdoc
doc/api/
96 changes: 96 additions & 0 deletions pkgs/lints/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
## 5.1.1

- Updated the SDK lower bound to 3.6.

## 5.1.0

- `core`:
- added [unintended_html_in_doc_comment] (https://github.com/dart-lang/lints/issues/192)
- Updated the SDK lower bound to 3.6 (dev).

[unintended_html_in_doc_comment]: https://dart.dev/lints/unintended_html_in_doc_comment

## 5.0.0

- `recommended`:
- added [invalid_runtime_check_with_js_interop_types] (https://github.com/dart-lang/lints/issues/188)
- added [unnecessary_library_name] (https://github.com/dart-lang/lints/issues/181)
- removed [avoid_null_checks_in_equality_operators] (https://github.com/dart-lang/lints/issues/200)
- Updated the SDK lower-bound to 3.5.

[invalid_runtime_check_with_js_interop_types]: https://dart.dev/tools/linter-rules/invalid_runtime_check_with_js_interop_types
[unnecessary_library_name]: https://dart.dev/lints/unnecessary_library_name
[avoid_null_checks_in_equality_operators]: https://dart.dev/tools/linter-rules/avoid_null_checks_in_equality_operators

## 4.0.0

- `core`:
- added `library_annotations` (https://github.com/dart-lang/lints/issues/177)
- added `no_wildcard_variable_uses` (https://github.com/dart-lang/lints/issues/139)
- removed `package_prefixed_library_names` (https://github.com/dart-lang/lints/issues/172)
- `recommended`:
- removed `library_names` (https://github.com/dart-lang/lints/issues/181)
- Updated the SDK lower-bound to 3.1.
- Add a section on upgrading to the latest lint set to the readme.

## 3.0.0

- `core`:
- added `collection_methods_unrelated_type`
- added `dangling_library_doc_comments`
- added `implicit_call_tearoffs`
- added `secure_pubspec_urls`
- added `type_literal_in_constant_pattern`
- added `use_string_in_part_of_directives`
- removed `iterable_contains_unrelated_type`
- removed `list_remove_unrelated_type`
- `recommended`:
- added `unnecessary_to_list_in_spreads`
- added `use_super_parameters`
- removed `prefer_equal_for_default_values`
- removed `prefer_void_to_null`
- Add info about which lints have quick fixes to the package's readme.
- Move the list of lint rules from the readme to a separate
[rules.md](https://github.com/dart-lang/lints/blob/main/rules.md) file.

## 2.1.1

- Added the `analysis` and `lints` topics to the pubspec file.
- Update the package's readme to include the list of lint rules that
`package:lints/core.yaml` and `package:lints/recommended.yaml` include.

## 2.1.0

- Updated the SDK lower-bound to 3.0.
- Removed `always_require_non_null_named_parameters` from `recommended.yaml`
as it is only relevant in Dart pre 2.12 and with Dart 3.0, libraries can
no longer be opted back that far.

## 2.0.1

- Updated documentation for the `lib/core.yaml` and `lib/recommended.yaml`
analysis configurations.

## 2.0.0

- Added the following lints to core.yaml:
- `depend_on_referenced_packages`
- `null_check_on_nullable_type_parameter`
- Added the following lints to recommended.yaml:
- `library_private_types_in_public_api`
- `no_leading_underscores_for_library_prefixes`
- `no_leading_underscores_for_local_identifiers`
- `prefer_interpolation_to_compose_strings`
- `unnecessary_constructor_name`
- `unnecessary_late`
- `unnecessary_null_aware_assignments`
- `unnecessary_nullable_for_final_variable_declarations`
- Bumped the minimum required Dart SDK version to 2.17

## 1.0.1

- Documentation updates

## 1.0.0

- Initial stable version
27 changes: 27 additions & 0 deletions pkgs/lints/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright 2021, the Dart project authors.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
115 changes: 115 additions & 0 deletions pkgs/lints/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
[![Build Status](https://github.com/dart-lang/lints/workflows/validate/badge.svg)](https://github.com/dart-lang/lints/actions?query=branch%3Amain)
[![pub package](https://img.shields.io/pub/v/lints.svg)](https://pub.dev/packages/lints)
[![package publisher](https://img.shields.io/pub/publisher/lints.svg)](https://pub.dev/packages/lints/publisher)

# Official Dart lint rules

The Dart linter is a static analyzer for identifying possible problems in your
Dart source code. More than a hundred [linter rules][rules] are available,
checking anything from potential typing issues, coding style, and formatting.
This package - `package:lints` - contains the lint settings recommended by the
Dart team.

## Lint sets

This package includes two sets of lints:

* **Core lints**: Lints that help identify critical issues that are likely to
lead to problems when running or consuming Dart code. All code should pass these
lints.

* **Recommended lints**: Lints that help identify additional issues that may
lead to problems when running or consuming Dart code, and lints that enforce
writing Dart using a single, idiomatic style and format. All code is encouraged
to pass these lints. The recommended lints include all the core lints.

Additionally, a third lint set -
[`package:flutter_lints`](https://pub.dev/packages/flutter_lints) - extends the
recommended set with additional recommended Flutter-specific lints.

The Dart team will likely not provide recommendations past the `core` and
`recommended` sets (e.g., a `strict` rule set). However, there are many such rule
sets in the ecosystem (available at [pub.dev](https://pub.dev/)).

Rule set authors: consider adding the `lints` topic to your pubspec to allow
easier discovery (e.g.,
[pub.dev/packages?q=topic:lints](https://pub.dev/packages?q=topic%3Alints)).
For more information about topics, visit
[dart.dev/tools/pub/pubspec#topics](https://dart.dev/tools/pub/pubspec#topics).

## Where these lints are used

When creating a new Dart project using the [`dart create`][dart create] command,
the `recommended` set of lints from `package:lints` is enabled by default.

When uploading a package to the [pub.dev] package repository, packages are
[awarded pub points][scoring] based on how many of the 'core' lints pass.

## Enabling the lints

For new apps created with `dart create` the `recommended` set of lints are
enabled by default.

For existing apps or packages, you can enable these lints via:

1. In a terminal, located at the root of your package, run this command:

```terminal
dart pub add dev:lints
```
2. Create a new `analysis_options.yaml` file, next to the pubspec, that
includes the lints package:
```yaml
include: package:lints/recommended.yaml
```
or:
```yaml
include: package:lints/core.yaml
```
## Upgrading to the latest lints
To upgrade to the latest version of the lint set, run:
```
dart pub add dev:lints
```
## Customizing the predefined lint sets
For details on customizing static analysis above and beyond the predefined
lint sets, check out [Customizing static analysis].
## Evolving the lint sets
The Dart language changes and the ecosystem continues to develop new best
practices, so the lint sets must be periodically updated to reflect the best way
we know to write Dart code. The process we use is:
1. Anyone can file an [issue] to discuss a potential change to a lint set
(i.e., adding or removing a lint from one or both sets; if you're proposing
an entirely new lint, the place to suggest that is at the [linter repo]).
Feedback is welcome from any Dart user.
2. Periodically, a group of Dart and Flutter team members meet to review the
suggestions and decide what to adopt.
3. The lists are updated and a new version of the package is published.
## Lint set contents
See [rules.md](https://github.com/dart-lang/lints/blob/main/rules.md) for a list
of rules that make up the core and recommended rule sets.
[dart create]: https://dart.dev/tools/dart-create
[scoring]: https://pub.dev/help/scoring
[customizing static analysis]: https://dart.dev/tools/analysis
[rules]: https://dart.dev/tools/linter-rules
[pub.dev]: https://pub.dev
[issue]: https://github.com/dart-lang/lints/issues
[linter repo]: https://github.com/dart-lang/linter
[`package:flutter_lints`]: https://pub.dev/packages/flutter_lints
1 change: 1 addition & 0 deletions pkgs/lints/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An example project that uses Dart recommended lints.
30 changes: 30 additions & 0 deletions pkgs/lints/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
10 changes: 10 additions & 0 deletions pkgs/lints/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: example
description: An example project that uses Dart recommended lints.
version: 0.1.0
publish_to: none

environment:
sdk: ^3.0.0

dev_dependencies:
lints: ^2.1.0
Loading

0 comments on commit 0ca0d5c

Please sign in to comment.